Meet ColdSpringXMLUtils, a New Addition to the ColdSpring Bean Utilities Family
One thing that I've heard people ask about in the ColdSpring mailing list over the years relates to properties. These are quite useful. If you didn't know, you can specify a dynamic property in certain places in your ColdSpring XML using the syntax ${myPropertyName}. You then pass a structure of property names and values into ColdSpring, and it will substitute your property names for the placeholder values.
It's a nice feature, but it only works in specific places, like simple string values. People regularly discover this option, and then wonder why they can't put dynamic properties anywhere in the XML.
Well, now you can!
The ColdSpringXMLUtils component has joined the ColdSpring Bean Utilities RIAForge project. It will replace dynamic properties in a ColdSpring XML file with values specified in the passed structure. Using this CFC allows you to place dynamic properties anywhere in the XML. Note that because the ColdSpring XML file can be quite sizable in large applications, this component uses a Java StringBuilder to avoid using up large amounts of memory while doing the replacements. As a result, this component must be used on a server that is running Java 5 or later. Most installations of ColdFusion 7 or 8 should be running at least Java 5 so this should not affect many people. Usage of the ColdSpringXMLUtils is fairly straightforward. An original ColdSpring XML file might contain an element like this:
<bean id="userService" class="myapp.components.services.userService" />
Using this CFC, you could make part or all of the class name dynamic, like this:
<bean id="userService" class="${servicePackage}.userService" />
You would then define a data structure to map the dynamic properties to the values that you want:
<cfscript> dynamicProperties = StructNew(); dynamicProperties.servicePackage = "myapp.components.services"; </cfscript>
Then simply use this CFC to create the bean factory like this:
<cfset coldSpringXMLUtils = CreateObject('component', 'path.to.ColdSpringXMLUtils').init() />
<cfset beanFactory = coldSpringXMLUtils.loadDynamicColdSpring('/myapp/config/coldspring.xml', dynamicProperties) />
This component will replace any matching dynamic properties in the XML, create the bean factory, and return it for you to use!
I've added this component to the zip file and SVN repository at RIAForge. I hope folks find it useful!




There's your weekend homework assignment. :)
Thanks.