Hi all,
I know there are people out there who would prefer writing HiveMind
module descriptors using a scripting language instead of XML files.
I've spent a few hours now on trying to get a Groovy script
(http://groovy.codehaus.org/) to define a HiveMind module.
As a test I wrote this Groovy script which yields an equivalent to the
HiveMind calculator example module:
import org.apache.hivemind.examples.*;
import org.apache.hivemind.examples.impl.*;
class ExamplesModule {
createModule(builder) {
services = [
'Adder':[Adder.class, AdderImpl.class],
'Subtracter':[Subtracter.class, SubtracterImpl.class],
'Multiplier':[Multiplier.class, MultiplerImpl.class],
'Divider':[Divider.class, DividerImpl.class]
]
builder.module(id:'examples', version:'1.0.0') {
services.keySet().each { id |
builder.servicePoint(id:id,
interface:services.get(id)[0].name) {
createInstance(class:services.get(id)[1].name)
interceptor(serviceId:'hivemind.LoggingInterceptor')
}
}
servicePoint(id:'Calculator',
interface:Calculator.class.name) {
invokeFactory {
construct(class:CalculatorImpl.class.name)
}
interceptor(serviceId:'hivemind.LoggingInterceptor')
}
}
}
}
IMHO this script is still fairly readable. Whether the code block
defining the Adder, Subtracter, Multiplier, and Divider services
really contributes to the readability is probably a matter of taste.
There are still a few ugly hacks in the implementation (as getting the
line numbers by throwing and catching an exception), but it does work.
What do you all think about this? Is this something we could add to
the HiveMind lib?
--knut
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]