<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cranky Bit &#187; General Web Dev.</title>
	<atom:link href="http://blog.crankybit.com/tags/webdev/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.crankybit.com</link>
	<description>Take a byte out of tech!</description>
	<lastBuildDate>Wed, 09 Mar 2011 17:23:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Importance of Understanding Factories, Part 2: Transient Factories</title>
		<link>http://blog.crankybit.com/factories-2/</link>
		<comments>http://blog.crankybit.com/factories-2/#comments</comments>
		<pubDate>Tue, 05 May 2009 06:01:04 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[factories]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=327</guid>
		<description><![CDATA[In my last post, I discussed some of the mistakes that can be made when using ColdSpring as our factory. It became evident that using ColdSpring to inject transient objects&#8212;that is, objects that have a state for a momentary use and then are discarded&#8212;into our service objects or other related singletons is problematic. This is [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I discussed some of the <em>mistakes</em> that can be made when using ColdSpring as our factory. It became evident that using ColdSpring to inject transient objects&mdash;that is, objects that have a state for a momentary use and then are discarded&mdash;into our service objects or other related singletons is problematic. This is largely due to the concurrency issue with reusing that injected bean in the service object's methods, and mistakes that can be made if we forget about objects being <em>passed by reference</em>. Ray Camden also discussed this recently in <a href="http://www.coldfusionjedi.com/index.cfm/2009/5/1/ColdFusion-and-Pass-by-Reference-versus-Value" target="_blank">ColdFusion and Pass by Reference versus Value</a>.</p>
<p><strong>The answer is to build a transient factory for those beans.</strong> We can do it without losing the benefits of ColdSpring's dependency and configuration management. <em>And</em> it doesn't take much to make a factory. Take a look at this sample that works with my previous post's code.</p>
<div class="igBar"><span id="lcfm-5"><a href="#" onclick="javascript:showCodeTxt('cfm-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-5">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;">&lt;cfcomponent&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!----------------- Constructor ----------------------&gt;</span></span>&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"init"</span> returntype=<span style="color: #009900;">"BeanFactory"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.config=<span style="color: #0000FF;">StructNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> this /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!------------------ Config --------------------------&gt;</span></span>&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"setConfig"</span> returntype=<span style="color: #009900;">"void"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"Settings"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"struct"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.config=arguments.settings /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"getConfig"</span> returntype=<span style="color: #009900;">"struct"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> variables.config /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!--------------- Create Methods ---------------------&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"createBean"</span> returntype=<span style="color: #009900;">"any"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> <span style="color: #000000; font-weight: bold;">var</span> com=<span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"component"</span>,<span style="color: #009900;">"Bean"</span><span style="color: #0000FF;">&#41;</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> com.setConfig<span style="color: #0000FF;">&#40;</span>getConfig<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> com.init<span style="color: #0000FF;">&#40;</span>argumentCollection=arguments<span style="color: #0000FF;">&#41;</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;/cfcomponent&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The factory has a <code>setConfig()</code> method, just like the Bean does, and can be used to conveniently inject all configuration information with ColdSpring. Now, let's look at the <code>createBean()</code> method where the action is. It performs 3 key actions: <strong>(a)</strong> Create a fresh object. <strong>(b)</strong> Pass in configuration. <strong>(c)</strong> Call the <code>init()</code> method and return the object.</p>
<p>Our ColdSpring file can now be rewritten like this:</p>
<div class="igBar"><span id="lxml-6"><a href="#" onclick="javascript:showCodeTxt('xml-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-6">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"BeanService"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.BeanService"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constructor</span>-arg <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"BeanFactory"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">"BeanFactory"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/constructor</span>-arg<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"BeanFactory"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.BeanFactory"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Config"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;map<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">"dsn"</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>MyDSN<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/entry<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/map<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>See, we use the same XML for injecting configuration, it's just injected it into <code>BeanFactory</code>. We then inject <em>BeanFactory</em> into <code>BeanService</code>, instead of the Bean itself. It can use the factory to get a fresh bean whenever it needs one&mdash;properly instantiated and configured.</p>
<p>An example of <code>BeanService</code> tweaked to accept and use the factory:</p>
<div class="igBar"><span id="lcfm-7"><a href="#" onclick="javascript:showCodeTxt('cfm-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-7">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cfcomponent</span> <span style="color: #0000FF">hint</span>=<span style="color: #009900;">"Handles beans."</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"init"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"BeanFactory"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"BeanFactory"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.BeanFactory=Arguments.BeanFactory /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> this /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"workWithBean"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myBean=variables.BeanFactory.createBean<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; myBean.setX<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"I changed X on the bean!"</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; myBean.setY<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"I changed Y on the bean!"</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; return myBean;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #990000;">&lt;/cffunction&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cfcomponent&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Let's make the factory better.</strong> First, your app probably has more than one type of transient object. You don't need a separate transient factory for each type of object. Just have a different <code>create<em>BeanName</em>()</code> method for each object type, with creation code specific for each object. And if your objects are all essentially created with the same conventions, you can handle create methods for all of them with a single onMissingMethod handler. Something like this:</p>
<div class="igBar"><span id="lcfm-8"><a href="#" onclick="javascript:showCodeTxt('cfm-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-8">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!--- Create Methods ---&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"onMissingMethod"</span> returntype=<span style="color: #009900;">"any"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"MissingMethodName"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"MissingMethodArguments"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000FF;">method</span>=Arguments.MissingMethodName ;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> args=Arguments.MissingMethodArguments ;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> classList=<span style="color: #009900;">"MyBean,DiffBean,AnotherBean"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> className=<span style="color: #0000FF;">RemoveChars</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">1</span>,<span style="color: #FF0000;color:#800000;">6</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> com=<span style="color: #009900;">""</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">Left</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">6</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF">=</span>=<span style="color: #009900;">"create"</span> &amp;&amp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ListFindNoCase</span><span style="color: #0000FF;">&#40;</span>classList,className<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">&#41;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000FF;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; com=<span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"component"</span>,className<span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; com.setConfig<span style="color: #0000FF;">&#40;</span>getConfig<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">StructKeyExists</span><span style="color: #0000FF;">&#40;</span>com,<span style="color: #009900;">"setFactory"</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; com.setFactory<span style="color: #0000FF;">&#40;</span>this<span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; return com.init<span style="color: #0000FF;">&#40;</span>argumentCollection=args<span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000FF;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cffunction&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>See how the first <code>if</code> statement checks to make sure the method is a valid method name: One that starts with "create" and ends with an acceptable class name as we define in our <code>classList</code> variable. So this onMissingMethod handler will work with <code>createMyBean()</code>, <code>createDiffBean()</code>, and <code>createAnotherBean()</code>. Note how it also checks for the existence of a <code>setFactory()</code> method in the object it creates. If it is there, it will use the method to inject itself into the new object! This is a simple example of how autowiring is accomplished.</p>
<p><strong>Take it even <em>further!</em></strong> Head over to Paul Marcotte's blog post, <a href="http://www.fancybread.com/blog/post.cfm/A-Coldfusion-Transient-Factory-Example" target="_blank">A Coldfusion Transient Factory Example</a>, which shows how to make a very generic transient factory that receives configuration on which classes it should create through ColdSpring. Very cool stuff.</p>
<p><strong>Review.</strong> Transient factories don't require a lot of code, and are a vital step to simplifying and centralizing our instantiation and configuration of transient objects, or objects that have a state. Doing so doesn't negate the need for ColdSpring, in fact it complements it as it was intended, since ColdSpring works well with instantiation of singletons, and transient factories as described here are used as singletons. By utilizing ColdSpring and a transient factory, we can be well on our way to cleaner and more organized development.</p>
<p><strong>Get the files.</strong> Download sample code to play with: <a href='/wp-content/uploads/2009/05/coldspringbeantest.zip'>ColdSpring Bean Test</a>. It walks us through the issues discussed in the previous post as well as using transient factories like we just discussed.</p>
<p>This post has gotten pretty long, so I'll save the race condition demonstration for "Part 3". <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/factories-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importance of Understanding Factories, Part 1: ColdSpring Misunderstandings</title>
		<link>http://blog.crankybit.com/factories-1/</link>
		<comments>http://blog.crankybit.com/factories-1/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 13:33:26 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[ColdSpring]]></category>
		<category><![CDATA[factories]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=326</guid>
		<description><![CDATA[As ColdFusion developers progress in the use of object oriented programming concepts with CFCs, our applications become more flexible and able to support additional interfaces such as Ajax or Flex through web services. We also potentially benefit just from overall code maintainability, extensibility, and reusability by using best practices and design patterns common in OOP. [...]]]></description>
			<content:encoded><![CDATA[<p>As ColdFusion developers progress in the use of object oriented programming concepts with CFCs, our applications become more flexible and able to support additional interfaces such as Ajax or Flex through web services. We also potentially benefit just from overall code maintainability, extensibility, and reusability by using best practices and design patterns common in <abbr title="object-oriented programming">OOP</abbr>. </p>
<p>The benefits are many, but there are certainly pitfalls along the way. Perhaps we're ready to begin using service objects. And we'd like to create and pass in our transient objects with ColdSpring as a factory for all objects.</p>
<p>Let's cover the groundwork of our example, and then consider a pitfall. Here's our transient object:</p>
<p><strong>Bean.cfc</strong></p>
<div class="igBar"><span id="lcfm-13"><a href="#" onclick="javascript:showCodeTxt('cfm-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-13">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cfcomponent</span> <span style="color: #0000FF">hint</span>=<span style="color: #009900;">"Represents a bean."</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"init"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"public"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returntype=<span style="color: #009900;">"Bean"</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"x"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"any"</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">"true"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"y"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"any"</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">"true"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"z"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"any"</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">"true"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> setX<span style="color: #0000FF;">&#40;</span>arguments.x<span style="color: #0000FF;">&#41;</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> setY<span style="color: #0000FF;">&#40;</span>arguments.y<span style="color: #0000FF;">&#41;</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> setZ<span style="color: #0000FF;">&#40;</span>arguments.z<span style="color: #0000FF;">&#41;</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> this /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!------------------- Config -------------------------&gt;</span></span>&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"setConfig"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"public"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output=<span style="color: #009900;">"false"</span> returntype=<span style="color: #009900;">"void"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF">hint</span>=<span style="color: #009900;">"Method to pass in configs."</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"Settings"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"struct"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.instance.config=arguments.settings/<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!------------------ Setters -----------------------&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"setX"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"newval"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.instance.<span style="color: #0000FF;">data</span>.x=arguments.newval /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"setY"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"newval"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.instance.<span style="color: #0000FF;">data</span>.y=arguments.newval /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"setZ"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"newval"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.instance.<span style="color: #0000FF;">data</span>.z=arguments.newval /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!------------------ Getters -----------------------&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"getMemento"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"public"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returntype=<span style="color: #009900;">"struct"</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> variables.instance /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;/cfcomponent&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This is an overly-simplified example of a bean. It just has 3 properties (X, Y, Z) and corresponding setter methods. It also has a typical <code>init()</code> method, a <code>setConfig()</code> method to pass in configuration, and a getter method so we can quickly dump the state of the object. It'll be enough for our samples.</p>
<p>Perhaps we might write a ColdSpring configuration like this:</p>
<div class="igBar"><span id="lxml-14"><a href="#" onclick="javascript:showCodeTxt('xml-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-14">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"BeanService"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.BeanService"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constructor</span>-arg <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Bean"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">"Bean"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/constructor</span>-arg<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"Bean"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.Bean"</span> <span style="color: #000066;">singleton</span>=<span style="color: #ff0000;">"false"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Config"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;map<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">"dsn"</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>MyDSN<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/entry<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/map<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constructor</span>-arg <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"x"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>One<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/constructor</span>-arg<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constructor</span>-arg <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"y"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>Two<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/constructor</span>-arg<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constructor</span>-arg <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"z"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>Three<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/constructor</span>-arg<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This seems like it should work, eh? We're instantiating a service object, instantiating and configuring a bean, and passing the bean into the service object. Here's a really simple example of the bean service object:</p>
<p><strong>BeanService.cfc</strong></p>
<div class="igBar"><span id="lcfm-15"><a href="#" onclick="javascript:showCodeTxt('cfm-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-15">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cfcomponent</span> <span style="color: #0000FF">hint</span>=<span style="color: #009900;">"Handles beans."</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"init"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"Bean"</span> /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> variables.Bean=Arguments.Bean /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> this /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"getBean"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> variables.Bean /<span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"workWithBean"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myBean=variables.Bean;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; myBean.setX<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"I changed X on the bean!"</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; myBean.setY<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"I changed Y on the bean!"</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; return myBean;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #990000;">&lt;/cffunction&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cfcomponent&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This BeanService object has a constructor that receives the bean and stores it in its variables scope. It then has a the <code>getBean()</code> method so we can see the bean, and a <code>workWithBean()</code> method that simulates doing some work with the bean.</p>
<p><strong><em>And now, the pitfall: ColdSpring singletons and objects passed by reference.</em></strong></p>
<p>This code technically runs, and appears fine: The Bean instance that we pass into the service is <em>not</em> a singleton, so each BeanService we instantiate (<em>if</em> we were to instantiate multiple) would have a separate Bean instance. And <code>workWithBean()</code> appears to use a local var copy of Bean.</p>
<p>Wrong. </p>
<p>First, the <a target="_blank" href="http://www.coldspringframework.org/coldspring/examples/quickstart/index.cfm?page=singletons">Singleton vs. Transient Objects With ColdSpring</a> page explains that ColdSpring isn't ideal for generating transient components. Its overhead is more appropriate for less frequent creation of components that typically go in a shared scope, such as in the Application scope. Performance aside, though, the approach of injecting a transient bean into a singleton like BeanService does technically work.</p>
<p>So now the second point, how BeanService is working with Bean in our example <code>workWithBean()</code> method. The key misunderstanding is that CFCs like the Bean object are <em>passed by reference</em> when being assigned to variables. So when we do <code>var myBean=variables.Bean</code>, the local myBean variable is pointing to the same copy of Bean that <code>variables.Bean</code> points to. When it executes methods that change the bean's state, the one copy of Bean is being altered. Whoah, that wasn't an intended behavior. This could have very negative consequences, with Bean not being in the state you might expect it to be in.</p>
<p>So, how to fix it? Hmm. I don't want to use <code>CreateObject()</code> because that would become a dependency we'd have to manage, and we'd have to handle properly configuring the bean. This was the whole point of injecting the bean with ColdSpring in the first place.</p>
<p>Well, a quick solution could be to just use <code>Duplicate()</code> to make a copy of the injected bean before working on it! So, we could replace our <code>workWithBean()</code> method with this:</p>
<div class="igBar"><span id="lcfm-16"><a href="#" onclick="javascript:showCodeTxt('cfm-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-16">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"workWithBean"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myBean=<span style="color: #0000FF;">Duplicate</span><span style="color: #0000FF;">&#40;</span>variables.Bean<span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; myBean.setX<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"I changed X on the bean!"</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; myBean.setY<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"I changed Y on the bean!"</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; return myBean;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cffunction&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now, <code>variables.Bean</code> will always be the pristine, original bean injected by ColdSpring, and the local myBean variable will perform its work with a duplicate of that bean. Our code will now be working the way we intended; disaster has been averted.</p>
<p>Well, this <em>does</em> work. But it is neither graceful nor efficient, and it is <em>not</em> recommended. Consider Sean Corfield's blog post, <a href="http://corfield.org/blog/index.cfm/do/blog.entry/entry/duplicate_is_bad_for_your_objects_health" target="_blank">Duplicate() is Bad For Your (Object's) Health</a>. In an informal test, he clocked Duplicate() as being drastically slower&mdash;we're talking 50 to 1&mdash;than using <code>CreateObject()</code>. </p>
<p>Ugh. If we're back to using <code>CreateObject()</code>, what good is using ColdSpring for managing these component relationships, and what about dealing with configuration? <strong><em>Enter the world of factories.</em></strong> Yes, ColdSpring itself is a factory, but <em>it is a factory oriented around creating and configuring our singletons,</em> which can <em>include other factories</em> whose purpose is to properly create transient objects like Bean. </p>
<p>So instead of having ColdSpring inject Bean into BeanService, we can make a BeanFactory and inject <em>that</em> into BeanService, giving BeanService the ability to create Beans to work with any time it needs to. This may seem like a lot of effort, but we'll come to see that creating transient factories is easy and will clean up the mess of an architecture in this sample to something graceful and maintainable.</p>
<p>In this post, I described a few of the <em>mistakes</em> that can be made as we start to utilize ColdSpring. Hopefully these mistakes point to the importance of factories&mdash;not just ColdSpring, but our own transient factories as well. In the next blog post, we'll rework the sample to use a factory and review the benefits the factory provides and how it doesn't duplicate the purpose of ColdSpring. We'll review one more scenario that underscores the importance of factories: the dreaded race condition. And I'll provide source code that has executable demonstrations of these undesirable mistakes in action. <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/factories-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Generating a Decrypted Memento for a Transfer Decorator</title>
		<link>http://blog.crankybit.com/generating-a-decrypted-memento-for-a-transfer-decorator/</link>
		<comments>http://blog.crankybit.com/generating-a-decrypted-memento-for-a-transfer-decorator/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 12:57:27 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=319</guid>
		<description><![CDATA[In my last blog post, I discussed how to efficiently handle multiple encrypted fields while using Transfer. The key was using onMissingMethod in the Transfer decorator. However, what about when we use the memento with Transfer's getMemento() method? This approach can be especially handy to quickly transfer an object's properties when using web services to [...]]]></description>
			<content:encoded><![CDATA[<p>In my last blog post, I discussed how to efficiently handle multiple encrypted fields while using Transfer. The key was using onMissingMethod in the Transfer decorator. However, what about when we use the memento with Transfer's getMemento() method? This approach can be especially handy to quickly transfer an object's properties when using web services to Flex or AJAX front ends.</p>
<p>For reference, here was the object definition we were using in our sample Transfer configuration.</p>
<div class="igBar"><span id="lxml-19"><a href="#" onclick="javascript:showCodeTxt('xml-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-19">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;object</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Reg"</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"Regs"</span> <span style="color: #000066;">decorator</span>=<span style="color: #ff0000;">"MyProj.com.Reg"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"ID"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegID"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"numeric"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"FName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegFName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LastMod"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLastMod"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Expires"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegExpires"</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">"true"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncHome"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regHome"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncWork"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regWork"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncMobile"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regMobile"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncSMS"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regSMS"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/object<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The process is very simple. Recall that we prefixed our Transfer properties with "Enc" to know which fields are encrypted. Let's create a getDecryptedMemento() method. It will loop through all of the keys in the memento, which is just a struct, and decrypt any of the encrypted fields, saving them as new keys in the struct (i.e. "EncHome" is decrypted as "Home" in the struct). </p>
<p>Something like this will do the trick:</p>
<div class="igBar"><span id="lcfm-20"><a href="#" onclick="javascript:showCodeTxt('cfm-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-20">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"getDecryptedMemento"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"public"</span> returntype=<span style="color: #009900;">"struct"</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> <span style="color: #000000; font-weight: bold;">var</span> memento=getMemento<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> <span style="color: #000000; font-weight: bold;">var</span> key=<span style="color: #009900;">""</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> <span style="color: #000000; font-weight: bold;">var</span> newkey=<span style="color: #009900;">""</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfloop</span> <span style="color: #0000FF">index</span>=<span style="color: #009900;">"key"</span> <span style="color: #0000FF">list</span>=<span style="color: #009900;">"#StructKeyList(memento)#"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfif</span> <span style="color: #0000FF;">Left</span><span style="color: #0000FF;">&#40;</span>key,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span> is <span style="color: #009900;">"Enc"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> newkey=<span style="color: #0000FF;">RemoveChars</span><span style="color: #0000FF;">&#40;</span>key,<span style="color: #FF0000;color:#800000;">1</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> memento<span style="color: #0000FF;">&#91;</span>newkey<span style="color: #0000FF;">&#93;</span>=decryptValue<span style="color: #0000FF;">&#40;</span>memento<span style="color: #0000FF;">&#91;</span>key<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cfif&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;/cfloop&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> memento&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Not much to it. Note that we would use the same decryption function as we are using in onMissingMethod for the dynamic accessors. I'm calling it decryptValue() for this sample.</p>
<p>In the end, our getDecryptedMemento() method returns a memento that looks just like the Transfer-generated getMemento() output, with decrypted versions of the encrypted fields!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/generating-a-decrypted-memento-for-a-transfer-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling Multiple Encrypted Fields in a Transfer Decorator</title>
		<link>http://blog.crankybit.com/multiple-encrypted-fields-in-a-transfer-decorator/</link>
		<comments>http://blog.crankybit.com/multiple-encrypted-fields-in-a-transfer-decorator/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 12:55:55 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=318</guid>
		<description><![CDATA[I had a recent project that had multiple fields in a particular table that needed to be encrypted for privacy and security considerations. I was using Transfer for the project. The typical way to handle the encryption is to create custom accessor methods in a decorator component. The Transfer wiki has a decent explanation of [...]]]></description>
			<content:encoded><![CDATA[<p>I had a recent project that had multiple fields in a particular table that needed to be encrypted for privacy and security considerations. I was using <a href="http://docs.transfer-orm.com/" target="_blank">Transfer</a> for the project. The typical way to handle the encryption is to create custom accessor methods in a <a href="http://en.wikipedia.org/wiki/Decorator_pattern" target="_blank">decorator</a> component. The Transfer wiki has a decent explanation of this concept on a page entitled <a href="http://docs.transfer-orm.com/wiki/How_to_Encrypt_User_Passwords_Using_a_Decorator.cfm" target="_blank">How to Encrypt User Passwords Using a Decorator</a>. However, it is intentionally simple, demonstrating a single property. Multiply your getter/setter methods by how many properties you will be working with, and the lines of code can add up. This framework stuff is supposed to prevent that kind of repetition! Well, utilizing onMissingMethod() and the core concept on the Transfer decorator example, we can handle this scenario efficiently.</p>
<p>First, let's consider the object definition in our sample Transfer configuration file.</p>
<div class="igBar"><span id="lxml-23"><a href="#" onclick="javascript:showCodeTxt('xml-23'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-23">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;object</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Reg"</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"Regs"</span> <span style="color: #000066;">decorator</span>=<span style="color: #ff0000;">"MyProj.com.Reg"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"ID"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegID"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"numeric"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"FName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegFName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLName"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"LastMod"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegLastMod"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Expires"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"date"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"RegExpires"</span> <span style="color: #000066;">nullable</span>=<span style="color: #ff0000;">"true"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncHome"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regHome"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncWork"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regWork"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncMobile"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regMobile"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"EncSMS"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"string"</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"regSMS"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/object<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Note that I have prefixed the Transfer properties with "Enc". This isn't required, but will simplify our processing later on. So in this sample, we have 4 properties: Home, Work, Mobile, and SMS. The concept is that these are client phone numbers that we want to protect with encryption. So, Transfer will generate getEncHome(), getEncWork(), getEncMobile(), getEncSMS(), and corresponding setters. However, we want to provide getHome(), getWork(), getMobile(), getSMS(), and corresponding setters, that get and set the properties <em>after</em> encryption/decryption.</p>
<p><strong>Use onMissingMethod()</strong></p>
<p>To accomplish this, we might have an onMissingMethod() function in the decorator like this:</p>
<div class="igBar"><span id="lcfm-24"><a href="#" onclick="javascript:showCodeTxt('cfm-24'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-24">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"onMissingMethod"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"public"</span> returntype=<span style="color: #009900;">"any"</span> output=<span style="color: #009900;">"false"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"missingMethodName"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"string"</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">"true"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"missingMethodArguments"</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">"struct"</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">"true"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> func=<span style="color: #009900;">""</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> encList=<span style="color: #009900;">"Home,Mobile,SMS,Work"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000FF;">method</span>=Arguments.missingMethodName;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> args=Arguments.missingMethodArguments;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> firstArg=args<span style="color: #0000FF;">&#91;</span><span style="color: #0000FF;">ListFirst</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">StructKeyList</span><span style="color: #0000FF;">&#40;</span>args<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> prop=<span style="color: #0000FF;">RemoveChars</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">1</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Handle encryption/decryption of encrypted values:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">ListFindNoCase</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"get,set"</span>,<span style="color: #0000FF;">Left</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> and </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ListFindNoCase</span><span style="color: #0000FF;">&#40;</span>encList,prop<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000FF;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; func=variables<span style="color: #0000FF;">&#91;</span><span style="color: #0000FF;">Insert</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">"Enc"</span>,<span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">Left</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">method</span>,<span style="color: #FF0000;color:#800000;">3</span><span style="color: #0000FF;">&#41;</span> is <span style="color: #009900;">"get"</span><span style="color: #0000FF;">&#41;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; return decryptValue<span style="color: #0000FF;">&#40;</span>func<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; func<span style="color: #0000FF;">&#40;</span>encryptValue<span style="color: #0000FF;">&#40;</span>firstArg<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000FF;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cffunction&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As a good security measure, we use an "encList" string to check that only proper methods can be called. Then we examine the method name. If it starts with "get" or "set" and ends with one of the list items, we proceed. Thus, we'll process a method like getHome(), but not a method like getFoo(). We then call getEncHome() and decrypt it for getters, encrypt and call setEncHome() for setters. </p>
<p><strong>Dynamic Method Calling</strong></p>
<p>But alas, how do we do this dynamically without a long if-then-else chain? We call the proper method by referencing it from the component's variables scope. Terrence Ryan describes this in his blog post <a href="http://www.terrenceryan.com/blog/post.cfm/cheap-and-easy-dynamic-method-calling-in-cfscript" target="_blank">Cheap and Easy Dynamic Method Calling in CFScript</a>. We construct the method name, in our case, by inserting "Enc" after the "get" or "set" prefix of the method name passed into onMissingMethod (thus "getHome" becomes the Transfer method "getEncHome"). Assign the function to the local "func" variable, then call it as if "func" was the function. Finally, handle any encryption or decryption that you will be doing. For this sample, I have encryptValue() and decryptValue() methods handling the details of that work.</p>
<p><strong>Summary</strong></p>
<p>We've used two solutions to handle multiple encrypted fields in the decorator. First, we used onMissingMethod() to handle processing of all of the properties in a single method. Then, we used dynamic method calling to call the Transfer-generated accessors within onMissingMethod().</p>
<p>The end result is being able to use setHome(), getHome(), etc. with the encryption and decryption being handled automatically. Great!</p>
<p>In addition to accessors, we may sometimes want to use the object's memento with the Transfer method getMemento(). In my next blog post, I'll demonstrate how that process can also be done very efficiently.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/multiple-encrypted-fields-in-a-transfer-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Reason to Use CFQueryParam: Avoid Odd SQL Parsing by ColdFusion</title>
		<link>http://blog.crankybit.com/best-reason-to-use-cfqueryparam/</link>
		<comments>http://blog.crankybit.com/best-reason-to-use-cfqueryparam/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 19:02:29 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=314</guid>
		<description><![CDATA[After banging my head against the wall for a couple hours over an odd application error, I've finally come up with the best, most definitive reason to use &#60;cfqueryparam&#62; absolutely 100% of the time: It helps you avoid odd--dare I say erroneous--SQL parsing performed by ColdFusion in the &#60;cfquery&#62; tag.  Huh? Say again? That's right. [...]]]></description>
			<content:encoded><![CDATA[<p>After banging my head against the wall for a couple hours over an odd application error, I've finally come up with the best, most definitive reason to use &lt;cfqueryparam&gt; absolutely 100% of the time: It helps you avoid odd--dare I say erroneous--SQL parsing performed by ColdFusion in the &lt;cfquery&gt; tag. </p>
<p>Huh? Say again?</p>
<p>That's right. In <em>my </em>experience, anyway, the &lt;cfquery&gt; tag will erroneously parse the SQL and tag legitimate content as disallowed SQL. Let's take a look at an example.</p>
<p>Here's a basic query that inserts some HTML content into a field:</p>
<div class="igBar"><span id="lcfm-27"><a href="#" onclick="javascript:showCodeTxt('cfm-27'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-27">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cfquery</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"insertStuff"</span> <span style="color: #0000FF">datasource</span>=<span style="color: #009900;">"myDS"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;INSERT INTO myTable (fldTitle,fldContent) </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;VALUES ('Title','&amp;middot; Grant Deadline Extended')</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;/cfquery&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Never mind <em>why</em> you might do this; the point is that it is allowable SQL. There's just an HTML special entity in the string. However, ColdFusion 8 sees the semicolon followed by the word "GRANT", and if the GRANT statement is disallowed for the ColdFusion data source, ColdFusion will throw an error similar to: "Error Executing Database Query. Executing the SQL statement is not allowed."</p>
<p>Of course, there is no error in the SQL, and the same statement executes just fine when you run it at the command line or SQL Query Analyzer. ColdFusion is doing a security check by parsing the SQL and attempting to verify that the SQL statement(s) only use allowed SQL as defined for the data source in ColdFusion Administrator. </p>
<p>If a SQL keyword is not immediately following the semicolon, ColdFusion won't make this mistake. And naturally, if your data source is configured to allow the offending keyword (in my example, "GRANT"), it will execute the SQL and it will execute properly, not actually executing the grant statement. </p>
<p>But if my code had used &lt;cfqueryparam&gt;, this wouldn't have been an issue:</p>
<div class="igBar"><span id="lcfm-28"><a href="#" onclick="javascript:showCodeTxt('cfm-28'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-28">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cfquery</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"insertStuff"</span> <span style="color: #0000FF">datasource</span>=<span style="color: #009900;">"myDS"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;INSERT INTO myTable (fldTitle,fldContent) </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;VALUES (</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #333333;"><span style="color: #990000;">&lt;cfqueryparam</span> <span style="color: #0000FF;">value</span>=<span style="color: #009900;">"Title"</span> cfsqltype=<span style="color: #009900;">"cf_sql_varchar"</span><span style="color: #990000;">&gt;</span></span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #333333;"><span style="color: #990000;">&lt;cfqueryparam</span> <span style="color: #0000FF;">value</span>=<span style="color: #009900;">"&amp;middot; Grant Deadline Extended"</span> cfsqltype=<span style="color: #009900;">"cf_sql_varchar"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;)</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;/cfquery&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This code will happily pass the SQL on to the database server. </p>
<p>This scenario may be a bit apparent when presented cleanly as I have here, but when the string being passed in is 3,000 characters or something similar, you're banging your head on the wall wondering what the heck is wrong with your query, especially when it has been working for years and now fails on just a single particular set of data. To my credit, the offending code is about 6 years old and all of my queries do indeed use &lt;cfqueryparam&gt; now. And more than ever, I'm now convinced to continue that habit. <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>This oddity probably comes up rarely, but I'm sure someone else has or will experience this. I hope this post will help you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/best-reason-to-use-cfqueryparam/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>DST in cfexchangecalendar</title>
		<link>http://blog.crankybit.com/dst-in-cfexchangecalendar/</link>
		<comments>http://blog.crankybit.com/dst-in-cfexchangecalendar/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 14:54:44 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=313</guid>
		<description><![CDATA[I have an app that uses &#60;cfexchangecalendar&#62; to look at appointments in an Exchange calendar and display them on a form on a web page. Everything was going smoothly until the department called and notified me that new appointments they were entering were an hour off on the web app. The calendar in Outlook would [...]]]></description>
			<content:encoded><![CDATA[<p>I have an app that uses &lt;cfexchangecalendar&gt; to look at appointments in an Exchange calendar and display them on a form on a web page. Everything was going smoothly until the department called and notified me that new appointments they were entering were an hour off on the web app. The calendar in Outlook would say 11am, for instance, but my app would say 12pm. </p>
<p>After a little investigation, I came to realize that only new appointments with a date <em>after </em>daylight savings time ends were an hour off. Okay, that makes sense, but the query results returned by &lt;cfexchangecalendar&gt; don't provide any time zone information for me to properly handle the hour difference caused by DST!</p>
<p>As it turns out, Adobe has tracked this as Issue #70474, and the hot fix can be downloaded in <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403070" target="_blank">ColdFusion 8 Cumulative Hot Fix 3</a>. After applying the cumulative hot fix, &lt;cfexchangecalendar&gt; now returns the appointments exactly as they appear in Outlook.</p>
<p>It seems to me that it would be nice if the query results returns the GMT offset. But at least Adobe has addressed the inconsistency between the data ColdFusion retrieves and what Outlook displays.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/dst-in-cfexchangecalendar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trimming a String in JavaScript</title>
		<link>http://blog.crankybit.com/trimming-a-string-in-javascript/</link>
		<comments>http://blog.crankybit.com/trimming-a-string-in-javascript/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 15:30:12 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=307</guid>
		<description><![CDATA[This is a nice clean way to implement string trimming for the String object in JavaScript: PLAIN TEXT JavaScript: String.prototype.trim = function&#40;&#41; &#123;    return this.replace&#40;/^\s+&#124;\s+$/g,""&#41;; &#125; With that implemented, you can then trim a string in the object-oriented way you would prefer and love: PLAIN TEXT JavaScript: var myStr="This is a test!   "; [...]]]></description>
			<content:encoded><![CDATA[<p>This is a nice clean way to implement string trimming for the String object in JavaScript:</p>
<div class="igBar"><span id="ljavascript-31"><a href="#" onclick="javascript:showCodeTxt('javascript-31'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-31">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">String.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">trim</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/^\s+|\s+$/g</span>,<span style="color: #3366CC;">""</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>With that implemented, you can then trim a string in the object-oriented way you would prefer and love:</p>
<div class="igBar"><span id="ljavascript-32"><a href="#" onclick="javascript:showCodeTxt('javascript-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-32">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> myStr=<span style="color: #3366CC;">"This is a test!   "</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>myStr.<span style="color: #006600;">trim</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This is handy for client-side clean-up of form information, although bear in mind that depending on client-side code for data entry clean-up isn't necessarily wise unless you have some server-side code also checking the data.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/trimming-a-string-in-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Favorite ColdFusion Weekly Episodes</title>
		<link>http://blog.crankybit.com/favorite-coldfusion-weekly-episodes/</link>
		<comments>http://blog.crankybit.com/favorite-coldfusion-weekly-episodes/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 21:18:55 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[History]]></category>
		<category><![CDATA[IDEs]]></category>
		<category><![CDATA[IT Industry]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=305</guid>
		<description><![CDATA[In light of the departure of the ColdFusion Weekly podcast (so long Matt and Peter, and thank you!), I have assembled a list of my favorite "shows" or "episodes". Really, all of the episodes were good and worth hearing. But these episodes were fantastic. Presented in chronological order: v1.5 - IDEs of...April: Came at a [...]]]></description>
			<content:encoded><![CDATA[<p>In light of the <a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2008#3-09" target="_blank">departure</a> of the <a href="http://www.coldfusionweekly.com" target="_blank">ColdFusion Weekly</a> podcast (so long Matt and Peter, and thank you!), I have assembled a list of my favorite "shows" or "episodes". Really, <em>all</em> of the episodes were good and worth hearing. But these episodes were <em>fantastic. </em></p>
<p>Presented in chronological order:</p>
<ul>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2006#1-5 Beta" target="_blank">v1.5 - IDEs of...April</a>: Came at a perfect time for me, because I had just switched to CFEclipse recently. So it was great confirmation for me and I enjoyed the Eclipse plugin recommendations. This episode is good for anyone still using Dreamweaver or HomeSite.</li>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2006#1-6 Beta" target="_blank">v1.6 - Version Control</a>: Also had great timing, because I had already committed myself to exclusively using Subversion but hadn't yet set up my Subversion server. While you're at it, check out the follow-up episode on <a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2006#1-29" target="_blank">v1.29 - Source Control Revisited</a>. These episodes are a nice way to be introduced to version control for web development.</li>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2006#1-10" target="_blank">v1.10 - Design Pattern Safari</a>: Probably one of the most classic episodes and a must-hear. All about design patterns like beans, DAOs, etc.</li>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2007#2-01" target="_blank">v2.01 - Rise of the Virtual Machines</a>: Discussion of virtualization technology on both Macs and Windows. Great discussion, because I think this is an important technology for web developers; I am a big proponent of virtualization.</li>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2007#2-02" target="_blank">v2.02 - Cryptology and Security</a>: This was very interesting because of the information that was discussed regarding encryption, hashing, and salt.</li>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2007#2-15" target="_blank">v2.15 - Mark Mandel on Transfer</a>: Very good consideration of the popular ORM, Transfer.</li>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2007#2-27" target="_blank">v2.27 - Selenium</a>: Discussion on testing your apps on the client side with Selenium.</li>
<li><a href="http://www.coldfusionweekly.com/index.cfm?event=showArchive&amp;year=2008#3-06" target="_blank">v3.06 - Open Source BlueDragon</a>: Discussion with Vince Bonfanti about BlueDragon going open source.</li>
</ul>
<p>I will miss Matt's Vista rants. <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Thanks to both of you for all of your hard work.</p>
<p>If you're hankering for a podcast to listen to, Brian Meloche is picking up where Matt and Peter left off with a new podcast called <a href="http://www.cfconversations.com/" target="_blank">CFConversations</a>. W00T!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/favorite-coldfusion-weekly-episodes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CFLDAP Dies With java.lang.OutOfMemoryError</title>
		<link>http://blog.crankybit.com/cfldap-dies/</link>
		<comments>http://blog.crankybit.com/cfldap-dies/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 17:10:15 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=304</guid>
		<description><![CDATA[I have a report that is generated by ColdFusion that assists our department with account maintenance on our AD network. It looks for a certain set of accounts, then looks up the account of the employee who "requested" or "authorized" the creation of each account to ultimately get verification from that employee that this network [...]]]></description>
			<content:encoded><![CDATA[<p>I have a report that is generated by ColdFusion that assists our department with account maintenance on our AD network. It looks for a certain set of accounts, then looks up the account of the employee who "requested" or "authorized" the creation of each account to ultimately get verification from that employee that this network account is still needed. If you don't respond and indicate you still need the support account, it is tagged for removal when we do our system account cleaning.</p>
<p>The system ran perfectly in the past several years, but yesterday it started dying on one of the LDAP calls with the error: "java.lang.OutOfMemoryError: unable to create new native thread".</p>
<p>The kicker is that the error only occurs on the production server, even though my development box is hitting the same server and running the exact same JVM and is on the same version of ColdFusion 8. And it isn't failing on the <em>first</em> LDAP call. </p>
<p>Running short on time, I finally discovered a clunky solution: I would call &lt;cfthread action="sleep" duration="750" /&gt; to give the system a "break" before it made the LDAP call that would always fail. Oddly, this worked. Setting it to 100ms still caused it to crash (although it took longer), so I just went long at 750ms.</p>
<p>My only explanation as to why this works is that Java and/or ColdFusion may not be disposing of the LDAP calls quickly enough to avoid having them pile up and eventually cause an overflow and run out of memory.</p>
<p>I am open to someone describing a more appropriate way to handle this. But in the meantime, this is just a scheduled task that can stand to run a little more slowly. I just hate solutions that feel clunky like this, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/cfldap-dies/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why Isn&#8217;t @import Working in my CSS?</title>
		<link>http://blog.crankybit.com/why-isnt-import-working-in-css/</link>
		<comments>http://blog.crankybit.com/why-isnt-import-working-in-css/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 18:17:28 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[General Web Dev.]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=303</guid>
		<description><![CDATA[I was improving the CSS of an old intranet web app (written in early 2001) to be closer to standards-compliance (getting it to just look good in Firefox and Safari would be good enough for me). While I was working on that, I noticed a whole bunch of my CSS that was being completely ignored. [...]]]></description>
			<content:encoded><![CDATA[<p>I was improving the CSS of an old intranet web app (written in early 2001) to be <em>closer</em> to standards-compliance (getting it to just look good in Firefox and Safari would be good enough for me). While I was working on that, I noticed a whole bunch of my CSS that was being completely ignored. As it turns out, all of the code in a separate CSS file that was being imported with @import was not being rendered.</p>
<p>FireBug showed me that the CSS wasn't being applied to the elements that it should have been applied to. Hmm. Then I used the "Net" tab of FireBug to see that Firefox wasn't even <em>attempting </em>to load the external CSS file.</p>
<p>The solution is simple. My @import directive was surrounded by other CSS instructions. Whereas IE tolerates this, the actual W3C spec declares that @import directives should appear before any other CSS instructions, and Firefox honors this restriction.</p>
<p>Thus, my @import directive was being ignored. I moved it to the top of the file and everything started working.</p>
<p>The lessons? Don't abuse @import directives. Ideally, they should be used only to have a single CSS file that imports several smaller functional CSS files as a means to provide some organization to the CSS. I was using @import mixed in with my other CSS instructions, which is not ideal.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/why-isnt-import-working-in-css/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Looping Through Datagrid Rows in Flex</title>
		<link>http://blog.crankybit.com/looping-through-datagrid-rows-in-flex/</link>
		<comments>http://blog.crankybit.com/looping-through-datagrid-rows-in-flex/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 18:22:54 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[General Web Dev.]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=301</guid>
		<description><![CDATA[It wasn't readilly apparent to me how to loop through some datagrid rows in Flex. Finally, I came across Abdul Qabiz's DataGridDataExporter class, which basically does just that. The key is to set up a cursor that will loop through the Data Provider for the datagrid. Something like this: PLAIN TEXT ACTIONSCRIPT: var dp:Object=MyDG.dataProvider; var [...]]]></description>
			<content:encoded><![CDATA[<p>It wasn't readilly apparent to me how to loop through some datagrid rows in Flex. Finally, I came across Abdul Qabiz's <a href="http://www.abdulqabiz.com/blog/archives/flash_and_actionscript/datagriddataexporter.php" target="_blank">DataGridDataExporter class,</a> which basically does just that.</p>
<p>The key is to set up a cursor that will loop through the Data Provider for the datagrid.</p>
<p>Something like this:</p>
<p><div class="igBar"><span id="lactionscript-34"><a href="#" onclick="javascript:showCodeTxt('actionscript-34'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ACTIONSCRIPT:</span>
<div id="actionscript-34">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> dp:<span style="color: #0066CC;">Object</span>=MyDG.<span style="color: #006600;">dataProvider</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> cursor:IViewCursor=dp.<span style="color: #006600;">createCursor</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span> !cursor.<span style="color: #006600;">afterLast</span> <span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic;">// Access each column field like: cursor.current.MyFieldName</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>cursor.<span style="color: #006600;">current</span>.<span style="color: #006600;">MyFieldName</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic;">// Obviously don't forget to move to next row:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; cursor.<span style="color: #006600;">moveNext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</p>
<p>That's all there is to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/looping-through-datagrid-rows-in-flex/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Biased Flash Series by AppleInsider</title>
		<link>http://blog.crankybit.com/biased-flash-series-by-appleinsider/</link>
		<comments>http://blog.crankybit.com/biased-flash-series-by-appleinsider/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 15:47:07 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[History]]></category>
		<category><![CDATA[IT Industry]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=300</guid>
		<description><![CDATA[This is old news now, but it's worth noting that AppleInsider released a 3-part series of articles about Flash. Check them out here: Part 1: Adobe in the History and Future of Flash Part 2: The Many Enemies and Obstacles of Flash Part 3: Adobe Fights for AIR with the Open Screen Project Whether you [...]]]></description>
			<content:encoded><![CDATA[<p>This is old news now, but it's worth noting that AppleInsider released a 3-part series of articles about Flash. Check them out here:</p>
<ul>
<li><a href="http://www.appleinsider.com/articles/08/05/05/flash_wars_adobe_in_the_history_and_future_of_flash_part_1_of_3.html">Part 1: Adobe in the History and Future of Flash</a></li>
<li><a href="http://www.appleinsider.com/articles/08/05/06/flash_wars_the_many_enemies_and_obstacles_of_flash_part_2_of_3.html">Part 2: The Many Enemies and Obstacles of Flash</a></li>
<li><a href="http://www.appleinsider.com/articles/08/05/07/flash_wars_adobe_fights_for_air_with_the_open_screen_project_part_3_of_3.html">Part 3: Adobe Fights for AIR with the Open Screen Project</a></li>
</ul>
<p>Whether you love Flash, hate Flash, love Adobe, hate Adobe, or are neutral with the whole thing, this series is disturbingly prejudicial and biased. Comments on the posts even say as much. This is certainly disappointing, because I like AppleInsider, Apple, Adobe, and Flash. But these articles have a predisposition that results in negative interjected commentary in what would otherwise have been an interesting consideration of the history of Flash.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/biased-flash-series-by-appleinsider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memento Pattern is Great for Web Services</title>
		<link>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/</link>
		<comments>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/#comments</comments>
		<pubDate>Fri, 02 May 2008 21:34:28 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=298</guid>
		<description><![CDATA[Nothing Earth-shattering here. I've just come to appreciate how useful the memento design pattern can be to do web services a bit more efficiently sometimes. My web service is a facade CFC powered by objects being generated by Transfer and ColdSpring. So I conveniently have access to the objects' getMemento() or getPropertyMemento() methods. I had [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing Earth-shattering here. I've just come to appreciate how useful the <a href="http://en.wikipedia.org/wiki/Memento_pattern" target="_blank">memento design pattern</a> can be to do web services a bit more efficiently sometimes.</p>
<p>My web service is a facade CFC powered by objects being generated by Transfer and ColdSpring. So I conveniently have access to the objects' <strong>getMemento()</strong> or <strong>getPropertyMemento()</strong> methods.</p>
<p>I had a method in the web service that would accept several arguments and perform the simple task of processing them and saving them to the database. It returned a single boolean indicating success or failure.</p>
<p>The web service is just used by another web server that doesn't have access to the database and can't run Transfer (because it is currently running CFMX 6). This web server hosts a page with a form; when the user submits the form, the action page invokes the web service to process and save the information.</p>
<p>I needed the action page to display some data that wasn't available in the form data that was transmitted. For instance, a pull-down menu allowed the user to select from a list of sessions, but all that is transmitted is the database ID of the session they chose. My action page can't display any details about that session unless it makes another web service call to retrieve the details of that session. <em>And </em>I have to write the code for that web service method, which up to this point was unnecessary.</p>
<p>Aha! I changed the web service to return a <strong>struct</strong> that still contained the success/failure boolean, but also contained mementos of the objects that were created or referenced when processing the request. Now my web server invoking the web service has all the details of the session at its disposal for display on the action page.</p>
<p>What's the big deal, right? Who cares about one more web service call? Well, I'd like to keep the chatter between the two machines down to a minimally required amount, and besides, thanks to <strong>getMemento()</strong>, adding all of that data to the web service's response took one line of code, and way less time than it would take to write that extra web service method to retrieve session data, and also way less time than it took to even write this blog post. <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Here's the general thought process of the code in the web service (abbreviated to just show the point of mementos):</p>
<p>
<div class="igBar"><span id="lcfm-36"><a href="#" onclick="javascript:showCodeTxt('cfm-36'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-36">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"add"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"remote"</span> returntype=<span style="color: #009900;">"struct"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">var</span> ret=<span style="color: #0000FF;">StructNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">var</span> mySession=SessionService.getSession<span style="color: #0000FF;">&#40;</span>Arguments.SID<span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic; background-color:#FFFF99;">/* Do Processing */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ret.Success=true;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ret.Session=mySession.getMemento<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;cfreturn</span> ret&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cffunction&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Note for Flex Newbie: Test Your HTML Wrapper</title>
		<link>http://blog.crankybit.com/flex-newbie-test-html-wrapper/</link>
		<comments>http://blog.crankybit.com/flex-newbie-test-html-wrapper/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 11:48:57 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[General Web Dev.]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/flex-newbie-test-html-wrapper/</guid>
		<description><![CDATA[Note to self (the Flex newbie): Test your HTML wrapper for your SWF files to make sure that the user experience is a good one when you're setting up your Flex apps on your site! I took the HTML wrapper generated by Flex Builder and modified it to fit into my page. While doing so, [...]]]></description>
			<content:encoded><![CDATA[<p>Note to self (the Flex newbie): Test your HTML wrapper for your SWF files to make sure that the user experience is a good one when you're setting up your Flex apps on your site! I took the HTML wrapper generated by Flex Builder and modified it to fit into my page. While doing so, I forgot to include the playerProductInstall.swf file with my app, so when a browser with an older Flash Player viewed the page, the JavaScript I had in place to call playerProductInstall.swf would hang since it couldn't find it. The detection for when no Flash Player is present at all (or only a <u>really</u> old version) was also a bit ungraceful.</p>
<p>But I was clueless to these poor experiences since I hadn't tested these scenarios. Fortunately, my app was <em>just</em> released, and only to a beta crowd.</p>
<p>To test the absence of Flash Player, you can download a <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14157" target="_blank">Flash Player Uninstaller</a> and uninstall Flash Player.  I'm not sure what the best way is to install and test an old version of the Flash Player; I just had a virtual machine that had an old version on it, so I used that because it was convenient. If you google for "<a href="http://www.google.com/search?q=download+flash+player+8" target="_blank">download flash player 8</a>", there are some non-Adobe links that appear to be valid links, but I did not try these.</p>
<p>Adobe has a <a href="http://www.adobe.com/devnet/flashplayer/detection_installation.html" target="_blank">Flash Player Detection and Installation</a> support page that is helpful as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/flex-newbie-test-html-wrapper/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tom Yager Praises AIR</title>
		<link>http://blog.crankybit.com/tom-yager-praises-air/</link>
		<comments>http://blog.crankybit.com/tom-yager-praises-air/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 18:44:17 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[IT Industry]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/tom-yager-praises-air/</guid>
		<description><![CDATA[Tom Yager, writer of the Ahead of the Curve column in InfoWorld, wrote up a nice article about AIR entitled AIR gets rich apps right. Touting Adobe's credentials through their past record, he indicated that Adobe is a great candidate for accomplishing what AIR is intended to do: Get that web technology to the desktop [...]]]></description>
			<content:encoded><![CDATA[<p>Tom Yager, writer of the <a href="http://weblog.infoworld.com/yager/" target="_blank">Ahead of the Curve</a> column in InfoWorld, wrote up a nice article about AIR entitled <a href="http://weblog.infoworld.com/yager/archives/2008/04/air_gets_rich_a.html" target="_blank">AIR gets rich apps right</a>. Touting Adobe's credentials through their past record, he indicated that Adobe is a great candidate for accomplishing what AIR is intended to do: Get that web technology to the desktop environment untethered from the web browser.</p>
<p>I've always loved Tom Yager and find his columns very interesting (although the Intel/AMD discussions lose my interest). It's great to see him praising AIR.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/tom-yager-praises-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notes: Adobe AIR Local Data Storage Options</title>
		<link>http://blog.crankybit.com/notes-adobe-air-local-data-storage-options/</link>
		<comments>http://blog.crankybit.com/notes-adobe-air-local-data-storage-options/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 17:13:10 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Webinars]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/notes-adobe-air-local-data-storage-options/</guid>
		<description><![CDATA[The following are my notes during the Adobe AIR Local Data Storage Options webinar that was presented during Adobe Developer Week. It was presented by Greg Hamer and the slides and demo code are already online. Before getting started, note how Microsoft and Adobe are taking two different approaches: Microsoft is trying to bring the [...]]]></description>
			<content:encoded><![CDATA[<p>The following are my notes during the Adobe AIR Local Data Storage Options webinar that was presented during <a href="http://adobe.com/go/2008_developer_week" target="_blank">Adobe Developer Week</a>. It was presented by Greg Hamer and the slides and demo code are already <a href="http://halcyonsolutions.net/presos/08/airsql/" target="_blank">online</a>.</p>
<p>Before getting started, note how Microsoft and Adobe are taking two different approaches: Microsoft is trying to bring the .Net desktop development community to the web. Adobe is conversely trying to bring web developers to the desktop! (<a href="http://www.news.com/8301-10784_3-9789007-7.html" target="_blank">Kevin Lynch</a>)</p>
<p>There are four main options for AIR local storage: Local Shared Objects, File System, Encrypted Local Store, and the embedded SQLite database. Shared Objects are available in the Flash Player as well; all of these options are obviously available in AIR. Note that the data size limitation for Shared Objects does not exist in the AIR runtime!</p>
<p><strong>Performance considerations.</strong> Shared Objects read and write very quickly. File system access and encrypted local stores are typically be slow in writing. Embedded SQLite databases are typically the best combination of speed and random access of items. Greg highlighted the AIR_LocalStorage_Demo app created by Jason Williams that demonstrates the speeds of the four storage methods.</p>
<p><strong>Local Shared Objects.</strong> You can serialize memory resident data structures. Great! However, it runs in <em>synchronous</em> mode.</p>
<p><strong>Encrypted Local Store.</strong> Used to store sensitive data. The price is the slow write speeds.  Also runs in synchronous mode. All data is serialized using ByteArray.</p>
<p><strong>File System. </strong>Obviously important for management of documents. Can run in sync and async mode. The File and FileStream objects work together to point to a file and read/write data. The File object helps remove you from the pain of dealing with Mac vs. Windows environments with properties like File.userDirectory, File.documents.Directory, File.desktopDirectory, etc. It also has methods for opening Open and Save dialog boxes native to the environment as well as copying/moving/deletion methods.</p>
<p><strong>Embedded SQLite Database.</strong>  Nice thing about them is that they are self-contained in a single file and require no external software installation to begin using them (support is built into the AIR runtime). Even supports transactions. And the database supports large amounts of data: SQLite has a theoretical limit of over 2TB. Supports ANSI-SQL 92.</p>
<p>However, it's not a full-blown enterprise database server, obviously. So you lose things like stored procedures, enforcing data type constraints, foreign key constraints, and primary keys must be integers. It also isn't a multiuser environment.</p>
<p><strong>Session evaluation. </strong>I am unhappy to say that I was disappointed with the session. It was high-level, the coverage of code samples (when they weren't passed over completely) consisted of merely reading the code back to us. I recommend viewing the recording if you have zero knowledge of data storage in Flex and AIR, as it would serve as a decent first-baby-step introduction for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/notes-adobe-air-local-data-storage-options/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The Solution to Flex Remoting Over SSL</title>
		<link>http://blog.crankybit.com/flex-remoting-over-ssl/</link>
		<comments>http://blog.crankybit.com/flex-remoting-over-ssl/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 12:21:52 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/flex-remoting-over-ssl/</guid>
		<description><![CDATA[If you've tried calling ColdFusion CFCs with RemoteObject over SSL in your Flex apps, you probably feel my pain already, because you have either tried to get it working and gave up, or had a heck of a time getting it working. Adobe's documentation for this specific need wasn't helpful to me, and discussion about [...]]]></description>
			<content:encoded><![CDATA[<p>If you've tried calling ColdFusion CFCs with RemoteObject over SSL in your Flex apps, you probably feel my pain already, because you have either tried to get it working and gave up, or had a heck of a time getting it working. Adobe's documentation for this specific need wasn't helpful to me, and discussion about it online is relatively sparse and unsure as well, from what I've seen. My intranet environment at work demanded that I get remote communication with CFCs working over SSL, so as I neared completion of my first couple Flex apps, I needed to get an understanding of this issue. Hopefully it will be useful to others.</p>
<p><strong>So, what's the problem? </strong>In a nutshell, when you try to use the RemoteObject component in a Flex app to communicate with CFCs, the default installation of ColdFusion 8 and Flex Builder 3 will compile your app to communicate with the ColdFusion server over HTTP (http://yourserver.com/flex2gateway/), <em>not</em> over HTTPS (https://yourserver.com/flex2gateway/cfamfsecure), regardless of whether the SWF was loaded over HTTPS or not.</p>
<p>If your site exists in both HTTP and HTTPS, you may not even be aware this is happening. I wasn't aware of it while I was developing on my local machine. But our production server hosts its site <em>only </em>in HTTPS and the site on port 80 is a nearly empty site that redirects all requests to the SSL-protected version of the site. So this behavior broke my Flex app.</p>
<p>If your site exists only in SSL or sensitive data is being transmitted to and from the Flex app and the CFCs, you probably are trying to get RemoteObject to communicate over SSL.</p>
<p><strong>Quick workarounds.</strong> If you have time and leniency to skirt the issue, you can avoid the RemoteObject/SSL issue. You can always use the HTTPService and WebService components instead of RemoteObject. But like most workarounds, this has its disadvantages and limits you from the benefit of using RemoteObject.</p>
<p>I imagine you also could set up a ColdFusion mapping to make the CFCs available on the HTTP site, but this solution is viable only if you really don't care about security, in which case you probably wouldn't have your site wrapped in SSL anyway.</p>
<p><strong>The solution.</strong> What makes the solution tricky is that there are a few things that have to be configured properly, and there are some pitfalls along the way that can be misleading.  The primary solution lies in some changes to the ColdFusion server's config files <em>services-config.xml</em> and <em>remoting-config.xml</em>. These both reside in <em>{ColdFusion installation}</em>\wwwroot\WEB-INF\flex\. For instance, on my Windows workstation, this is located at c:\ColdFusion8\wwwroot\WEB-INF\flex\.</p>
<p><strong>1. Add the secure channel to remoting-config.xml.</strong> ColdFusion 8 already has a channel in its configuration for RemoteObject over SSL--it is called "my-cfamf-secure"--it just isn't configured to be used. So you have to add the "my-cfamf-secure" channel to remoting-config.xml. To do this, add &lt;channel ref="my-cfamf-secure" /&gt; to the &lt;default-channels&gt; node and the &lt;channels&gt; node for the "ColdFusion" destination.</p>
<p>In other words, your new remoting-config.xml file should look like this:</p>
<div class="igBar"><span id="lxml-40"><a href="#" onclick="javascript:showCodeTxt('xml-40'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-40">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"UTF-8"</span>?<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"remoting-service"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"flex.messaging.services.RemotingService"</span> <span style="color: #000066;">messageTypes</span>=<span style="color: #ff0000;">"flex.messaging.messages.RemotingMessage"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;adapters<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;adapter</span>-definition <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"cf-object"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"coldfusion.flash.messaging.ColdFusionAdapter"</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;adapter</span>-definition <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"java-object"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"flex.messaging.services.remoting.adapters.JavaAdapter"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/adapters<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;default</span>-channels<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">"my-cfamf-secure"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">"my-cfamf"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/default</span>-channels<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;destination</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"ColdFusion"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channels<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">"my-cfamf-secure"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">"my-cfamf"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/channels<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;properties<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;source<span style="font-weight: bold; color: black;">&gt;</span></span></span>*<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/source<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- define the resolution rules and access level of the cfc being invoked --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;access<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Use the ColdFusion mappings to find CFCs, by default only CFC files under your webroot can be found. --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;use</span>-mappings<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/use</span>-mappings<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- allow &quot;public and remote&quot; or just &quot;remote&quot; methods to be invoked --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;method</span>-access-level<span style="font-weight: bold; color: black;">&gt;</span></span>remote<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/method</span>-access-level<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/access<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span>-case<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- cfc property names --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;force</span>-cfc-lowercase<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/force</span>-cfc-lowercase<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Query column names --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;force</span>-query-lowercase<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/force</span>-query-lowercase<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- struct keys --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;force</span>-struct-lowercase<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/force</span>-struct-lowercase<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property</span>-case<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/properties<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/destination<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/service<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This brings me to the first pitfall to watch out for. Be sure to list &lt;channel ref="my-cfamf-secure" /&gt; <em>ahead of</em> &lt;channel ref="my-cfamf" /&gt; so that ColdFusion will try the secure channel <em>first</em>. </p>
<p><strong>2. Add a property to make IE happy.</strong> At this point, your configuration will be adequate for Firefox. However, IE still seems to get tripped up and tries to access the insecure channel. To fix this, just add &lt;add-no-cache-headers&gt;false&lt;/add-no-cache-headers&gt; to the &lt;properties&gt; node of the &lt;channel-definition&gt; nodes for "my-cfamf" and "my-cfamf-secure" in services-config.xml. </p>
<p>I won't display the entire services-config.xml file here, but your "my-cfamf" channel definition will now look like this:</p>
<div class="igBar"><span id="lxml-41"><a href="#" onclick="javascript:showCodeTxt('xml-41'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-41">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channel</span>-definition <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"my-cfamf"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"mx.messaging.channels.AMFChannel"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;endpoint</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">"http://{server.name}:{server.port}{context.root}/flex2gateway/"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"flex.messaging.endpoints.AMFEndpoint"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;properties<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;polling</span>-enabled<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/polling</span>-enabled<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;serialization<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;instantiate</span>-types<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/instantiate</span>-types<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/serialization<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;add</span>-no-cache-headers<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/add</span>-no-cache-headers<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/properties<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/channel</span>-definition<span style="font-weight: bold; color: black;">&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>And the "my-cfamf-secure" channel definition:</p>
<div class="igBar"><span id="lxml-42"><a href="#" onclick="javascript:showCodeTxt('xml-42'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-42">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channel</span>-definition <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"my-cfamf-secure"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"mx.messaging.channels.SecureAMFChannel"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;endpoint</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">"https://{server.name}:{server.port}{context.root}/flex2gateway/cfamfsecure"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"flex.messaging.endpoints.SecureAMFEndpoint"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;properties<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;polling</span>-enabled<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/polling</span>-enabled<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;serialization<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;instantiate</span>-types<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/instantiate</span>-types<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/serialization<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;add</span>-no-cache-headers<span style="font-weight: bold; color: black;">&gt;</span></span>false<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/add</span>-no-cache-headers<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/properties<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/channel</span>-definition<span style="font-weight: bold; color: black;">&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Some more pitfalls to consider.</strong> These can be really misleading, making you think your changes aren't working.</p>
<p><strong>A.</strong> Flex Builder incorporates these settings into your app when it compiles the SWF. Go to your Flex project's properties, under "Flex Compiler", and you'll see a reference to your services-config.xml file. <em>If your SWF is compiled on a workstation that hasn't had these changes, it will not work on your server, even if you did change your server's config files.</em> So be sure that your local installation of ColdFusion has its services-config.xml and remoting-config.xml files updated just like your production server. </p>
<p><strong>B.</strong> On a related note, be sure to <em>recompile</em> an app if you've compiled it before making these config changes. You can recompile in Flex Builder by going to Project &gt; Clean. That option will ensure that you have a clean, recompiled SWF. </p>
<p><strong>C.</strong> If your SWF file is actually served on port 80, it will not be allowed to communicate over the secure channel unless you tell it that it is permissible to do so by setting up a crossdomain.xml file. Check out Shannon Whitley's post <a href="http://www.voiceoftech.com/swhitley/?p=117">SSL, crossing domains, and Flex</a> to read a bit on that.</p>
<p><strong>Tools for the job.</strong> With the right tools, you can test all of these things out on your own. For instance, <a href="http://www.getfirebug.com/">Firebug</a> and <a href="http://www.fiddlertool.com/">Fiddler</a> are great tools for Firefox and IE respectively that clearly show your Flex app's behavior, and whether it is attempting to access the secure or insecure channel. They also show the app attempting to access a crossdomain.xml file when the SWF file was loading over HTTP, because it's first attempt is to make a cross-domain connection to the secure HTTPS channel.</p>
<p>The great thing about this configuration is that your SWFs will use the secure channel when they can, but silently fail over to the insecure channel. So your development workstation doesn't have to use SSL, but your compiled apps will utilize it when you move them to your production server. This is cleaner than setting up a separate "Destination" in remoting-config.xml, or other solutions that require changes to your app's code. Alas, I am still green in the Flex universe and don't claim anything different. Nevertheless, this solution is working perfectly for me and I hope it proves useful for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/flex-remoting-over-ssl/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>iPhone AIR?</title>
		<link>http://blog.crankybit.com/iphone-air/</link>
		<comments>http://blog.crankybit.com/iphone-air/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 22:16:03 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[iPod/iPhone]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/iphone-air/</guid>
		<description><![CDATA[So, with Apple preparing to hold an iPhone Software Roadmap event this Thursday, people are eagerly anticipating news about how Apple will handle an SDK for the iPhone environment. Many developers were frustrated--and many web developers had our curiosities pleasantly piqued--when Apple initially announced that "software" would be available for the iPhone in the form [...]]]></description>
			<content:encoded><![CDATA[<p>So, with Apple preparing to hold an <a href="http://www.appleinsider.com/articles/08/02/27/apple_to_hold_iphone_software_roadmap_media_event_next_week.html" target="_blank">iPhone Software Roadmap event</a> this Thursday, people are eagerly anticipating news about how Apple will handle an SDK for the iPhone environment.</p>
<p>Many developers were frustrated--and many web developers had our curiosities pleasantly piqued--when Apple initially announced that "software" would be available for the iPhone in the form of Ajax web applications. Naturally, many of the disappointed folks were irritated because the web platform is something that they're entirely unfamiliar with, probably having backgrounds in Objective C or something similar; probably a minority were disappointed because their target application legitimately could not be powered by HTML and Ajax.</p>
<p>That said, it is indeed a very thought-provoking concept: Using web technology as your application environment. As most web developers will attest to, there honestly isn't that much that a typical application does that cannot be accomplished with web technology. With the advent of Ajax frameworks, applications built with web technology can have very similar responsiveness and dynamics of a "classic" application. Especially when you remove the burden of cross-browser compatibility, in the iPhone's case.</p>
<p>But with the iPhone/iPod Touch scenario, it is irritating that the application <em>has</em> to reside in Safari and <em>has</em> to be loaded off the web. It almost feels as if Apple was trying to push something that wasn't...quite...ready. Something like <a href="http://www.adobe.com/go/air" target="_blank">AIR</a>!</p>
<p>AIR accomplishes everything that Apple was suggesting for the iPhone environment, but for the desktop. Use web technology, but write a "compiled", stand-alone application that really doesn't even have to use the web. Use HTML. Use Ajax. Use Flex and Flash. Have a nice encapsulated application on your desktop. Especially when you throw the Flash technology into the platform, it is now a very capable environment for a large variety of applications, without being constrained to the browser. Wouldn't it be great if that same cross-platform environment, AIR, worked on the iPhone as well?</p>
<p>Oops, Flash technology isn't currently supported by the iPhone. That is actually another source of contention. And the AIR environment <u>does</u> lose some of its punch without Flash and Flex, even though its HTML/Ajax implementation can do a very decent job with most typical applications.</p>
<p>Steve Jobs has <a href="http://www.apple.com/pr/library/2007/06/11iphone.html" target="_blank">made it clear</a> that he likes the idea of web technology powering iPhone apps. Now, consider some of the  facts. Apple announces the iPhone SDK will be released in February, and then fails to deliver. Meanwhile, Flash still isn't found on the iPhone, and Adobe "invents the wheel" by getting web technology to drive native apps through its work with AIR. Is there a common theme with these events? Perhaps something like: <em><strong>Are Apple and Adobe working together to get the much-needed Flash technology onto the iPhone and, subsequently, releasing an SDK that uses AIR technology, with hooks into the iPhone system just like AIR currently has hooks into the Linux, Windows, and Mac OS X desktop operating systems? </strong></em></p>
<p>It wouldn't be the first time Apple has had to wait for its partners, or take the heat for them. For instance, Apple has clearly been taking a lot of heat for many factors of the iPhone that are clearly not in Apple's interest, but in AT&amp;T's.</p>
<p>And this scenario would fit the circumstances around Adobe's development of AIR. Adobe has been working on AIR since well before the iPhone was released, but AIR wasn't officially released until <em>February 25, 2008. </em>Even if Apple and Adobe <u>were</u> working closely together, there just hasn't been enough time for AIR to get released <em>and </em>hooks to be developed to provide iPhone-specific functionality in AIR. Adobe has understandably concerned itself with its own business first. With that done, attention can turn to Apple to support them in concluding their own business.</p>
<p>Of course, this prediction is a reflection of my own desires as much as it fits the circumstances. As a developer that uses Adobe technology including Flex and AIR, and an Apple enthusiast for more than 20 years, I would love to see things happen this way. Undoubtedly we will have a clearer idea of Apple's iPhone development roadmap after this Thursday.</p>
<p>As if the thought of an "iPhone AIR" isn't confusing enough. <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/iphone-air/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Microsoft Access 2007 and ColdFusion 8</title>
		<link>http://blog.crankybit.com/msaccess2007-and-cf8/</link>
		<comments>http://blog.crankybit.com/msaccess2007-and-cf8/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 19:45:33 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/msaccess2007-and-cf8/</guid>
		<description><![CDATA[With Microsoft Office 2007, Microsoft strikes again and implements a new format for their Access database standard. I do not recommend using Microsoft Access databases for production applications. In fact, I believe you will pay, sooner or later, for adopting such a practice. Nevertheless, it is useful for testing or development at times, and more [...]]]></description>
			<content:encoded><![CDATA[<p>With Microsoft Office 2007, Microsoft strikes again and implements a new format for their Access database standard. I do <u>not</u> recommend using Microsoft Access databases for production applications. In fact, I believe you will pay, sooner or later, for adopting such a practice. Nevertheless, it is useful for testing or development at times, and more importantly, you may be in a situation like me, where there are databases that you do not "own" or control but your ColdFusion apps must use them.</p>
<p>That said, please note that the drivers that come with CF8 do not support Access 2007. This is mentioned in the <a href="http://www.adobe.com/support/documentation/en/coldfusion/8/releasenotes.pdf" target="_blank">ColdFusion 8 Release Notes</a> under #69495. The solution is nicely described right in the release notes. Download and install the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891" target="_blank">Data Connectivity Components for Office 2007</a>, set up a Windows ODBC connection, and use ColdFusion's ODBC socket driver to connect to the Windows ODBC connection. A bit irritating that all of this has to be done, but like I said at the outset, these irritants are the price you pay, among other things, when using Access databases.</p>
<p>Another point to note! You thought you were done, but no, Microsoft has more joy in store for some of us.  The Office 2007 drivers do not support Windows 2000. So if your server is still sitting on a Windows 2000 installation, the final word is either (a) No Access 2007 for you, or (b) Time to upgrade to Windows 2003 SP1 or later.</p>
<p><strong>UPDATE:</strong> Definitely take note of the comment by Oğuz below that describes using JDBC along with the connectivity engine from Microsoft to create the datasource without having to use an ODBC socket.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/msaccess2007-and-cf8/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Notes: BlazeDS Revealed!</title>
		<link>http://blog.crankybit.com/notes-blazeds-revealed/</link>
		<comments>http://blog.crankybit.com/notes-blazeds-revealed/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 00:10:23 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Webinars]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/notes-blazeds-revealed/</guid>
		<description><![CDATA[These are notes from the presentation by Tom Jordahl about BlazeDS. History lesson. Flex 1.0 introduced MXML. Originally built to be a server-based compiler. Flex 2.0 fine-tuned the product. ActionScript 3 was introduced, the Eclipse-based IDE was developed, and the server-side component was renamed Flex Data Services. That server-side product continued development and was renamed [...]]]></description>
			<content:encoded><![CDATA[<p>These are notes from the presentation by Tom Jordahl about <a href="http://opensource.adobe.com/blazeds" target="_blank">BlazeDS</a>.</p>
<p><strong>History lesson. </strong>Flex 1.0 introduced MXML. Originally built to be a <em>server-based </em>compiler. Flex 2.0 fine-tuned the product. ActionScript 3 was introduced, the Eclipse-based IDE was developed, and the server-side component was renamed Flex Data Services. That server-side product continued development and was renamed eventually to LiveCycle Data Services. Finally, a free portion was released as BlazeDS. So, its heart and heritage is in the development of Flex.</p>
<p><strong>So what is BlazeDS?</strong>  The part that lets your Flash/Flex app have remoting and messaging services via web services, remote objects, data push, etc.</p>
<p><em>Remoting.</em> Used to be Flash Remoting. Allows mx:RemoteObject tag be used to make RPC calls to the server.  Allows you to use CFCs and ActionScript or MXML together! Works with Java classes too, but obviously it is very nicely integrated with ColdFusion. This is the most familiar purpose for this kind of tool. But what else can BlazeDS do?</p>
<p><em>Messaging. </em>Publish and Subscribe functionality becomes trivial. We can have real-time pushes over the web. What exactly does this mean? Your Flash/Flex apps can push data from one client to the next without refreshes or polling the server.</p>
<p>These services use AMF (Action Messaging Format). It is fast and small: Rather than being verbose text, it is a compact binary protocol. Not that you would ever have to know that, because it just happens behind the scenes. And its specs have been released, which means it can be supported by open source and third party developers.</p>
<p>So why would you still get LCDS? Well, you get certified builds with warranty coverage and support. You're paying for Adobe to back the product. There will even be an LCDS "Community Edition" that will basically be BlazeDS with this support. Somewhat reminiscent to Red Hat vs. CentOS: Why get Red Hat when CentOS is everything Red Hat is? Because Red Hat has official support for its product. So Adobe is making the technology freely available, and giving you the option to pay for support and official builds and bug fixes.</p>
<p>LCDS "Enterprise Edition" is still the mother of data services. This version adds the data management capability of data services.</p>
<p>The installation of ColdFusion 8 gives you the free express edition of LCDS. But this is a single CPU license. If it doesn't meet your needs, you can configure BlazeDS for ColdFusion 8. But to do this, you WILL have to remove the LCDS Express Edition that installed with CF8. Now, if you're just using Flash Remoting, there isn't any burning need to go to BlazeDS with CF8. However, the messaging features have no CPU restrictions with BlazeDS, so if you are using the messaging features, you may want to go with BlazeDS.</p>
<p>What do you use with BlazeDS vs. LCDS? LCDS has the data management features: Real-time data updates, conflict detection, caching, paging, more!  RTMP channels: Direct socket connection to server, instead of the more resource-expensive HTTP. Scalability is also better with LCDS.</p>
<p>Tom indicated that Flex and BlazeDS will not be standing still. He certainly implied that <a href="http://en.wikipedia.org/wiki/Silverlight" target="_blank">Silverlight</a> is in Adobe's sights by indicating that it is "nipping at [Flex's] heels", suggesting that the AIR, Flex, and BlazeDS technologies will be progressing in development at a rapid pace by Adobe.</p>
<p>Tom explained BlazeDS and LCDS very clearly, albeit at a quick pace at first. My development rarely calls for the messaging features that would especially drive me to BlazeDS, but even so, it was beneficial to understand what BlazeDS is and it is good to know even when a product is <em>not </em>needed in your development arsenal, as in my case. For me, I will be using remoting only, so will stick with LCDS Express that comes with CF8.</p>
<p>Thanks, Tom.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/notes-blazeds-revealed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

