|
From: <jas...@ma...> - 2004-06-23 16:43:52
|
The Spring XML config file is cool and flexible; but for constrained
problems it can be a little verbose. For certain scenarios I'd like to
provide some neater, more concise XML syntax.
e.g. I'm considering configuring the ActiveMQ JMS message broker using
Spring's configuration mechanism, but I'd prefer to be able to use some
well defined aliases/macros in the config file - while preserving the
full power of Spring's XML.
The basic idea is to use the default bean/property/value type syntax
for Spring and add some context-specific macros (elements) which map
directly onto specific well known bean factories - always allowing
folks to drop down to the default Spring XML if they need to, so that
we...
* reduce typing hugely
* to allow an XSD or DTD to be created to (i) validate the incoming XML
and (ii) to auto-document the various properties available easily
* preserve the extensible & flexible nature of Spring's XML
This would be especially useful for configuring large services which
want to have their own configuration mechanisms (like a message broker
or other custom kinds of container). Having a little schema optimised
for the problem space would really help
Here's an example of the kind of thing I mean, where we'd add a few new
elements which the ActiveMQ-specific parser would understand...
<container name="foo">
<!-- macros of some kind that ActiveMQ knows about -->
<connector url="tcp://localhost:61616"/>
<connector url="multicast://228.1.2.3.4:5000"/>
<messageStore class="Foo">
<!-- inside here drop down to Spring XML to customize some plugin -->
<property name="cheese"><value>123</value></property>
</messageStore>
</container>
Using the example above we could use a simple macro which turns
<connector url="..." timeout="2000"/>
into
<bean class="MyConnectorBean">
<property name="url"><value>...</value></property>
<property name="timeout"><value>2000</value></property>
</bean>
This could be a trivial optional transformation step written in a
little Java code, where the ActiveMQXmlBeanFactory could derive from
the Spring XmlBeanFactory and install a custom transformer into the
XmlBeanDefinitionReader so that any XML notation the ActiveMQ factory
knew about could be transformed into normal Spring XML ready for Spring
to do its thing.
I'm thinking the easiest way to do it could be to allow custom
XmlBeanDefinitionReader implementations to be registered with an
XmlBeanFactory via some constructor or protected method (e.g. either a
setter method or create the XmlBeanDefinitionReader by lazy
construction inside the XmlBeanFactory), then I could just provide my
own custom XmlBeanDefinitionReader derivation which implements the
macros I need - all used inside my own ActiveMQXmlBeanFactory which
extends XmlBeanFactory.
I wondered if folks had tried this kinda thing yet? If folks agree -
could we have the constructor or XmlBeanDefinitionReader setter/lazy
create method on XmlBeanFactory please?
James
-------
http://radio.weblogs.com/0112098/
|