Aliaspooryorik
ColdFusion ORM Book

ColdSpring arrays and structs

I found out today that you can create structs and arrays in the ColdSpring configuration file. I've haven't actually used it yet, but it could be quite useful for setting up configurations.

Here's how you do it.


<!--
I am an example of a struct / map in coldspring
-->

<bean id="MailServerConfig" class="coldspring.beans.factory.config.MapFactoryBean">
<property name="SourceMap">
<map>
<entry key="ServerHostName"><value>127.0.0.1</value></entry>
<entry key="ServerUsername"><value>foo</value></entry>
<entry key="ServerPassword"><value>bar</value></entry>
</map>
</property>
</bean>

<!--
I am an example of an array in coldspring
-->

<bean id="AuditOperations" class="coldspring.beans.factory.config.ListFactoryBean">
<property name="SourceList">
<list>
<value>create</value>
<value>edit</value>
<value>delete</value>
</list>
</property>
</bean>

Because they are both declared as beans, you can inject them as you normally would via autowire or manually setting up the dependancy.


<bean id="MyObject" class="myPath.MyObject">
<!-- set the dependancy manually -->
<property name="AuditOperations">
<ref bean="AuditOperations" />
</property>
</bean>

 


6 comments

  1. When Chris Scott first told me about these helper classes, I couldn't imagine why they'd be useful but now I use them all the time to provide structured configuration data. They're great!

    Comment by Sean Corfield – March 06, 2009
  2. Hi Sean. Yeah I think they are going to be cropping up quite a lot in my config files! I'm thinking of using them as equivalents to the Java Enum Type.

    Comment by John Whish – March 06, 2009
  3. +1, MapFactoryBean rocks! I was recently reintroduced to it by Matt Quackenbush and have found a number of ways to use it. Not only for injecting configuration information, but I also used it in a place where I thought I was going to have to write a factory. I blogged about that back in November (in case you're interested).

    Comment by Bob Silverberg – March 07, 2009
  4. Hi Bob, I think that these helper classes are a real hidden gem. I'd be really interested to read your post. I probably read it at the time and didn't quite realise the power of it!

    Comment by John Whish – March 07, 2009
  5. These last two coldspring posts were great. Tiny little nuggets of interesting information.

    Comment by greg cerveny – March 10, 2009
  6. Glad you found them useful Greg :)

    Comment by John Whish – March 10, 2009

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts