Learn About Doug!
View Doug Boude's online resume

View Doug Boude's profile on LinkedIn
Follow Doug Boude on Twitter
Contact Doug!
OO Lexicon
Chat with Doug!
Recent Entries
You may also be interested in...
Florida web site design

hotels boeken in 7 sec
Engagement Rings
Online Dating Australia


Czech your Page Rank!
Check Page Rank of any web site pages instantly:
This free page rank checking tool is powered by Page Rank Checker service
Surf's Up!
Visit Egosurf.org and massage YOUR web ego!
My Score: 6,828
Doug's Books

Read (and recommend)

  • Men are from Mars, Women are from Venus
  • The Wisdom of Crowds: Why the Many Are Smarter Than the Few and How Collective Wisdom Shapes Business, Economies, Societies and Nations
  • Blink: The Power of Thinking Without Thinking
  • Head First Design Patterns
  • Transact-SQL Programming
  • What's So Amazing About Grace?
  • Just So Stories (Rudyard Kipling collection)

Reading

  • Prayer: Does it Make Any Difference?
  • Data Mining (Practical Machine Learning Tools and Techniques)
<< January, 2009 >>
SMTWTFS
123
45678910
11121314151617
18192021222324
25262728293031
Search Blog

Recent Comments
Re: Using Google as your CF Mail Server (by wesdom at 12/26 2:00 PM)
Re: Refreshing Cached ColdFusion Webservices Through the Back Door (by Michael at 12/19 12:36 PM)
Re: Getting a Complete List of Timezones from Java (by PaulH at 12/17 9:32 AM)
Re: A Look at Male Enhancement (by ike at 12/16 4:44 AM)
Re: Very Useful Snippet (by Dan Vega at 12/13 11:00 AM)
Re: Very Useful Snippet (by Jason Fisher at 12/13 8:56 AM)
Re: Viewing Option Text (in IE7) that's Wider than the Select List (by nfurs dfksdjalk at 12/12 5:28 PM)
Re: SQL Forward Engineering with Visio 2003 Professional (by Peter J. Smith at 12/11 5:30 PM)
Re: Element.show/hide anomoly in Prototype (by Michael Sharman at 12/11 3:10 PM)
Re: Basic Security in Coldbox using Transfer and Coldspring - Part II (of II) (by orc at 12/08 11:44 PM)
Categories
Archives
Photo Albums
Funnies (5)
Family (3)
RSS

Powered by
BlogCFM v1.11

10 November 2008
Using Variables in Coldspring.xml with Coldbox

As you can tell from  my last two posts, I am getting pretty deep into Coldbox used in conjunction with Coldspring. One of the things that Coldbox does for us is pass in our configuration settings to the Coldspring bean factory when it initially loads our beans (from Coldspring.xml), thus allowing us to use configuration variables, like so:

<bean id="transferFactory" class="transfer.TransferFactory" singeleton="true">
 <constructor-arg name="datasourcePath">
  <value>${TransferSettings.datasourcePath}</value>
 </constructor-arg>
  ....

The only shortcoming with this is that because we're using Coldspring's DefaultXmlBeanFactory.cfc, it will only do variable replacements when they are found within <value> tags. Brian Kotek addressed this issue with a CFC found in his Coldspring Utilities collection (http://coldspringutils.riaforge.org/ ) , specifically with a CFC called "DynamicXMLBeanFactory.cfc". Using this instead of Coldspring's default bean factory allows you to place variables in other places within your Coldspring.xml. I've used this CFC before in another project, so now my challenge was to figure out how to implement it in Coldbox so that I could make my Coldspring.xml file more dynamic.

 

After a couple hours of tinkering around, AND having to make a minor modification to DynamicXMLBeanFactory.cfc to account for it being used in the Coldbox environment, here are the steps:

1. Place a copy of the modified version of DynamicXMLBeanFactory.cfc in the Coldbox/System/Extras/Coldspring folder. The Coldspring folder won't exist, so go ahead and create it;

2. Add a setting to your Coldbox.xml.cfm file like so:

<YourSettings>
 <Setting name="ColdspringBeanFactory" value="coldbox.system.extras.coldspring.DynamicXMLBeanFactory" />
  ....

That's it! If you want to make sure it's working, create a Coldbox.xml setting such as this:

<Setting name="modelRoot" value="myapproot.model" />

and then add that variable to your Coldspring.xml as part of a bean's class path, for instance:

<bean id="authenticationService" class="${modelRoot}.services.authenticationservice">

If the app fires up without error, you're in business!

 

 

 

Hope this helps someone.  :0)

 


P.S.
If anybody is interested in the changes I made to DynamicXMLBeanFactory and why, they are as follows:

1. Since DynamicXMLBeanFactory extends Coldspring's DefaultXmlBeanFactory, and since Coldbox is hardwired in its "ioc" plugin to interact with DefaultXmlBeanFactory's interface (specifically calling the method "loadBeansFromXmlFile", which does not exist within DynamicXMLBeanFactory), I had to overload that method in DynamicXMLBeanFactory like so:

<cffunction name="loadBeansFromXmlFile" returntype="void" access="public" hint="I am overloading this super class method">
  <cfargument name="beanDefinitionFile" type="string" required="true" hint="I am the location of the bean definition xml file"/>
  <cfset loadBeansFromDynamicXmlFile(arguments.beanDefinitionFile,getDefaultProperties()) />
</cffunction>

2. DynamicXMLBeanFactory was executing an "expandpath" on an already expanded path (Coldbox is already passing in the fully expanded path to the Coldspring.xml file ), resulting in an error of "file not found". Because of this, I had to comment out line 98 in the "getReplacedColdSpringXML" method.

Perhaps there was a more elegant method for implementing Brian's CFC, but the only two choices I saw was to either modify the framework (NO! BAD MAN! NO!), or the CFC. I opted for the CFC. What I was thinking, though, is that perhaps it would be good if Coldbox allowed not only the path to the IOC's beanfactory class to be a setting, but also the name of the bean loader method that should be called (after init)? Just a thought.

Doug out




Posted by dougboude at 5:00 PM | PRINT THIS POST! |Link | 1 comment
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: Using Variables in Coldspring.xml with Coldbox
Doug,

This functionality is now in SVN for both coldspring and embedded lightwire in ColdBox. THe new version also has this method exposed in the Utilities plugin: placeholderReplacer(), which can be used for ANY application you want to use ${} groupings. The difference on my approach is that you can use it for any string, struct and have nested structure evaluations, plus it is super tiny.

Enjoy.
Posted by Luis Majano on November 12, 2008 at 12:36 AM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Time to take the Turing Test!!!

What letter comes one place(s) before the letter H? (in the alphabet, if that wasn't already apparent)
Type your answer exactly one time(s) in the designated box.

Type in the answer to the question you see above:

Your comment:

Sorry, no HTML allowed!