You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hivemind.apache.org by Knut Wannheden <kn...@gmail.com> on 2004/10/11 12:58:03 UTC

experimenting with groovy support

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: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


Re: experimenting with groovy support

Posted by Knut Wannheden <kn...@gmail.com>.
Generating HiveDoc from ModuleDescriptor objects would definitely be a
requirement.  This in turn requires some additions to the Descriptor
classes (I can only think of "description" fields right now).

But the big question is: How should the HiveDoc be generated? Using a
visitor to generate the equivalent XML again and then use the existing
XSLT is the best solution I can come up with at the moment. Is anyone
working on this yet?

The Groovy support I've been playing with piggybacks on the
DescriptorParser to create the ModuleDescriptors by generating SAX
events. I think that's a reasonable approach as there is quite a bit
of logic in DescriptorParser which would be unfortunate to duplicate.
This, alas, requires changing the DescriptorParser so it can be used
as a standard SAX ContentHandler.

--knut

On Tue, 12 Oct 2004 08:15:06 -0400, Howard Lewis Ship <hl...@gmail.com> wrote:
> I'd like to see some refactoring to support generating HiveDoc from
> the parsed Descriptor objects (however that would work!).  Once that
> is in place, I'd personally be much more open to various scripting
> approaches to building the  Registry.
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


Re: experimenting with groovy support

Posted by Howard Lewis Ship <hl...@gmail.com>.
I'd like to see some refactoring to support generating HiveDoc from
the parsed Descriptor objects (however that would work!).  Once that
is in place, I'd personally be much more open to various scripting
approaches to building the  Registry.


On Mon, 11 Oct 2004 12:58:03 +0200, Knut Wannheden
<kn...@gmail.com> wrote:
> 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: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org