creating a custom namespace handler

17 views
Skip to first unread message

Chris Blackwell

unread,
May 3, 2013, 10:01:48 AM5/3/13
to coldspring-users
I've had a look around but can't find any references for how to implement my own namespace handlers.  

I have a gateway per orm entity based on an abstract gateway (similar to the one included with CS2, except each gateway only deals with a single entity)  and I end up with a lot of repeated bean definitions like this.  The factory looks for {path.to.entity}Gateway and if it finds it uses that, if not creates an instance of the abstract gateway.

<bean id="GWFactory" class="model.factory.GatewayFactory" />

<bean id="ContactGateway" factory-bean="GWFactory" factory-method="getGateway">
<constructor-arg name="entity" value="Contact" />
</bean>

<bean id="CustomerGateway" factory-bean="GWFactory" factory-method="getGateway">
<constructor-arg name="entity" value="Customer" />
</bean>

etc...


So what i was thinking was to create a custom namespace to allow me to write this in a more compact fashion, or even automate the process of creating a gateway bean for every entity.

<gw:config factory-class="model.factory.GatewayFactory" />
<gw:create id="ContactGateway" for="Contact" />
<gw:create id="CustomerGateway" for="Customer" />

Has anyone ever tried to implement a custom namespace, or have any pointers to get me started?  

I'd be happy to contribute this back in the form of github repo and/or docs

Cheers, Chris


Mark Mandel

unread,
May 5, 2013, 4:32:28 PM5/5/13
to coldspri...@googlegroups.com
The easiest reference to follow is the UTIL custom namespace.

All namespaces in CS2 are custom namespaces, the only clever trick is that they are automatically registered with the XMLBeanFactory

So you'll need an XSD:

And namespace handler like so:

And some BeanDefinitionParsers:

Register them, and you're pretty much good to go.

E.g.

The API documentation should get you through it. Let me know if you have any questions.

Mark


--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldspring-use...@googlegroups.com.
To post to this group, send email to coldspri...@googlegroups.com.
Visit this group at http://groups.google.com/group/coldspring-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
Reply all
Reply to author
Forward
0 new messages