<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Brian Kotek: Inversion of Control - ColdSpring</title>
			<link>http://www.briankotek.com/blog/index.cfm</link>
			<description>Brian Kotek on ExtJS, DeftJS, CoffeeScript, Java, Groovy, Grails, Design Patterns, and Object-Oriented Programming</description>
			<language>en-us</language>
			<pubDate>Wed, 22 May 2013 02:27:47 -0700</pubDate>
			<lastBuildDate>Wed, 16 Dec 2009 09:49:00 -0700</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>brian428@briankotek.com</managingEditor>
			<webMaster>brian428@briankotek.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>brian428@briankotek.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>Iterator on RIAForge, and Updates to FormUtils and ColdSpring Utils</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/12/16/Iterator-on-RIAForge-and-Updates-to-FormUtils-and-ColdSpring-Uti</link>
				<description>
				
				The blog has been quiet lately, but that should be changing now that I&apos;m finally doing some real work with ColdFusion 9! In the meantime, I&apos;ve committed a few minor updates to some RIAForge projects, and added a new one.

The new project is &lt;a href=&quot;http://collectioniterator.riaforge.org/&quot; target=&quot;_blank&quot;&gt;Collection Iterator&lt;/a&gt;. This is simply a CFC that allows you to iterate the same way over queries, lists, structures, or arrays. The syntax is simple:

&lt;code&gt;
var array = [&apos;foo&apos;, &apos;boo&apos;, &apos;zoo&apos;];
var iterator = new Iterator( array );
var counter = 0;

while( iterator.hasNext() )
{
    counter++;
    var thisRow = iterator.next();
    assertTrue( array[counter] == thisRow, &quot;Array element not found.&quot; );    
}

assertTrue( counter == 3, &quot;Iterator did not loop the correct number of times.&quot; );    
&lt;/code&gt;

The obvious benefit is that it lets you handle all four collection types in a standard way. This is a CF9-only component, as it is written using the new script-only CFC syntax (which I LOVE, but will be talking about further in future entries).

As for updates, I fixed a bug in the DynamicXMLBeanFactory, which is part of the &lt;a href=&quot;http://coldspringutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;ColdSpring Bean Utilities library&lt;/a&gt;. There was an issue when using ColdSpring configuration files that imported multiple other config files. The CFC was also modified to only attempt to do an ExpandPath() on the configuration file location if a file doesn&apos;t exist using the value supplied by the developer. I also updated the &lt;a href=&quot;http://formutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;FormUtils CFC&lt;/a&gt; to make the constructor arguments optional, to make it easier to configure and use.

So, that&apos;s all for now, but look for some entries on CF9 ORM tips and techniques, as well as a full reboot of my earlier series on the Swiz framework for Flex. &lt;a href=&quot;http://swizframework.org/2009/12/swiz-1-0-0-alpha-released/&quot; target=&quot;_blank&quot;&gt;Swiz 1.0 alpha was just released&lt;/a&gt;, and as the finishing touches are added I plan to be blogging about all the excellent new capabilities that have been added by the Swiz team!
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<category>FormUtilities CFC</category>
				
				<pubDate>Wed, 16 Dec 2009 09:49:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/12/16/Iterator-on-RIAForge-and-Updates-to-FormUtils-and-ColdSpring-Uti</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>ColdSpring on TheServerSide.com</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/1/6/ColdSpring-on-TheServerSidecom</link>
				<description>
				
				Just a quick note that &lt;a href=&quot;http://www.theserverside.com/tt/articles/article.tss?l=ColdSpringDependencyInjectionFramework&quot; target=&quot;_blank&quot;&gt;an article on ColdSpring&lt;/a&gt; that I wrote for TheServerSide is now online.
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>OOP CF</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Tue, 06 Jan 2009 17:08:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/1/6/ColdSpring-on-TheServerSidecom</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>What&apos;s New In ColdSpring 1.2?</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/9/22/Whats-New-In-ColdSpring-12</link>
				<description>
				
				Some folks on the list asked (understandably) for a &quot;what&apos;s new&quot; list for ColdSpring 1.2, so I put this together. We should get it up on the site shortly as well:

&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Bean Aliases:&lt;/b&gt; Allows you to define additional bean IDs for existing beans. i.e.:
&lt;code&gt;
&lt;bean id = &quot;myBean&quot; class=&quot;com.myBean&quot; /&gt;
&lt;alias name=&quot;myBean&quot; alias=&quot;anotherIDForMyBean&quot; /&gt;
&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;&lt;b&gt;Abstract / Parent Beans:&lt;/b&gt; Allows you to reduce XML duplication by defining common properties and settings in a parent bean that can be used by multiple child beans. See Quickstart Guide for full details and examples.
&lt;/li&gt;

&lt;li&gt;&lt;b&gt;Collection Factory Beans (ListFactoryBean and MapFactoryBean):&lt;/b&gt; Factory beans that will create collections. ListFactoryBean creates an Array, MapFactoryBean creates a structure.

&lt;code&gt;
&lt;bean id=&quot;myList&quot; class=&quot;coldspring.beans.factory.config.ListFactoryBean&quot;&gt;
&lt;property name=&quot;sourceList&quot;&gt;
	&lt;list&gt;
		&lt;value&gt;Array Element 1&lt;/value&gt;
		&lt;value&gt;Array Element 2&lt;/value&gt;
		&lt;value&gt;Array Element 3&lt;/value&gt;
	&lt;/list&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;myList&quot; class=&quot;coldspring.beans.factory.config.MapFactoryBean&quot;&gt;
&lt;property name=&quot;sourceMap&quot;&gt;
	&lt;map&gt;
		&lt;entry key=&quot;keyA&quot;&gt;&lt;value&gt;keyA value&lt;/value&gt;&lt;/entry&gt;
		&lt;entry key=&quot;keyB&quot;&gt;&lt;value&gt;keyB value&lt;/value&gt;&lt;/entry&gt;
		&lt;entry key=&quot;keyC&quot;&gt;&lt;value&gt;keyC value&lt;/value&gt;&lt;/entry&gt;
	&lt;/map&gt;
&lt;/property&gt;
&lt;/bean&gt; 
&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;&lt;b&gt;Import XML directive:&lt;/b&gt; Allows you to include the contents of a separate ColdSpring XML file into another ColdSpring XML file:

&lt;code&gt;
&lt;beans&gt;
	&lt;import resource=&quot;/myotherxmlfile.xml&quot; /&gt;
&lt;/beans&gt;
&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;&lt;b&gt;Bean Factory Postprocessors:&lt;/b&gt; Allows you to specify a component that will run after all beans have been processed and apply additional processing on the bean definitions. ColdSpring will call postProcessBeanFactory() on each postprocessor, and you can then run any additional processing you would like to. For an example, look at /beans/factory/config/PropertyPlaceholderConfigurer.cfc.
&lt;/li&gt;

&lt;li&gt;&lt;b&gt;coldspring.cfcunit.AbstractAutowireTests and coldspring.cfcunit.AbstractAutowireTransactionalTests:&lt;/b&gt; Both of these allow you to provide the location of your applications bean config file and then simply define setters for any beans you want to test. The transactional version automatically rolls back database transactions. You can read &lt;a href=&quot;http://cdscott.blogspot.com/2007/11/even-more-coldspring-updates.html&quot;&gt;Chris Scott&apos;s blog entry&lt;/a&gt; about both of these.
&lt;/li&gt;

&lt;li&gt;&lt;b&gt;Numerous bug fixes and improvements:&lt;/b&gt; Over 30 bug or enhancement tickets have been resolved, with &lt;b&gt;critical improvements in thread safety&lt;/b&gt;, having ColdSpring call inherited methods and constructors during autowiring and bean creation, automatic support for creating any beans marked with lazy-init=&quot;false&quot; at bean factory creation, and many others.
&lt;/li&gt;
&lt;/ul&gt;
				
				</description>
				
				
				<category>Development</category>
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Mon, 22 Sep 2008 11:52:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/9/22/Whats-New-In-ColdSpring-12</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>ColdSpring 1.2 Gold, and New ColdSpring Site</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/9/12/ColdSpring-12-Gold-and-New-ColdSpring-Site</link>
				<description>
				
				After a long wait, version 1.2 of the &lt;a href=&quot;http://www.coldspringframework.org&quot; target=&quot;_blank&quot;&gt;ColdSpring dependency injection framework&lt;/a&gt; has been released. This includes a large number of bug fixes and enhancements since the last official release.

Along with 1.2 is a new ColdSpring web site. Rachel Lehman did a great job with the new design. And of course, hats off to the others on the team (Chris Scott, Dave Ross, Adam Lehman, Kurt Wiersma, and others) for all the work on ColdSpring over the months and years!

To toot my own horn a little, in addition to fixes and enhancements, I added a new example to the ColdSpring codebase called the &lt;a href=&quot;http://www.coldspringframework.org/coldspring/examples/quickstart/&quot; target=&quot;_blank&quot;&gt;ColdSpring Quickstart Guide&lt;/a&gt; which you can see at the live site, but can also run locally if you&apos;d like to look at the code (it&apos;s all live ColdSpring code). Since our next task is a full update of the documentation, I thought adding this would be a good interim step while we get that in place.

Anyway, what are you waiting for?! Go check out the new site and grab the latest release if you don&apos;t have it already. :-)
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Fri, 12 Sep 2008 09:05:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/9/12/ColdSpring-12-Gold-and-New-ColdSpring-Site</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>BeanInjector Patch from Paul Marcotte</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/8/4/BeanInjector-Patch-from-Paul-Marcotte</link>
				<description>
				
				Paul Marcotte sent me over a small test case that demonstrated an issue with the BeanInjector CFC. I went through his test and discovered a bug in the BeanInjector that stopped recursion up the inheritance hierarchy in certain cases. This has been fixed and pushed out to the &lt;a href=&quot;http://coldspringutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;ColdSpring Bean Utilities RIAForge project&lt;/a&gt;. 

Thanks to Paul for helping me to spot this, as well as sending over a very small test case to help me reproduce the problem. I can&apos;t overstate how valuable this sort of thing is. Removing any extraneous code and just including the files that are involved in the problem really makes it easier to track down bugs.
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Mon, 04 Aug 2008 09:59:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/8/4/BeanInjector-Patch-from-Paul-Marcotte</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>My IECFUG Presentation Recording and Files</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/7/15/My-IECFUG-Presentation-Recording-and-Files</link>
				<description>
				
				Last Friday I gave a presentation to the Inland Empire ColdFusion User Group. It covered a range of topics: &lt;a href=&quot;http://www.mxunit.org&quot; target=&quot;_blank&quot;&gt;MXUnit&lt;/a&gt;, &lt;a href=&quot;http://coldmock.riaforge.org/&quot; target=&quot;_blank&quot;&gt;ColdMock&lt;/a&gt;, and elements of my RIAForge &lt;a href=&quot;http://formutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;FormUtilities&lt;/a&gt; and &lt;a href=&quot;http://coldspringutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;ColdSpring Bean Utilities&lt;/a&gt; projects.

The presentation went well, I think. There are a few technical issues towards the end when they were trying to set up a microphone to get a Q&amp;A going, but they are minor. I&apos;ve linked to the files and the recording below in case anyone is interested in having a look. Thanks again to Sami, Luis, and the IECFUG for allowing me to present!

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.briankotek.com/blog/files/iecfug_presentation_brian_kotek.zip&quot; target=&quot;_blank&quot;&gt;PowerPoint presentation and associated code examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://adobechats.adobe.acrobat.com/p58908414/&quot; target=&quot;_blank&quot;&gt;Connect recording&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>Unit Testing</category>
				
				<category>ColdSpring</category>
				
				<category>FormUtilities CFC</category>
				
				<category>ColdMock</category>
				
				<category>Presentations</category>
				
				<pubDate>Tue, 15 Jul 2008 13:44:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/7/15/My-IECFUG-Presentation-Recording-and-Files</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>DynamicXMLBeanFactory and Custom FactoryBeans added to ColdSpring Utils Project</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/7/10/DynamicXMLBeanFactory-and-Custom-FactoryBeans-added-to-ColdSpring-Utils-Project</link>
				<description>
				
				Late last night I updated the &lt;a href=&quot;http://coldspringutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;ColdSpring Bean Utilities RIAForge project&lt;/a&gt;. The updates include:

&lt;ul&gt;
&lt;li&gt;Added DynamicXMLBeanFactory: This extends the standard DefaultXMLBeanFactory but allows the ability to replace dynamic properties anywhere in the XML file, as well as in imported XML files.&lt;/li&gt;
&lt;li&gt;Added MetadataAwareProxyFactoryBean: This extends the ColdSpring ProxyFactoryBean and automatically injects metadata information into any Advices that extend AbstractMetadataAwareAdvice after the AOP proxy is created.&lt;/li&gt;
&lt;li&gt;Added MetadataAwareRemoteFactoryBean: This extends the ColdSpring RemoteFactoryBean and automatically injects metadata information into any Advices that extend AbstractMetadataAwareAdvice after the remote proxy is created.&lt;/li&gt;
&lt;li&gt;Updated the AbstractMetadataAwareAdvice and the VOConverterAdvice for better integration with the new custom FactoryBeans.&lt;/li&gt;
&lt;li&gt;Added an Examples subfolder to show these components working. A readme file is include to explain how to set it up.&lt;/li&gt;
&lt;/ul&gt;

The CFCs themselves all contain fairly thorough documentation in their header comments, but I&apos;ll talk briefly about some of the new components.

The new custom FactoryBeans (MetadataAwareProxyFactoryBean and MetadataAwareRemoteFactoryBean) are something of uncharted territory for me, and I&apos;ll be interested to hear what some other ColdSpring users think of how I am doing this. Basically, these extend the base ColdSpring ProxyFactoryBean and RemoteFactoryBean and contain logic to loop over the advice chain and inject metadata information into any advices that extend AbstractMetadataAwareAdvice.

Back when I first started talking about making metadata available to Advices by having ColdSpring pass the beanID of the proxied bean into the Advice, there was a lot of concern about increased coupling between the Advices and ColdSpring. I believe that the way I am using this sidesteps the issue. 

My Advices are still extremely generic. All the metadata does is allow them to behave more flexibly. For example, I could create some security metadata that specifies different rules for different method calls, and a SecurityAdvice could would be able to process the correct rules for the current method call without a lot of conditional logic or actual dependence on the name of the bean or the name of the method. All it knows is that the metadata it was handed says &quot;apply these rules now&quot;, and it does. The same could be true for a LoggingAdvice. All it would know is that the metadata being passed to it says &quot;log these variables&quot;, and it does. The fact that you can specify different logging settings for different beans or methods is totally hidden from the Advice.

Overall I&apos;ve found these new components to be very useful. I hope others agree! As always, please reply with any questions or comments. Thanks.
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Thu, 10 Jul 2008 08:23:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/7/10/DynamicXMLBeanFactory-and-Custom-FactoryBeans-added-to-ColdSpring-Utils-Project</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Ask Brian: How to Handle Object Composition?</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/6/12/Ask-Brian-How-to-Handle-Object-Composition</link>
				<description>
				
				Christopher R contacted me through my contact form to ask about object composition. I thought I would answer it here in case it helps other folks as well. I&apos;m also planning on answering questions like this going forward, so if anyone has questions that you think I can help with, feel free to contact me through the blog and I&apos;ll do my best to answer!

&lt;blockquote&gt;greetings...i recently came across a  great article you wrote called &lt;a target=&quot;_blank&quot; href=&quot;http://articles.techrepublic.com.com/5100-10878_11-5087794.html?tag=rbxccnbtr1&quot;&gt;&quot;Write efficient code with the Composition object pattern and CFCs&quot;&lt;/a&gt;. it greatly assisted in my initial dilemma involving how to relate distinct but related classes. the current article works for related classes (PhoneNumber) into which you pass a final piece of data (e.g. the phone number). however, whats the best approach when that data is merely a reference or pointer (e.g. PhoneID) that requires further querying / creation of data access objects? as an example, several customers may share the same phone number (PhoneID). in this case - bear in mind that we still want to stick to OOP + not introduce db queries into the related class (e.g. PhoneID.cfc) - we might use a DAO to communicate with the related class (e.g. PhoneDAO.cfc) into which we would need to pass a database ref along with the PhoneID(s) in order to find the proper record. i would like to return a reference to the Phone object that the main class (e.g.Customer) could then utilize. to better elucidate the approach, im following a series of articles at &lt;a target=&quot;_blank&quot; href=&quot;http://www.iknowkungfoo.com/blog/index.cfm/2007/10/23/Object-Oriented-Coldfusion--71--A-Basic-Data-Access-Object-DAO&quot;&gt;iknowkingfoo&lt;/a&gt;. 

hopefully this makes some sense - difficult to encapsulate in writing succintly. im getting up in arms as far as these objects, accessing their data as well as trying to access application variables. any help greatly appreciated.&lt;br /&gt;&lt;br /&gt;thanks in advance.&lt;br /&gt;&lt;/blockquote&gt;

To reiterate, composition models a &quot;has-a&quot; relationship between objects, as opposed to an &quot;is-a&quot; relationship which is typically done through inheritance or interface implementation. However, Christopher seems to be working with two different kinds of objects here: Singletons and business objects. How you handle the composition can depend on the kind of object you are dealing with and what they are meant to do.

For example, a PhoneDAO would almost certainly be a Singleton object, meaning that only one instance of the PhoneDAO exists in the application. However, a PhoneNumber object would be a business object, meaning that there could be many instances of PhoneNumber, each with their own data, modeling many different actual phone numbers. The same goes for Customer. Customer is a business object.

The question seems to be how to build up composite object relationships in your business objects. The answer is usually to use a Factory to build your business object. The Factory would also be a Singleton since you only need one. So Christopher might consider creating a CustomerFactory which he would call &quot;getCustomer(13)&quot; on to create an instance of that Customer and return it. The factory would then be responsible for also creating and setting any composite objects. As a result, the factory may itself have other singletons composed within it such as a CustomerDAO, PhoneNumberDAO, etc. The factory would use these objects and know what to do with the results (in this case, setting the resulting PhoneNumber into the resulting Customer before returning it).

The idea with factories is not only that they create objects. It has to do with the primary OO design principle of encapsulation. What the factory encapsulates is knowledge of how to create and relate a Customer and a PhoneNumber. This is crucial to understand, because it means that you become free to change how the Customer and PhoneNumber are created and related at any time. Nothing outside the factory would ever know that you made any changes.

Consider the &lt;a target=&quot;_blank&quot; href=&quot;http://docs.transfer-orm.com/&quot;&gt;Transfer ORM framework&lt;/a&gt;. Transfer handles making queries to the database as well as building object relationships for you. It is very handy, and I would recommend that Christopher have a look at it when he has the time to evaluate it. But lets say that he creates a CustomerFactory and any code that needs a user calls customerFactory.createCustomer(id). If he later decides to use Transfer, he can easily make that change because he only has to change one thing: the CustomerFactory. He can remove his own DAOs and rip out the logic that relates these objects, and replace it with calls to Transfer. Nothing outside his factory needs to know that the way these objects are being created has changed. That is the beauty and power of encapsulation, and why factories are so useful.

For building composite relationships in your Singletons, there is another option to consider: the &lt;a target=&quot;_blank&quot; href=&quot;http://www.coldspringframework.org/&quot;&gt;ColdSpring framework&lt;/a&gt;. This framework is designed primarily to &quot;wire up&quot; or relate your Singleton objects. That means things like Services, DAOs, Gateways, etc. It is a really powerful tool but does have a learning curve to wrap your head around. I have a number of &lt;a href=&quot;http://www.briankotek.com/blog/index.cfm?mode=cat&amp;catid=963BA7A1-3048-23C1-DDD298C03361DDC9&quot; target=&quot;_blank&quot;&gt;blog entries on ColdSpring&lt;/a&gt; and there are numerous other blogs and &lt;a href=&quot;http://groups.google.com/group/coldspring-users&quot; target=&quot;_blank&quot;&gt;mailing lists&lt;/a&gt; that can help with this as well. If you give ColdSpring a look and I can offer any additional help please let me know.

Hopefully that helps, Christopher? I&apos;d look at using a factory to handle creating and relating your objects. The factories can get rather complex if you have a lot of object relationships to manage, but again, the logic is all kept in the factories. It&apos;s certainly possible for one factory to use another factory as well, so don&apos;t feel like you have to create a single uber-factory that does everything. And if or when you decide to try out another approach such as Transfer, you&apos;ll be happy you went the factory route. Good luck!
				
				</description>
				
				
				<category>Development</category>
				
				<category>Design Patterns</category>
				
				<category>ColdFusion</category>
				
				<category>OOP CF</category>
				
				<category>Ask Brian</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Thu, 12 Jun 2008 11:11:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/6/12/Ask-Brian-How-to-Handle-Object-Composition</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>More on Extending ColdSpring: A Custom BeanFactory</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/6/6/More-on-Extending-ColdSpring-A-Custom-BeanFactory</link>
				<description>
				
				The more I dig into how ColdSpring works the more impressed I am with it (and I was already hella impressed). I&apos;m realizing that a lot of the &lt;a href=&quot;http://coldspringutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;utility and helper CFCs I&apos;ve created and released on RIAForge&lt;/a&gt; can actually be implemented directly within ColdSpring by extending it.
				 [More]
				</description>
				
				
				<category>Development</category>
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Fri, 06 Jun 2008 12:38:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/6/6/More-on-Extending-ColdSpring-A-Custom-BeanFactory</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Extending ColdSpring Through Custom Factory Beans</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/6/3/Extending-ColdSpring-Through-Custom-Factory-Beans</link>
				<description>
				
				Before I jumped across the pond to London and Paris last week, I had &lt;a href=&quot;http://www.briankotek.com/blog/index.cfm/2008/5/19/More-on-ColdSpring-and-Remote-Facades&quot;&gt;posted a blog entry about ColdSpring Remote Proxies&lt;/a&gt;. In response to some of the comments and IM messages, I wanted to expand on my mention of extending ColdSpring with your own Factory Beans. The ability to create your own extensions to ColdSpring is an extremely powerful technique. Unfortunately, it&apos;s also an extremely unexplained technique! I hope to change that a bit, so let&apos;s get to it.

If you aren&apos;t familiar with ColdSpring&apos;s ability to automatically generate Remote Proxy components, I&apos;ll refer you to a few blog entries:

&lt;ul&gt;&lt;li&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://www.coldspringframework.org/docs/Developing_w__ColdSpring.htm#ColdSpring_and_Remoting&quot;&gt;ColdSpring Documentation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://www.iterateme.com/blog/index.cfm/2007/10/30/A-Guide-to-Automatic-Remote-Proxy-Generation-in-ColdSpring&quot;&gt;Brian Klaas - A Guide to Automatic Remote Proxy Generation in ColdSpring&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://andyjarrett.co.uk/andy/blog/index.cfm/2008/5/19/ColdSpring-and-Remote-Facades&quot;&gt;Andy Jarrett - ColdSpring and Remote Facades&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;

In a nutshell, ColdSpring can create remote proxy CFCs for your actual underlying CFCs, typically service layer components. Which is pretty darn sweet. Unfortunately, the configuration XML to do this can get rather verbose, especially if you want to create numerous proxies. Consider:

&lt;code&gt;
&lt;bean id=&quot;remoteUserService&quot; class=&quot;coldspring.aop.framework.RemoteFactoryBean&quot;&gt;
	&lt;property name=&quot;target&quot;&gt;
		&lt;ref bean=&quot;userService&quot; /&gt;
	&lt;/property&gt;
	&lt;property name=&quot;beanFactoryScope&quot;&gt;
		&lt;value&gt;application&lt;/value&gt;
	&lt;/property&gt;        
	&lt;property name=&quot;beanFactoryName&quot;&gt;
		&lt;value&gt;beanFactory&lt;/value&gt;
	&lt;/property&gt;    
	&lt;!--- Physical name given to the proxy component ---&gt;
	&lt;property name=&quot;serviceName&quot;&gt;
		&lt;value&gt;RemoteUserService&lt;/value&gt;
	&lt;/property&gt;
	&lt;!--- location to the physical proxy component ---&gt;
	&lt;property name=&quot;relativePath&quot;&gt;
		&lt;value&gt;/remote&lt;/value&gt;
	&lt;/property&gt;
	&lt;!--- you could have something like get* for all get methods only ---&gt;
	&lt;property name=&quot;remoteMethodNames&quot;&gt;
		&lt;value&gt;*&lt;/value&gt;
	&lt;/property&gt;
&lt;/bean&gt;
&lt;/code&gt;

It seems like a lot, and I suppose it is. The good news is that you only have to do it one time, at the start of your project. Still, my previous blog entry showed that you can trim this down a bit, especially if you are creating more than one remote proxy:

&lt;code&gt;
&lt;!--- Create a parent bean that all concrete remote proxies to extend, which reduces the XML for the child beans. ---&gt;
&lt;bean id=&quot;abstractRemoteProxy&quot; class=&quot;&quot; abstract=&quot;true&quot;&gt;
	&lt;property name=&quot;beanFactoryScope&quot;&gt;
		&lt;value&gt;application&lt;/value&gt;
	&lt;/property&gt;
	&lt;property name=&quot;beanFactoryName&quot;&gt;
		&lt;value&gt;beanFactory&lt;/value&gt;
	&lt;/property&gt;
	&lt;!--- location to the physical proxy component ---&gt;
	&lt;property name=&quot;relativePath&quot;&gt;
		&lt;value&gt;/remote&lt;/value&gt;
	&lt;/property&gt;
&lt;/bean&gt;

&lt;!--- Concrete bean extends the abstract parent bean. ---&gt;
&lt;bean id=&quot;remoteUserService&quot; class=&quot;coldspring.aop.framework.RemoteFactoryBean&quot; parent=&quot;abstractRemoteProxy&quot; lazy-init=&quot;false&quot;&gt;
	&lt;property name=&quot;target&quot;&gt;
		&lt;ref bean=&quot;userService&quot; /&gt;
	&lt;/property&gt;
	&lt;!--- Physical name given to the proxy component ---&gt;
	&lt;property name=&quot;serviceName&quot;&gt;
		&lt;value&gt;RemoteUserService&lt;/value&gt;
	&lt;/property&gt;
	&lt;!--- you could have something like get* for all get methods only ---&gt;
	&lt;property name=&quot;remoteMethodNames&quot;&gt;
		&lt;value&gt;*&lt;/value&gt;
	&lt;/property&gt;
&lt;/bean&gt;
&lt;/code&gt;

Better, but I still think we can improve on it. But this is where we go into potentially scary territory: we&apos;re going to extend ColdSpring to make our lives easier. In this case, I&apos;m going to create my own custom Remote Factory Bean that extends ColdSpring&apos;s RemoteFactoryBean and sets up some default values that I tend to use over and over in my applications. This reduces the XML configuration even further, but still allows me to override the defaults if I need to. Here is the XML:

&lt;code&gt;
&lt;bean id=&quot;abstractRemoteProxy&quot; class=&quot;&quot; abstract=&quot;true&quot;&gt;
	&lt;property name=&quot;relativePath&quot;&gt;
		&lt;value&gt;/remote&lt;/value&gt;
	&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;remoteUserService&quot; class=&quot;factory.CustomRemoteFactoryBean&quot; parent=&quot;abstractRemoteProxy&quot; lazy-init=&quot;false&quot;&gt;
	&lt;property name=&quot;targetBeanID&quot;&gt;
		&lt;value&gt;UserService&lt;/value&gt;
	&lt;/property&gt;
	&lt;property name=&quot;remoteMethodNames&quot;&gt;
		&lt;value&gt;*&lt;/value&gt;
	&lt;/property&gt;
&lt;/bean&gt;
&lt;/code&gt;

Hmm, that&apos;s quite a bit shorter! You&apos;ll notice that my RemoteUserService is specifying it&apos;s class as &quot;CustomRemoteFactoryBean&quot;. That&apos;s the first change. You may also notice that many of the properties are gone, but a new one has appeared: &quot;targetBeanID&quot;. By passing the targetBeanID to my custom factory bean, I can set up a series of default property values due to the fact that my remote proxies tend to follow a fairly standard setup. Here is the code for the CustomRemoteFactoryBean to demonstrate what it is doing:

&lt;code&gt;
&lt;cfcomponent name=&quot;CustomRemoteFactoryBean&quot; extends=&quot;coldspring.aop.framework.RemoteFactoryBean&quot; hint=&quot;I add custom behavior to Remote Factory Beans.&quot;&gt;
	
	&lt;cffunction name=&quot;init&quot; access=&quot;public&quot; returntype=&quot;any&quot; hint=&quot;Constructor.&quot;&gt;
		&lt;cfset super.init() /&gt;
		&lt;cfreturn this /&gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;getObject&quot; access=&quot;public&quot; returntype=&quot;any&quot; output=&quot;true&quot;&gt;
		&lt;cfset var local = StructNew() /&gt;
		
		&lt;!--- If the current bean is not constructed, set default values. ---&gt;
		&lt;cfif not isConstructed()&gt;
		
			&lt;!--- Default the service name to the name of the target bean ID with &apos;Remote&apos; appended to the front of it. ---&gt;
			&lt;cfif not StructKeyExists(variables, &apos;serviceName&apos;) or not Len(variables.serviceName)&gt;
				&lt;cfset setServiceName(&apos;Remote#getTargetBeanID()#&apos;) /&gt;
			&lt;/cfif&gt;
			
			&lt;!--- Set the target to the bean referenced by the target bean ID. ---&gt;
			&lt;cfif not StructKeyExists(variables, &apos;target&apos;) or not IsObject(variables.target)&gt;
				&lt;cfset setTarget(getBeanFactory().getBean(getTargetBeanID())) /&gt;
			&lt;/cfif&gt;
			
			&lt;!--- Set default Bean Factory Name. ---&gt;
			&lt;cfif not StructKeyExists(variables, &apos;beanFactoryName&apos;) or not Len(variables.beanFactoryName)&gt;
				&lt;cfset setBeanFactoryName(&apos;beanFactory&apos;) /&gt;
			&lt;/cfif&gt;
			
			&lt;!--- Set default Bean Factory Scope. ---&gt;
			&lt;cfif not StructKeyExists(variables, &apos;beanFactoryScope&apos;) or not Len(variables.beanFactoryScope)&gt;
				&lt;cfset setBeanFactoryScope(&apos;application&apos;) /&gt;
			&lt;/cfif&gt;
			
		&lt;/cfif&gt;
		&lt;cfset local.object = super.getObject() /&gt;
		&lt;cfreturn local.object /&gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;getTargetBeanID&quot; access=&quot;public&quot; returntype=&quot;string&quot; output=&quot;false&quot; hint=&quot;I return the Target Bean ID.&quot;&gt;
		&lt;cfreturn variables[&apos;targetBeanID&apos;] /&gt;
	&lt;/cffunction&gt;
		
	&lt;cffunction name=&quot;setTargetBeanID&quot; access=&quot;public&quot; returntype=&quot;void&quot; output=&quot;false&quot; hint=&quot;I set the Target Bean ID.&quot;&gt;
		&lt;cfargument name=&quot;targetBeanID&quot; type=&quot;string&quot; required=&quot;true&quot; hint=&quot;TargetBeanID&quot; /&gt;
		&lt;cfset variables[&apos;targetBeanID&apos;] = arguments.targetBeanID /&gt;
	&lt;/cffunction&gt;
	
&lt;/cfcomponent&gt;
&lt;/code&gt;

The CustomRemoteFactoryBean extends the ColdSpring RemoteFactoryBean and adds additional behavior. If you weren&apos;t aware, under the hood ColdSpring calls getObject() on the RemoteFactoryBean when it needs to create an instance of your remote proxy. You can see that my getObject() method is automatically setting up default values for the service name, target, bean factory name, and bean factory scope if these are not defined. Then it simply calls the superclass&apos;s getObject() method to actually create the remote proxy. This is how I can get away with specifying so little in the XML.

Your first reaction might be &quot;OK that&apos;s kind of cool because I hate typing XML, but is that really it?&quot; Yes, that is it! For this blog entry anyway, since it&apos;s gotten rather long. But if people want me to keep going I can expand further. In the meantime, you might start thinking about what sort of behavior you can add to your own custom getObject() method that adds behavior beyond defining simple default values. And please fire away with thoughts or comments!
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Tue, 03 Jun 2008 18:05:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/6/3/Extending-ColdSpring-Through-Custom-Factory-Beans</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>More on ColdSpring and Remote Facades</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/5/19/More-on-ColdSpring-and-Remote-Facades</link>
				<description>
				
				&lt;div style=&apos;&apos;&gt;Andy Jarrett posted a very nice overview of &lt;a href=&quot;http://andyjarrett.co.uk/andy/blog/index.cfm/2008/5/18/ColdSpring-and-Remote-Facades&quot; target=&quot;_blank&quot;&gt;using ColdSpring to create Remote Proxies for your CFCs&lt;/a&gt;. I wanted to add a bit more to what he was saying and see if anyone has an interest in more details.

The first bit is just a small change that makes life easier. In Andy&apos;s example, he defines the remote proxy in his ColdSpring XML file and then manually calls getBean() to create that remote proxy. You actually can do this in an easier way, using the lazy-init attribute and the constructNonLazyBeans argument. If you pass &quot;constructNonLazyBeans=true&quot; as an argument to loadBeansFromXML, ColdSpring will automatically create any beans that you have not explicitly marked as lazy. Which means you can avoid having to manually call getBean() for all of your remote proxies. You just need to execute one initial request to your application, and it will create the remote proxies automatically. This is handy if you start having numerous remote proxies being generated.

Next is a small tip to make your configuration life a little easier. Andy shows the XML to define a remote proxy. It&apos;s fairly verbose XML, unfortunately. That&apos;s just how ColdSpring is. However, we could make life a bit easier on ourselves by defining a parent bean and setting common values there. Again, this makes life easier once you start getting into multiple remote proxies. You can do something like this:

&lt;code&gt;
&lt;bean id=&quot;abstractRemoteProxy&quot; class=&quot;&quot; abstract=&quot;true&quot;&gt;
	&lt;property name=&quot;beanFactoryScope&quot;&gt;
		&lt;value&gt;application&lt;/value&gt;
	&lt;/property&gt;      
	&lt;property name=&quot;beanFactoryName&quot;&gt;
		&lt;value&gt;beanFactory&lt;/value&gt;
	&lt;/property&gt;   
	&lt;!--- location to the physical proxy component ---&gt;
	&lt;property name=&quot;relativePath&quot;&gt;
		&lt;value&gt;/remote_cs&lt;/value&gt;
	&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;userServices_remote&quot; class=&quot;coldspring.aop.framework.RemoteFactoryBean&quot; parent=&quot;abstractRemoteProxy&quot; lazy-init=&quot;false&quot;&gt;
	&lt;property name=&quot;target&quot;&gt;
		&lt;ref bean=&quot;userServices&quot; /&gt;
	&lt;/property&gt;
	&lt;!--- Physical name given to the proxy component ---&gt;
	&lt;property name=&quot;serviceName&quot;&gt;
		&lt;value&gt;rUserServices&lt;/value&gt;
	&lt;/property&gt;
	&lt;!--- you could have something like get* for all get methods only ---&gt;
	&lt;property name=&quot;remoteMethodNames&quot;&gt;
		&lt;value&gt;*&lt;/value&gt;
	&lt;/property&gt;
&lt;/bean&gt;
&lt;/code&gt;

As you can see, assuming you are OK with having the same bean factory name, having the remote proxies be created in one central folder, etc., you can cut down the amount of XML you have to write per-proxy by a lot.

And one last time, don&apos;t forget that you can extend the base RemoteFactoryBean and ProxyFactoryBean components that ColdSpring uses to define your own custom behavior. This can reduce work even more by letting you skip a lot of the XML entirely and define settings or behavior directly in your custom Factory Bean. I can expand on this if anyone wants to hear more, I&apos;m just not sure how many people are actually using these parts of ColdSpring so I thought I would ask before I launch into a blog entry that no one cares about. ;-)

&lt;/div&gt;
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Mon, 19 May 2008 09:14:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/5/19/More-on-ColdSpring-and-Remote-Facades</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Slides and Code from My Code Generation Presentation</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/5/3/Presentation-and-Code-from-My-Code-Generation-Presentation</link>
				<description>
				
				As promised, here are the slides and code from my cf.Objective() 2008 presentation, &quot;Leveraging Code Generation to Jumpstart Your Development&quot;. Check the bottom of this entry for the enclosure.

So far the conference has been great. I&apos;ve learned a lot at several sessions, including Andrew Powell&apos;s integration presentation on using Spring and Hibernate as the Java model for an app using CF for Controller and View. Chris Scott&apos;s ColdSpring presentation got my wheels turning with regard to custom Proxy Factories. And the announcement of the ColdFusion Open Initiative was most welcome, with a public bug base and more organized enhancement request system.

I&apos;ll post more after the conference is over, but so far it&apos;s been as good as I expected it to be!
				
				</description>
				
				
				<category>Development</category>
				
				<category>Transfer</category>
				
				<category>ColdFusion</category>
				
				<category>CFC Stub Generator</category>
				
				<category>Conferences</category>
				
				<category>ColdSpring</category>
				
				<category>Reactor</category>
				
				<pubDate>Sat, 03 May 2008 14:48:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/5/3/Presentation-and-Code-from-My-Code-Generation-Presentation</guid>
				
				
				<enclosure url="http://www.briankotek.com/blog/enclosures/brian_kotek_cfobjective08_code_gen.zip" length="367243" type="application/zip"/>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Meet ColdSpringXMLUtils, a New Addition to the ColdSpring Bean Utilities Family</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/3/21/Meet-ColdSpringXMLUtils-a-New-Addition-to-the-ColdSpring-Bean-Utilities-Family</link>
				<description>
				
				One thing that I&apos;ve heard people ask about in the ColdSpring mailing list over the years relates to properties. These are quite useful. If you didn&apos;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&apos;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&apos;t put dynamic properties anywhere in the XML.

Well, now you can!

The ColdSpringXMLUtils component has joined the &lt;a target=&quot;_blank&quot; href=&quot;http://coldspringutils.riaforge.org/&quot;&gt;ColdSpring Bean Utilities RIAForge project&lt;/a&gt;. 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 &lt;b&gt;anywhere in the XML&lt;/b&gt;.
    
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:
        
&lt;code&gt;
&lt;bean id=&quot;userService&quot; class=&quot;myapp.components.services.userService&quot; /&gt;
&lt;/code&gt;

Using this CFC, you could make part or all of the class name dynamic, like this:

&lt;code&gt;
&lt;bean id=&quot;userService&quot; class=&quot;${servicePackage}.userService&quot; /&gt;
&lt;/code&gt;

You would then define a data structure to map the dynamic properties to the values that you want:

&lt;code&gt;
&lt;cfscript&gt;
dynamicProperties = StructNew();
dynamicProperties.servicePackage = &quot;myapp.components.services&quot;;
&lt;/cfscript&gt;
&lt;/code&gt;

Then simply use this CFC to create the bean factory like this:

&lt;code&gt;
&lt;cfset coldSpringXMLUtils = CreateObject(&apos;component&apos;, &apos;path.to.ColdSpringXMLUtils&apos;).init() /&gt;
&lt;cfset beanFactory = coldSpringXMLUtils.loadDynamicColdSpring(&apos;/myapp/config/coldspring.xml&apos;, dynamicProperties) /&gt;
&lt;/code&gt;

This component will replace any matching dynamic properties in the XML, create the bean factory, and return it for you to use!

I&apos;ve added this component to the zip file and SVN repository at RIAForge. I hope folks find it useful!
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<pubDate>Fri, 21 Mar 2008 08:36:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/3/21/Meet-ColdSpringXMLUtils-a-New-Addition-to-the-ColdSpring-Bean-Utilities-Family</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>BeanInjector Update (now at RIAForge!) and ColdMock update</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/3/12/BeanInjector-Update-now-at-RIAForge-and-ColdMock-update</link>
				<description>
				
				I&apos;ve updated the BeanInjector component and have created an RIAForge project to host these until we can figure out where these will live in the ColdSpring repository. The ColdSpring Bean Utilities project is at &lt;a href=&quot;http://coldspringutils.riaforge.org/&quot; target=&quot;_blank&quot;&gt;http://coldspringutils.riaforge.org/&lt;/a&gt;. It includes the BeanInjector and TDOBeanInjectorObserver, as well as the AbstractMetadataAwareAdvice, VOConverterAdvice, and GenericVOConverter. A zip file and Subversion access are available at RIAForge.

There is an update to the BeanInjector specifically. Bob Silverberg noticed a non-var-scoped variable during the initial caching of the metadata for the target object. This shouldn&apos;t actually affect anyone since the code lives in an exclusive lock, but better safe than sorry. Thanks Bob!

There&apos;s also a small update to ColdMock. You can now pass an optional argument named &quot;isVirtualMethod&quot; when you define a mock method. By default this is false, but if you specify true, ColdMock will skip all checks for the existence of the method, as well as argument and return type checks. This is useful if you want to mock a method that is injected dynamically into the component, since the metadata for the object will have no information on the dynamic method. So basically, you can define what the method will return, but you&apos;re on your own as far as making sure it is accepting and returning the proper types.

I hope folks find these useful!
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>ColdSpring</category>
				
				<category>ColdMock</category>
				
				<pubDate>Wed, 12 Mar 2008 15:02:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/3/12/BeanInjector-Update-now-at-RIAForge-and-ColdMock-update</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Unit Testing Transfer Decorators with CFCUnit, BeanInjector, and ColdMock</title>
				<link>http://www.briankotek.com/blog/index.cfm/2008/1/28/Unit-Testing-Transfer-Decorators-with-CFCUnit-BeanInjector-and-ColdMock</link>
				<description>
				
				Paul Marcotte asked me to post about how one might unit test a Transfer Decorator. So here you go Paul (and anyone else who might be interested) :-) .

To start with, basic testing of a Transfer Decorator is really no different than testing any other component. First, I set up a ColdSpring file to use for the test. Note that, depending on how many things you need to test and what you&apos;re testing, you can use the same ColdSpring file to test numerous things. In other words, you don&apos;t necessarily have to have a separate ColdSpring XML file for every test.

&lt;code&gt;
&lt;beans&gt;
	
	&lt;bean id=&quot;transferFactory&quot; class=&quot;transfer.transferFactory&quot;&gt;
	   &lt;constructor-arg name=&quot;datasourcePath&quot;&gt;&lt;value&gt;/tests/transfer/testing/datasource.xml&lt;/value&gt;&lt;/constructor-arg&gt;
	   &lt;constructor-arg name=&quot;configPath&quot;&gt;&lt;value&gt;/tests/transfer/testing/transfer.xml&lt;/value&gt;&lt;/constructor-arg&gt;
	   &lt;constructor-arg name=&quot;definitionPath&quot;&gt;&lt;value&gt;/tests/transfer/testing/definitions&lt;/value&gt;&lt;/constructor-arg&gt;
	&lt;/bean&gt;
	
	&lt;bean id=&quot;datasource&quot; factory-bean=&quot;transferFactory&quot; factory-method=&quot;getDatasource&quot; /&gt;

	&lt;bean id=&quot;transfer&quot; factory-bean=&quot;transferFactory&quot; factory-method=&quot;getTransfer&quot; /&gt;
	
&lt;/beans&gt;
&lt;/code&gt;

From here, the unit test might look like this (I&apos;m using CFCUnit but the approach in CFUnit would be similar):

&lt;code&gt;
&lt;cfcomponent name=&quot;TestRegisteredUser&quot; extends=&quot;org.cfcunit.framework.TestCase&quot;&gt;
	&lt;cffunction name=&quot;setUp&quot; access=&quot;public&quot; output=&quot;false&quot; hint=&quot;&quot;&gt;
		&lt;cfset var local = StructNew() /&gt;
		&lt;cfset local.config = &apos;/tests/transfer/testing/coldspring.xml.cfm&apos; /&gt;
		&lt;cfset beanFactory = CreateObject(&apos;component&apos;, &apos;coldspring.beans.DefaultXmlBeanFactory&apos;).init() /&gt;
		&lt;cfset beanFactory.loadBeansFromXmlFile(beanDefinitionFile=local.config) /&gt;
		&lt;cfset setRegisteredUser(beanFactory.getBean(&apos;transfer&apos;).get(&apos;user&apos;, 2)) /&gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;test_customDecoratorMethod&quot; returntype=&quot;void&quot; access=&quot;public&quot; output=&quot;false&quot; hint=&quot;&quot;&gt;
		&lt;cfset var local = StructNew() /&gt;
		&lt;cfset assertEqualsString(&quot;This is a custom method in the Decorator.&quot;, getRegisteredUser().customDecoratorMethod(), &apos;Custom decorator response does not match expected value.&apos;) /&gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;getRegisteredUser&quot; access=&quot;private&quot; output=&quot;false&quot; hint=&quot;I return the RegisteredUser.&quot;&gt;
		&lt;cfreturn variables.instance.RegisteredUser /&gt;
	&lt;/cffunction&gt;
		
	&lt;cffunction name=&quot;setRegisteredUser&quot; access=&quot;private&quot; output=&quot;false&quot; hint=&quot;I set the RegisteredUser.&quot;&gt;
		&lt;cfargument name=&quot;RegisteredUser&quot; required=&quot;true&quot; hint=&quot;RegisteredUser&quot; /&gt;
		&lt;cfset variables.instance.RegisteredUser = arguments.RegisteredUser /&gt;
	&lt;/cffunction&gt;
	
&lt;/cfcomponent&gt;
&lt;/code&gt;

As you can see, you grab the Decorator from Transfer, and then are free to test the methods in the Decorator the same way you would test any other CFC method.

To take this further, you can actually mix a number of the techniques that I&apos;ve talked about to handle more complex tests. In this example, I&apos;m using the TDOBeanInjectorObserver to wire in a ValidatorFactory to my Decorator. However, to keep the test isolated to the Decorator, I&apos;m using ColdMock to create a mock of the ValidatorFactory and injecting that into the Decorator:

&lt;code&gt;
&lt;beans&gt;
	
	&lt;bean id=&quot;transferFactory&quot; class=&quot;transfer.transferFactory&quot;&gt;
	   &lt;constructor-arg name=&quot;datasourcePath&quot;&gt;&lt;value&gt;/tests/transfer/testing/datasource.xml&lt;/value&gt;&lt;/constructor-arg&gt;
	   &lt;constructor-arg name=&quot;configPath&quot;&gt;&lt;value&gt;/tests/transfer/testing/transfer.xml&lt;/value&gt;&lt;/constructor-arg&gt;
	   &lt;constructor-arg name=&quot;definitionPath&quot;&gt;&lt;value&gt;/tests/transfer/testing/definitions&lt;/value&gt;&lt;/constructor-arg&gt;
	&lt;/bean&gt;
	
	&lt;bean id=&quot;datasource&quot; factory-bean=&quot;transferFactory&quot; factory-method=&quot;getDatasource&quot; /&gt;

	&lt;bean id=&quot;transfer&quot; factory-bean=&quot;transferFactory&quot; factory-method=&quot;getTransfer&quot; /&gt;
	
	&lt;bean id=&quot;validatorFactory&quot; factory-bean=&quot;MockFactory&quot; factory-method=&quot;createMock&quot;&gt;
		&lt;constructor-arg name=&quot;objectToMock&quot;&gt;
			&lt;value&gt;tests.transfer.testing.ValidatorFactory&lt;/value&gt;
		&lt;/constructor-arg&gt;
	&lt;/bean&gt;
	&lt;bean id=&quot;MockFactory&quot; class=&quot;coldmock.MockFactory&quot; /&gt;
	
	&lt;bean id=&quot;beanInjector&quot; class=&quot;common.components.utility.BeanInjector&quot;&gt;
		&lt;constructor-arg name=&quot;debugMode&quot;&gt;&lt;value&gt;false&lt;/value&gt;&lt;/constructor-arg&gt;
		&lt;constructor-arg name=&quot;suffixList&quot;&gt;&lt;value&gt;&lt;/value&gt;&lt;/constructor-arg&gt;
	&lt;/bean&gt;
	
	&lt;bean id=&quot;TDOBeanInjectorObserver&quot; class=&quot;common.components.transfer.TDOBeanInjectorObserver&quot; lazy-init=&quot;false&quot;&gt;
		&lt;constructor-arg name=&quot;transfer&quot;&gt;
			&lt;ref bean=&quot;transfer&quot; /&gt;
		&lt;/constructor-arg&gt;
		&lt;property name=&quot;beanInjector&quot;&gt;
			&lt;ref bean=&quot;beanInjector&quot; /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	
&lt;/beans&gt;
&lt;/code&gt;

This way, I can test any methods in the Decorator that actually rely on the ValidatorFactory by mocking the results from the ValidatorFactory method calls:

&lt;code&gt;
&lt;cfcomponent name=&quot;TestRegisteredUser&quot; extends=&quot;org.cfcunit.framework.TestCase&quot;&gt;
	&lt;cffunction name=&quot;setUp&quot; access=&quot;public&quot; output=&quot;false&quot; hint=&quot;&quot;&gt;
		&lt;cfset var local = StructNew() /&gt;
		&lt;cfset local.config = &apos;/tests/transfer/testing/coldspring.xml.cfm&apos; /&gt;
		&lt;cfset beanFactory = CreateObject(&apos;component&apos;, &apos;coldspring.beans.DefaultXmlBeanFactory&apos;).init() /&gt;
		&lt;cfset beanFactory.loadBeansFromXmlFile(beanDefinitionFile=local.config) /&gt;
		&lt;cfset setRegisteredUser(beanFactory.getBean(&apos;transfer&apos;).get(&apos;user&apos;, 2)) /&gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;test_customDecoratorMethodUsingValidator&quot; returntype=&quot;void&quot; access=&quot;public&quot; output=&quot;false&quot; hint=&quot;&quot;&gt;
		&lt;cfset var local = StructNew() /&gt;
		&lt;cfset local.validator = beanFactory.getBean(&apos;validatorFactory&apos;) /&gt;
		&lt;cfset local.validator.returns(&quot;This is the MOCKED ValidatorFactory method.&quot;) /&gt;
		&lt;cfset assertEqualsString(&quot;This is the MOCKED ValidatorFactory method.&quot;, getRegisteredUser().customDecoratorMethodUsingValidator(), &apos;Custom decorator using validator response does not match expected value.&apos;) /&gt;
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;getRegisteredUser&quot; access=&quot;private&quot; output=&quot;false&quot; hint=&quot;I return the RegisteredUser.&quot;&gt;
		&lt;cfreturn variables.instance.RegisteredUser /&gt;
	&lt;/cffunction&gt;
		
	&lt;cffunction name=&quot;setRegisteredUser&quot; access=&quot;private&quot; output=&quot;false&quot; hint=&quot;I set the RegisteredUser.&quot;&gt;
		&lt;cfargument name=&quot;RegisteredUser&quot; required=&quot;true&quot; hint=&quot;RegisteredUser&quot; /&gt;
		&lt;cfset variables.instance.RegisteredUser = arguments.RegisteredUser /&gt;
	&lt;/cffunction&gt;
	
&lt;/cfcomponent&gt;
&lt;/code&gt;

Just for reference, the Decorator I&apos;m using in these test examples looks like this:

&lt;code&gt;
&lt;cfcomponent hint=&quot;Registered User&quot; extends=&quot;transfer.com.TransferDecorator&quot; output=&quot;false&quot;&gt;
	
	&lt;cffunction name=&quot;customDecoratorMethod&quot; access=&quot;public&quot; returntype=&quot;string&quot; output=&quot;false&quot; hint=&quot;&quot;&gt;
		&lt;cfreturn &quot;This is a custom method in the Decorator.&quot; /&gt;		
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;customDecoratorMethodUsingValidator&quot; access=&quot;public&quot; returntype=&quot;string&quot; output=&quot;false&quot; hint=&quot;&quot;&gt;
		&lt;cfreturn getValidatorFactory().validatorFactoryMethod() /&gt;		
	&lt;/cffunction&gt;
	
	&lt;cffunction name=&quot;getValidatorFactory&quot; access=&quot;public&quot; returntype=&quot;any&quot; output=&quot;false&quot; hint=&quot;I return the ValidatorFactory.&quot;&gt;
		&lt;cfreturn variables.instance.validatorFactory /&gt;
	&lt;/cffunction&gt;
		
	&lt;cffunction name=&quot;setValidatorFactory&quot; access=&quot;public&quot; returntype=&quot;void&quot; output=&quot;false&quot; hint=&quot;I set the ValidatorFactory.&quot;&gt;
		&lt;cfargument name=&quot;validatorFactory&quot; type=&quot;any&quot; required=&quot;true&quot; hint=&quot;ValidatorFactory&quot; /&gt;
		&lt;cfset variables.instance.validatorFactory = arguments.validatorFactory /&gt;
	&lt;/cffunction&gt;
	
&lt;/cfcomponent&gt;
&lt;/code&gt;

Hopefully that helps clear up how one might go about testing a Transfer Decorator. It also shows how you can use unit testing, ColdMock, and the Transfer Bean Injector together. Please let me know what you think or if you have any questions or comments about how I&apos;m doing this.
				
				</description>
				
				
				<category>Transfer</category>
				
				<category>ColdFusion</category>
				
				<category>Unit Testing</category>
				
				<category>ColdSpring</category>
				
				<category>ColdMock</category>
				
				<pubDate>Mon, 28 Jan 2008 12:18:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2008/1/28/Unit-Testing-Transfer-Decorators-with-CFCUnit-BeanInjector-and-ColdMock</guid>
				
				
			</item>
			
		 	
			</channel></rss>