|
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/
|
|
From: Seth L. <se...@eh...> - 2004-06-23 18:08:52
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 | 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. One way to do that would be XSLT. I've often considered doing just that type of thing. For instance, our views.xml file is getting huge. That type of file really lends itself to a shortened version. Then, using XSLT at runtime, we can transform the views optimized XML into a full Spring BEANS xml file. I'd rather see this: <jstl url="/WEB-INF/jsp/foo.jsp" /> than: <bean class="org.springframework.servlet.view.JstlView"> ~ <property name="url"> ~ <value>/WEB-INF/jsp/foo.jsp</value> ~ </property> </bean> Other nice things about this is a DTD can be created for the shortened version, to allow for validating and smoother XSLT. Also, if others need to extend the shorted form, they can either edit the XSLT file, or better yet, just start writing spring BEANS elements. The XSLT file should just recognize the native spring beans elements and transfer them over. A XstlBeanFactory would do the trick there. Given an XML file, and a XSLT file, it should transform then delegate to XmlBeanFactory. Ideas? Thoughts? This might be a good middle ground for those that like XML and those that want to see the XML verbosity reduced somehow. Seth -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3-nr1 (Windows XP) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFA2cctKZsFSwtW+wIRAqLRAJ90cmj7E+J4O70gy0K5IwADpWMRcgCdHrbU TQKCg6TDIF8yGEysAilxxIk= =JRgu -----END PGP SIGNATURE----- |
|
From: <jas...@ma...> - 2004-06-24 03:32:05
|
On 23 Jun 2004, at 19:08, Seth Ladd wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > | 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. > > One way to do that would be XSLT. I've often considered doing just > that > type of thing. For instance, our views.xml file is getting huge. That > type of file really lends itself to a shortened version. Then, using > XSLT at runtime, we can transform the views optimized XML into a full > Spring BEANS xml file. > > I'd rather see this: > > <jstl url="/WEB-INF/jsp/foo.jsp" /> > > than: > > <bean class="org.springframework.servlet.view.JstlView"> > ~ <property name="url"> > ~ <value>/WEB-INF/jsp/foo.jsp</value> > ~ </property> > </bean> > > Other nice things about this is a DTD can be created for the shortened > version, to allow for validating and smoother XSLT. Also, if others > need to extend the shorted form, they can either edit the XSLT file, or > better yet, just start writing spring BEANS elements. The XSLT file > should just recognize the native spring beans elements and transfer > them > over. > > A XstlBeanFactory would do the trick there. Given an XML file, and a > XSLT file, it should transform then delegate to XmlBeanFactory. > > Ideas? Thoughts? This might be a good middle ground for those that > like XML and those that want to see the XML verbosity reduced somehow. XSLT is certainly one way of doing it. Either way, whether its some Java code that does the transformation, or XSLT the effect is the same - we get a shortened XML file (along with a custom DTD / XSD) for easier editing. Personally I find XSLT to be a PITA so would rather a little simple bit of Java code to navigate over a DOM tree and turn elements into normal Spring XML but each to their own. So long as the hooks are there to easily modify the DOM before Spring starts to process it, folks could use Java code or XSLT to transform the DOM. James ------- http://radio.weblogs.com/0112098/ |