<?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>software, bourbon, and the banjo</title>
	<atom:link href="http://www.cansado.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cansado.org</link>
	<description>musings on software development, usually while inebriated</description>
	<lastBuildDate>Mon, 09 Jan 2012 02:13:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using JavaLoader in Mach-II</title>
		<link>http://www.cansado.org/2010/02/14/using-javaloader-in-mach-ii/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-javaloader-in-mach-ii</link>
		<comments>http://www.cansado.org/2010/02/14/using-javaloader-in-mach-ii/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 22:33:55 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Mach-II]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=71</guid>
		<description><![CDATA[There are probably dozens of ways to incorporate Mark Mandel&#8217;s JavaLoader library into Mach-II, but the way I&#8217;m going to focus on today involves writing a custom Property to handle configuration and access. First off, let&#8217;s look at the source code for the Property: &#60;cfcomponent displayname=&#34;JavaLoaderProperty&#34; output=&#34;false&#34; extends=&#34;MachII.framework.Property&#34;&#62; &#160; &#60;cfset variables.loadPaths = ArrayNew&#40;1&#41;/&#62; &#60;cfset variables.javaLoader [...]]]></description>
			<content:encoded><![CDATA[<p>There are probably dozens of ways to incorporate Mark Mandel&#8217;s <a href="http://javaloader.riaforge.org/">JavaLoader</a> library into Mach-II, but the way I&#8217;m going to focus on today involves writing a custom Property to handle configuration and access.</p>
<p>First off, let&#8217;s look at the source code for the Property:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span></span>
<span style="color: #333333;">   displayname<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;JavaLoaderProperty&quot;</span></span>
<span style="color: #333333;">   output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">   extends<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;MachII.framework.Property&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.loadPaths <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ArrayNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.javaLoader <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;configure&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span></span>
<span style="color: #333333;">              <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Called automatically by Mach-II on application initialization&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isParameterDefined<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;loadPaths&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> setLoadPaths<span style="color: #0000FF;">&#40;</span>getParameter<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;loadPaths&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> prepareJavaLoader<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getJavaLoader&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;javaloader.JavaLoader&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.javaLoader<span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;prepareJavaLoader&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> pathArray <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ArrayNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> i <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">0</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ArrayLen(variables.loadPaths)#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> pathArray<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">expandPath</span><span style="color: #0000FF;">&#40;</span>variables.loadPaths<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.javaLoader <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;javaloader.JavaLoader&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>pathArray<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setLoadPaths&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;loadPaths&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.loadPaths <span style="color: #0000FF;">=</span> arguments.loadPaths<span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getLoadPaths&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.loadPaths<span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>The first thing you&#8217;ll notice is that this is a very simple Property. It only has five methods, 3 of which are accessors/mutators.</p>
<p>The configuration method, per Mach-II Property convention, accesses configured properties through the &#8216;isParameterDefined/getParameter&#8217; methods. These are convenience methods for pulling configuration data out of the <kbd>mach-ii.xml</kbd> file.</p>
<p>Speaking of which, let&#8217;s take a look at the configuration of this particular parameter within the <kbd>mach-ii.xml</kbd> file:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>property <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;javaLoader&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;path.to.JavaLoaderProperty&quot;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>parameters<span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>parameter <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;loadPaths&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>array<span style="color: #0000FF;">&gt;</span></span>
	    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>element <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lib/core.jar&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
	    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>element <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lib/javase.jar&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
	    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>element <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lib/jai_codec.jar&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
	    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>element <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lib/jai_core.jar&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
	    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>element <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lib/barbecue.jar&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
	    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>element <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lib/PDFRenderer.jar&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span>array<span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span>parameter<span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span>parameters<span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span>property<span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>The most important thing to notice is that the configuration parameter is called &#8216;loadPaths&#8217;, which is exactly what we were trying to access from the <kbd>configuration</kbd> method in the Property class.</p>
<p>Once the Property is configured, it sits in the PropertyManager and waits for Listeners to call it via the <kbd>getProperty</kbd> function, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;prepareBarcode&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;event&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;MachII.framework.Event&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> javaLoader <span style="color: #0000FF;">=</span> getProperty<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;javaLoader&quot;</span><span style="color: #0000FF;">&#41;</span>.getJavaLoader<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> barcodeFactory <span style="color: #0000FF;">=</span> javaLoader.create<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;net.sourceforge.barbecue.BarcodeFactory&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
     . . .
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Very simply, we access the <kbd>javaLoader</kbd> Property via <kbd>getProperty("javaLoader").getJavaLoader()</kbd>. Once we have that, we can load any Class that is contained within the Jar files we used during the Property configuration.</p>
<p>I hope this method of accessing a JavaLoader property is useful. If there are any questions or comments, please feel free to leave them below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2010/02/14/using-javaloader-in-mach-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Java&#8217;s BigInteger for Large Operations</title>
		<link>http://www.cansado.org/2009/12/01/using-javas-biginteger-for-large-operations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-javas-biginteger-for-large-operations</link>
		<comments>http://www.cansado.org/2009/12/01/using-javas-biginteger-for-large-operations/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 04:56:39 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=66</guid>
		<description><![CDATA[Java&#8217;s BigInteger is a very handle tool to have in your toolbox as a ColdFusion programmer. If you&#8217;re ever in a situation where you need to do operations on large numbers (larger than a mere 32-bit Integer can handle) you&#8217;ll need to delve into BigInteger territory. For example, someone came into the #Coldfusion channel on [...]]]></description>
			<content:encoded><![CDATA[<p>Java&#8217;s <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html">BigInteger</a> is a very handle tool to have in your toolbox as a ColdFusion programmer. If you&#8217;re ever in a situation where you need to do operations on large numbers (larger than a mere 32-bit Integer can handle) you&#8217;ll need to delve into BigInteger territory.</p>
<p>For example, someone came into the #Coldfusion channel on freenode.net wanting to know why <code>InputBaseN("0x85A308d3", 16)</code> was giving a negative response. Well, that&#8217;s because most numeric operations in ColdFusion are performed on Integers, and the argument was sufficiently large enough to overflow the result into negative.</p>
<p>BigInteger to the rescue! Feast on this code:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> bigint <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;java.math.BigInteger&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;85A308d3&quot;</span>, <span style="color: #FF0000;">16</span><span style="color: #0000FF;">&#41;</span>.<span style="color: #0000FF;">toString</span><span style="color: #0000FF;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Very simply, we&#8217;re creating a BigInteger with the value of 85A308D3 in hexadecimal (the 16 is called the <i>radix</i>) and then outputting it via <code>toString(10)</code> where the 10 is the radix for decimal.</p>
<p>Simple! And if you look at the Javadocs for BigInteger, you&#8217;ll see you can perform a whole slew of operations: addition, subtraction, modulo, xor, and, or, pow&#8230; almost any numeric operation.</p>
<p>So that&#8217;s 10 posts. Time for a celebratory bourbon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/12/01/using-javas-biginteger-for-large-operations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementing a Custom Logger in Mach-II, Part 3</title>
		<link>http://www.cansado.org/2009/11/18/implementing-a-custom-logger-in-mach-ii-part-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=implementing-a-custom-logger-in-mach-ii-part-3</link>
		<comments>http://www.cansado.org/2009/11/18/implementing-a-custom-logger-in-mach-ii-part-3/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 00:54:48 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Mach-II]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=57</guid>
		<description><![CDATA[This is the last of a three-part series. For the first and second parts, click here and here. When we left off last time we had a nearly functioning logger; we were just missing the bits that actually output the logging information to IRC. Let&#8217;s jump right in and fill out the onRequestEnd callback and [...]]]></description>
			<content:encoded><![CDATA[<p>This is the last of a three-part series. For the first and second parts, click <a href="http://www.cansado.org/2009/11/16/implementing-a-custom-logger-in-mach-ii-part-1/">here</a> and <a href="http://www.cansado.org/2009/11/17/implementing-a-custom-logger-in-mach-ii-part-2/">here</a>.</p>
<p>When we left off last time we had a nearly functioning logger; we were just missing the bits that actually output the logging information to IRC. Let&#8217;s jump right in and fill out the <code>onRequestEnd</code> callback and get those logs dumped correctly:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;onRequestEnd&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Sends an email for this logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000FF;">data</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ArrayNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> messageString <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> i <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">0</span><span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!--- Only display output if logging is enabled ---&gt;</span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.getLoggingEnabled<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> AND getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.isLoggingDataDefined<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">data</span> <span style="color: #0000FF;">=</span> getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.getLoggingData<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.<span style="color: #0000FF;">data</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> <span style="color: #0000FF;">ArrayLen</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!--- Send to the channel ---&gt;</span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ArrayLen(data)#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> messageString <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">javaCast</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;string&quot;</span>, <span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span>.channel <span style="color: #0000FF;">&amp;</span> <span style="color: #009900;">&quot;: &quot;</span> <span style="color: #0000FF;">&amp;</span> <span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span>.message<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> sendMessage<span style="color: #0000FF;">&#40;</span>messageString<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;sendMessage&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;message&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> messageCommand <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;f00f.net.irc.martyr.commands.MessageCommand&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>getChannel<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>, arguments.message<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.sendCommand<span style="color: #0000FF;">&#40;</span>messageCommand<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>A very straightforward callback. A vast majority of the time your <code>onRequestEnd</code> callbacks will look exactly like this one, with the only difference being what&#8217;s within the <code>cfloop</code>. The method simply checks to see whether logging is enabled, and if so it loops over all the logging data available, sending each line to the IRC connection through <code>sendMessage</code>. If you want to see what values are available to play around with in the <code>data</code> array, check out <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/browser/framework/1-8-0/trunk/logging/loggers/MachIILog/defaultOutputTemplate.cfm">the MachIILog&#8217;s output template</a> in the source code. It&#8217;s a simple page that&#8217;s pretty easy to understand.</p>
<p>And with that, we have a functioning logger. Let&#8217;s look at the configuration in <code>mach-ii.xml</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Logging&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;MachII.logging.LoggingProperty&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IrcLog&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;struct<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;type&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;project.loggers.IrcLogger&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loggingEnabled&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loggingLevel&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;info&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;irc.server.net&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;channel&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#debugging&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;nick&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;project[bot]&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;filter&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;*,!MachII*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/struct<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Notice <code>server</code>, <code>channel</code>, and <code>nick</code>? Those were the parameters we configured in Part 2. This is where we give those parameters values. <code>Type</code> points to the logger CFC we&#8217;ve been writing, and <code>filter</code> sets up some of the filtering rules mentioned in Part 2.</p>
<p>For more on filtering, read <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/IntroToLogging#UsingtheGenericChannelFilter">how to use the GenericChannelFilter</a> on the wiki; if you want to set up multiple loggers, check out <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/IntroToLogging#MultipleLoggers">the multiple logger section</a> on the same page.</p>
<p>Okay, we&#8217;re set up and running, but we&#8217;re not handling redirects yet. Redirects simply require that the logging data accrued prior to the redirect be persisted and then restored into the new logging data once the redirect is finished. This requires we fill out <code>preRedirect</code>, <code>postRedirect</code>, and a convenience method called <code>arrayConcat</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;preRedirect&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Pre-redirect logic for this logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span></span>
<span style="color: #333333;">		<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Redirect persist data struct.&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.getLoggingEnabled<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> AND getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.isLoggingDataDefined<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> arguments.<span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span>getLoggerId<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.getLoggingData<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;postRedirect&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Post-redirect logic for this logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span></span>
<span style="color: #333333;">		<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Redirect persist data struct.&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> loggingData <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">StructNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.getLoggingEnabled<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> AND getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.isLoggingDataDefined<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftry</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> loggingData <span style="color: #0000FF;">=</span> getLogAdapter<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.getLoggingData<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> loggingData.<span style="color: #0000FF;">data</span> <span style="color: #0000FF;">=</span> arrayConcat<span style="color: #0000FF;">&#40;</span>arguments.<span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span>getLoggerId<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#93;</span>.<span style="color: #0000FF;">data</span>, loggingData.<span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcatch</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;any&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	  <span style="color: #808080; font-style: italic;">&lt;!--- Do nothing as the configuration may have changed between start of</span>
<span style="color: #808080; font-style: italic;">	      the redirect and now ---&gt;</span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcatch</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftry</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;arrayConcat&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Concats two arrays together.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array1&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array2&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> result <span style="color: #0000FF;">=</span> arguments.array1 <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> i <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ArrayLen(arguments.array2)#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">ArrayAppend</span><span style="color: #0000FF;">&#40;</span>result, arguments.array2<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> result <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>There&#8217;s a lot going on here, but don&#8217;t panic! Most of the time you&#8217;ll be able to copy/paste these methods directly into your logger and it will just work. The only time that might not be true is if you implement your own custom Adapter. Functionally, both methods check to make sure logging is enabled, and then either persist or restore the logging data through the registered logging adapter by assigning or saving the data from a <code>data</code> array passed in as an argument.</p>
<p>There&#8217;s one more method before we wrap up this little tutorial: <code>getConfigurationData</code>. As far as I know, this method is just a way to let the Dashboard module (which if you&#8217;re not using, you should really look into) know some information about your logger. For this logger, I implemented it like so:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getConfigurationData&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Gets the configuration data for this logger including adapter and filter.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000FF;">data</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">StructNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span><span style="color: #009900;">&quot;Server&quot;</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> getServer<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span><span style="color: #009900;">&quot;Channel&quot;</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> getChannel<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span><span style="color: #009900;">&quot;Nick&quot;</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> getNick<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">data</span><span style="color: #0000FF;">&#91;</span><span style="color: #009900;">&quot;Logging Enabled&quot;</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">YesNoFormat</span><span style="color: #0000FF;">&#40;</span>isLoggingEnabled<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> <span style="color: #0000FF;">data</span> <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>And that&#8217;s it! We now have a perfectly working IRC-based logger for the Mach-II framework. Finally I can just lounge in my favorite IRC channels and know instantly when a problem happens with my web applications. It&#8217;s also pretty handy to include a call to <code>getLog().info()</code> when some interesting function I wrote goes off, just to watch it run.</p>
<p>If you&#8217;d like to see the whole file, you can download it <a href="http://www.cansado.org/wp-content/uploads/2009/11/Logger.zip">here</a>.</p>
<p>As always, if you have questions or concerns, leave a comment. As always, I&#8217;m going to enjoy a post-entry glass of bourbon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/18/implementing-a-custom-logger-in-mach-ii-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing a Custom Logger in Mach-II, Part 2</title>
		<link>http://www.cansado.org/2009/11/17/implementing-a-custom-logger-in-mach-ii-part-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=implementing-a-custom-logger-in-mach-ii-part-2</link>
		<comments>http://www.cansado.org/2009/11/17/implementing-a-custom-logger-in-mach-ii-part-2/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 23:57:31 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Mach-II]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=51</guid>
		<description><![CDATA[This is the second part of a three-part series. To read the first part, click here. Let&#8217;s dive right in with some boring IRC housekeeping. Since this logger is an IRC-based logger, we&#8217;re going to have to store things like server and channel, so let&#8217;s make those properties of the object: &#60;!--- PROPERTIES ---&#62; &#60;cfset [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second part of a three-part series. To read the first part, <a href="http://www.cansado.org/2009/11/16/implementing-a-custom-logger-in-mach-ii-part-1/">click here</a>.</p>
<p>Let&#8217;s dive right in with some boring IRC housekeeping. Since this logger is an IRC-based logger, we&#8217;re going to have to store things like <code>server</code> and <code>channel</code>, so let&#8217;s make those properties of the object:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #808080; font-style: italic;">      PROPERTIES</span>
<span style="color: #808080; font-style: italic;">    ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.loggerTypeName <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;IRC&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.server <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.channel <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.nick <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.bot <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>In this case, <code>server</code> is the IRC server we&#8217;ll be connecting to; <code>channel</code> is the channel you want the logger to join; <code>nick</code> is the IRC nickname for the bot, and <code>bot</code> is the actual Java object that will be doing all the IRC trickery for us.</p>
<p>Unfortunately we have to do a little more in the way of boring housekeeping code: getters and setters. I&#8217;ll just copy/paste so we can knock these out and move to something more interesting.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #808080; font-style: italic;">      ACCESSORS</span>
<span style="color: #808080; font-style: italic;">    ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setServer&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;server&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.server <span style="color: #0000FF;">=</span> arguments.server <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getServer&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.instance.server <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setChannel&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;channel&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.channel <span style="color: #0000FF;">=</span> arguments.channel <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getChannel&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.instance.channel <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setNick&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;nick&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.nick <span style="color: #0000FF;">=</span> arguments.nick <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getNick&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.instance.nick <span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setBot&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;bot&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;any&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.bot <span style="color: #0000FF;">=</span> arguments.bot<span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getBot&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;any&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> variables.instance.bot<span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now that these properties are in place, let&#8217;s dive into the <code>configure</code> method. First we need to set up the <code>filter</code> and the <code>adapter</code>.</p>
<p>The <code>filter</code> of a logger is simply a configurable object that filters out logging messages based on channels. Say you get along in your development of a Mach-II application and you decide you no longer want to see Mach-II debugging messages. You could disable the Mach-II Logger, or you could introduce a filter set to weed out all those debugging messages. I&#8217;ll get more into filter configuration in Part 3.</p>
<p>The <code>adapter</code> is the object you&#8217;ll eventually be using when you say <code>getLog().debug("your error message")</code>. That method call bubbles all the way into the adapter of the logging interface. The adapter handles all the actual logging of messages and stores all the logging data. We&#8217;ll be using these more in Part 3 when we handle redirects.</p>
<p>Let&#8217;s look at some code:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;configure&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Configures the logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> filter <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;MachII.logging.filters.GenericChannelFilter&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>getParameter<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;filter&quot;</span>, <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> adapter <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;MachII.logging.adapters.ScopeAdapter&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>getParameters<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!--- Set the filter to the adapter ---&gt;</span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> adapter.setFilter<span style="color: #0000FF;">&#40;</span>filter<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!--- Configure and set the adapter ---&gt;</span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> adapter.configure<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> setLogAdapter<span style="color: #0000FF;">&#40;</span>adapter<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>This code simply sets up the <code>filter</code> and <code>adapter</code>. These default objects (<code>GenericChannelFilter</code> and <code>ScopeAdapter</code>) are probably what you want 99% of the time. If there&#8217;s enough demand I might write an entry about writing your own adapter or filter.</p>
<p>Let&#8217;s finish off the <code>configure</code> method by storing some of the preferences we&#8217;ll be passing to our logger via the <code>mach-ii.xml</code> config file and setting up the Java IRC connection object:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">    <span style="color: #808080; font-style: italic;">&lt;!--- Configure the remaining parameters ---&gt;</span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isParameterDefined<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;server&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> setServer<span style="color: #0000FF;">&#40;</span>getParameter<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;server&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfthrow</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IrcLogger&quot;</span></span>
<span style="color: #333333;">		 message<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;A parameter named 'server' is required. The IRC server to which the logger will connect.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isParameterDefined<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;channel&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> setChannel<span style="color: #0000FF;">&#40;</span>getParameter<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;channel&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfthrow</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IrcLogger&quot;</span></span>
<span style="color: #333333;">		 message<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;A parameter named 'channel' is required. The IRC channel which the logger will join.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isParameterDefined<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;nick&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> setNick<span style="color: #0000FF;">&#40;</span>getParameter<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;nick&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfthrow</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IrcLogger&quot;</span></span>
<span style="color: #333333;">		 message<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;A parameter named 'nick' is required. The nick of the bot that will represent the logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> setBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;f00f.net.irc.martyr.IRCConnection&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;f00f.net.irc.martyr.services.AutoRegister&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>getBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>, getNick<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>, getNick<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>, getNick<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;f00f.net.irc.martyr.services.AutoResponder&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>getBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;f00f.net.irc.martyr.services.AutoJoin&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>getBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>, getChannel<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;f00f.net.irc.martyr.services.AutoReconnect&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span>getBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span>.go<span style="color: #0000FF;">&#40;</span>getServer<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>, <span style="color: #FF0000;">6667</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>If you don&#8217;t quite follow all of the <code>createObject</code> lines toward the end, that&#8217;s perfectly fine. We&#8217;re simply setting up the Java object that will connect to the IRC server. Just note that the <code>bot</code> object property will point to the <code>IRCConnection</code> object, as we&#8217;ll need that for the <code>deconfigure</code> method.</p>
<p>Which we will fill out now. What does the <code>deconfigure</code> method do? It simply executes code that needs to happen when the logger is unloaded by the framework. In our case, we&#8217;d like for the <code>IRCConnection</code> to disconnect from the server and shut down. With that in mind, let&#8217;s write some code:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;deconfigure&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> quitCommand <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;f00f.net.irc.martyr.commands.QuitCommand&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;Client exiting...&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.sendCommand<span style="color: #0000FF;">&#40;</span>quitCommand<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getBot<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.stop<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Pretty simple.</p>
<p>If you&#8217;re following along so far, what we have is a <em>nearly</em> functioning IRC logger. In the next part we&#8217;ll actually get to logging some messages, dealing with redirects, and configuring the logger to work with Mach-II. If you have any questions or corrections, please feel free to comment on this entry.</p>
<p>As for me, as always, it&#8217;s time for some bourbon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/17/implementing-a-custom-logger-in-mach-ii-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing a Custom Logger in Mach-II, Part 1</title>
		<link>http://www.cansado.org/2009/11/16/implementing-a-custom-logger-in-mach-ii-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=implementing-a-custom-logger-in-mach-ii-part-1</link>
		<comments>http://www.cansado.org/2009/11/16/implementing-a-custom-logger-in-mach-ii-part-1/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:06:51 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Mach-II]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=47</guid>
		<description><![CDATA[Since I&#8217;m on IRC constantly anyway, I like the various web applications I maintain to be there with me, letting me know if there&#8217;s a problem, or when someone is using a feature I implemented &#8212; that sort of thing. Because of the integration between ColdFusion and Java, this hasn&#8217;t been such a hard thing [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m on IRC constantly anyway, I like the various web applications I maintain to be there with me, letting me know if there&#8217;s a problem, or when someone is using a feature I implemented &#8212; that sort of thing. Because of the integration between ColdFusion and Java, this hasn&#8217;t been such a hard thing to do historically. However, with recent changes to Mach-II&#8217;s logging framework, the implementation just got easier and cleaner.</p>
<p>Mach-II introduced Loggers in version 1.6 &#8220;to give developers a full blown logging package with extensibility to customize&#8221;, which is exactly what we&#8217;re going to take advantage of. If you&#8217;d like to read up on the MachII Logging framework, check out the <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/IntroToLogging">wiki entry.</a></p>
<p>The first step is the Java library that will handle the IRC calls. I chose the <a href="http://martyr.sourceforge.net/">martyr</a> library because you don&#8217;t need to modify or extend it in order to use it for simple use cases, such as this one. If you&#8217;re feeling adventurous, you could use the more well known <a href="http://www.jibble.org/pircbot.php">PircBot</a>. I have used both; if you&#8217;re interested in getting a working logger, use martyr; if you eventually want to have a fully fledged IRC bot, try PircBot.</p>
<p>To install martyr, simply drop the file <code>martyr.jar</code> in your ColdFusion classpath (${ColdFusion Installation Dir}/lib).</p>
<p>Okay, let&#8217;s start coding! Fire up your favorite text editor and create the following skeleton:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span></span>
<span style="color: #333333;">   displayname<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IRCLogger.Logger&quot;</span></span>
<span style="color: #333333;">   extends<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;MachII.logging.loggers.AbstractLogger&quot;</span></span>
<span style="color: #333333;">   output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">   <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;A logger for sending logging information to an IRC channel.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #808080; font-style: italic;">      PROPERTIES</span>
<span style="color: #808080; font-style: italic;">    ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance.loggerTypeName <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;IRC&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #808080; font-style: italic;">      INITIALIZATION / CONFIGURATION / DECONFIGURATION</span>
<span style="color: #808080; font-style: italic;">    ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;configure&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Configures the logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;deconfigure&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #808080; font-style: italic;">      PUBLIC FUNCTIONS</span>
<span style="color: #808080; font-style: italic;">    ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;onRequestEnd&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Here the logger displays its data&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;preRedirect&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Pre-redirect logic for this logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span></span>
<span style="color: #333333;">		<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Redirect persist data struct.&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;postRedirect&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Post-redirect logic for this logger.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span></span>
<span style="color: #333333;">		<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Redirect persist data struct.&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getConfigurationData&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span></span>
<span style="color: #333333;">	      <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Gets the configuration data for this logger including adapter and filter.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #808080; font-style: italic;">      PROTECTED FUNCTIONS</span>
<span style="color: #808080; font-style: italic;">    ---&gt;</span>
&nbsp;
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!---</span>
<span style="color: #808080; font-style: italic;">      ACCESSORS</span>
<span style="color: #808080; font-style: italic;">    ---&gt;</span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>The <code><b>configure</b></code> and <code><b>deconfigure</b></code> methods are hooks that get called when the logger is being initialized by the framework and when the framework unloads the logger, respectively. You would want to put your startup/shutdown logic here. For our IRC example, these methods are where we will create and destroy the IRC connection object.</p>
<p>The <code><b>onRequestEnd</b></code> method is a callback that gets executed (surprise) at the end of the request lifecycle before the user&#8217;s page is rendered. This is where the logger renders its data into a cohesive output. In the Mach-II logger, this means outputing a nice HTML table structure with all the logging data gathered during the request lifecycle. For our IRC logger, that means taking all the logging information gathered during the request lifecyle and formatting it into an easy-to-read string (or strings) to be sent to an IRC channel.</p>
<p>The <code><b>preRedirect</b></code> and <code><b>postRedirect</b></code> functions are somewhat tricky. Conceptually they are easy to understand, but they delve the deepest into the Mach-II logging voodoo. They are at their core callbacks that happen before and after a redirect, respectively. During these callbacks you will want to persist and then restore all the logging information gathered thus far. If you&#8217;re confused at this prospect, I will expound on these functions in Part 3, so keep reading!</p>
<p>The <code><b>getConfigurationData</b></code> function is my favorite, because it&#8217;s the easiest to understand. Its job is simply to return information about this logger. I&#8217;m pretty sure that&#8217;s how the Mach-II Dashboard gets its nice logger display data.</p>
<p>Okay, we have our skeleton and we know roughly what&#8217;s going on. Part 2 is going to cover some boring housekeeping that&#8217;s necessary for IRC, then it will describe what we need to do to implement <code>configure</code> and <code>deconfigure</code>. Part 3 will be on the persisting and restoring of the logging data, and will wrap up our IRC logger with some Mach-II configuration code.</p>
<p>Now we&#8217;ll take a break for bourbon and regroup in the morning.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/16/implementing-a-custom-logger-in-mach-ii-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using CKEditor with Mach-II and JQuery</title>
		<link>http://www.cansado.org/2009/11/12/using-ckeditor-with-mach-ii-and-jquery/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-ckeditor-with-mach-ii-and-jquery</link>
		<comments>http://www.cansado.org/2009/11/12/using-ckeditor-with-mach-ii-and-jquery/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 04:04:02 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Mach-II]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=40</guid>
		<description><![CDATA[CKEditor is a wonderful rich text editor written in Javascript. It more or less replaces a textarea with a robust WYSIWYG editor. Integrating it into your Mach-II application is extremely easy with the new Form taglib and HtmlHelperProperty. This article assumes you&#8217;ve already downloaded, extracted, and copied the CKEditor files into whichever directory you keep [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ckeditor.com/">CKEditor</a> is a wonderful rich text editor written in Javascript. It more or less replaces a <code>textarea</code> with a robust WYSIWYG editor. Integrating it into your Mach-II application is extremely easy with the new Form taglib and <code>HtmlHelperProperty</code>. This article assumes you&#8217;ve already downloaded, extracted, and copied the CKEditor files into whichever directory you keep your Javascript files in.</p>
<p>First thing&#8217;s first: you&#8217;ll need to declare the HtmlHelperProperty in your <code>mach-ii.xml</code> file. In my case, the directory where I keep all my Javascript files is in the project directory, so I need to modify the <code>jsBasePath</code> parameter; the default will look in the absolute-referenced <code>/js</code> directory:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;MachII.properties.HtmlHelperProperty&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jsBasePath&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;js&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Once that&#8217;s in place, your application will be able to use all the cool functionality introduced with the <code>HtmlHelperProperty</code>. To learn more about this property, check out <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/HTMLHelperProperty">the specification</a> on the Mach-II wiki.</p>
<p>The next step will be to make the form aware of the new Form taglib. This is easily accomplished by adding the following line to the top of your <code>cfm</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfimport</span> prefix<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;form&quot;</span> taglib<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;/MachII/customtags/form&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Again, feel free to refer to the <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/MachII1.8SpecificationFormTagLib">documentation</a> to learn more about the Form taglib.</p>
<p>Since we plan on using the CKEditor, we should probably import that Javascript file. I assume that most people use a templating scheme of some sort, so adding per-page Javascript files can get kind of hairy. Luckily the <code>HtmlHelperProperty</code> we declared earlier makes this extremely easy. Simply add the following line under the Form taglib declaration:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getProperty<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;html&quot;</span><span style="color: #0000FF;">&#41;</span>.addJavascript<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;jquery-1.3.2.min.js&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getProperty<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;html&quot;</span><span style="color: #0000FF;">&#41;</span>.addJavascript<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;ckeditor_basic.js&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>I went ahead and threw in the JQuery declaration since we&#8217;ll be using that in a few minutes.</p>
<p>Now we need to define a <code>textarea</code> control that we&#8217;re going to  replace with the CKEditor. In our test file, we&#8217;ll call this field <code>description</code> as if we&#8217;re describing some product in a bookstore.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>form:form actionEvent<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;product.create&quot;</span> bind<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;product&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!--- . . . ---&gt;</span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>form:textarea path<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;description&quot;</span> <span style="color: #0000FF;">rows</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10&quot;</span> <span style="color: #0000FF;">cols</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;50&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
     <span style="color: #808080; font-style: italic;">&lt;!--- . . . ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span>form:form<span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>So far, so good, and so simple. The next step is to actually add the Javascript code that replaces the <code>textarea</code> with the CKEditor control. The documentation suggests that you either do this directly after you create the <code>textarea</code> or put the code in function to be called when the page is finished loading. Fortunately JQuery makes this simple.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> onLoadFunction <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  CKEDITOR.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;product&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span>onLoadFunction<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>All it takes is a couple dozen lines of code and your <code>textarea</code> can support rich text. Wow your friends, neighbors, and bosses, while you secretly let Mach-II do the heavy lifting, a glass of your favorite bourbon in hand. If you don&#8217;t like bourbon, I&#8217;ll hold your glass for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/12/using-ckeditor-with-mach-ii-and-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mach-II Deployment with Apache Ant</title>
		<link>http://www.cansado.org/2009/11/10/mach-ii-deployment-with-apache-ant/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mach-ii-deployment-with-apache-ant</link>
		<comments>http://www.cansado.org/2009/11/10/mach-ii-deployment-with-apache-ant/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 01:44:04 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Mach-II]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=31</guid>
		<description><![CDATA[One of the (admittedly few) things that bugs me about ColdFusion development is deploying an application. Mach-II alleviated some of this pain with its recent addition of Environment properties, but (unless I&#8217;m mistaken) a large problem still exists: being able to deploy your application twice on the same machine or under a different directory name. [...]]]></description>
			<content:encoded><![CDATA[<p>One of the (admittedly few) things that bugs me about ColdFusion development is deploying an application. Mach-II alleviated some of this pain with its recent addition of <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/EnvironmentSpecificProperities">Environment properties</a>, but (unless I&#8217;m mistaken) a large problem still exists: being able to deploy your application twice on the same machine or under a different directory name.</p>
<p>Why would you want to do this? Well, at my company we only have a development server and a deployment server. What should we do for staging, QA, or continuous integration deployments? We can fake it by deploying an application under a different name/directory on the same server as another deployment of the same application. We just have to make sure to avoid ApplicationName (and other property) collisions.</p>
<p>I do this with <a href="http://ant.apache.org">Apache Ant</a>. First we create a Java properties file containing some per-deployment properties (I call this file <code>build.properties</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="properties" style="font-family:monospace;"><span style="color: #000080; font-weight:bold;">cf.app.root</span><span style="color: #000000;">=</span><span style="color: #008000; font-weight:bold;">myproject</span>
<span style="color: #000080; font-weight:bold;">cf.app.dsn</span><span style="color: #000000;">=</span><span style="color: #008000; font-weight:bold;">mysql_myproject</span>
<span style="color: #000080; font-weight:bold;">cf.app.deploy.dir</span><span style="color: #000000;">=</span><span style="color: #008000; font-weight:bold;">/var/www/html/myproject</span></pre></div></div>

<p>Then we modify the layout of the Mach-II Skeleton. For this example, all my config files will be put into the &#8216;config&#8217; directory; Application.cfc is in the &#8216;base&#8217; directory; all other deployment-agnostic files are in the &#8216;src&#8217; directory.</p>
<p>Let&#8217;s take a look at how these mappings look in a basic <code>mach-ii.xml</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE mach-ii PUBLIC &quot;-//Mach-II//DTD Mach-II Configuration 1.6.0//EN&quot;</span>
<span style="color: #00bbdd;">	  &quot;http://www.mach-ii.com/dtds/mach-ii_1_6_0.dtd&quot; &gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mach-ii</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.6&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #808080; font-style: italic;">&lt;!-- INCLUDES --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;./mach-ii_coldspringProperty.xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;applicationRoot&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/@cf.app.root@&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultEvent&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;home&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;eventParameter&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;event&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;parameterPrecedence&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;form&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- LISTENERS --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listeners<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;testListener&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;/@cf.app.root@/listeners/TestListener&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userListener&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;/@cf.app.root@/listeners/UserListener&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;reportListener&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;/@cf.app.root@/listeners/ReportListener&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listeners<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- . . . --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mach-ii<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Notice the <code>@cf.app.root@</code>? That tells Ant &#8220;We need to replace this with some kind of property value&#8221;. Now let&#8217;s look at a sample buildfile:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myproject&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;dist&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Buildfile for a Sample Project<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;help&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;usage information for common tasks&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>usage: ant [target]<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>target can be all, init, dist, deploy, clean, install, help <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;init&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Initializes a project and all relevant data&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;build/config&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;dist&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clean&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Cleans up the entire project</span>
<span style="color: #009900;">						   (reset)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;dist&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Builds the code from source files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;src&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;webapp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter</span> <span style="color: #000066;">filtersfile</span>=<span style="color: #ff0000;">&quot;build.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;build/config&quot;</span> <span style="color: #000066;">filtering</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;config&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">filtering</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;base&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dist&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Creates the distribution code&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;dist&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The magic happens within <code>&lt;copy todir="build" filtering="true"&gt;</code>. That tells Ant to copy the files to the &#8216;build&#8217; directory and replace all the <code>@cf.app.whatever@</code> tags with values found in the build.properties file mentioned earlier. After running this Ant script, we&#8217;ll have the following waiting for us in <code>dist/config/mach-ii.xml</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mach-ii</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.6&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- . . . --&gt;</span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;applicationRoot&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/myproject&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- . . . --&gt;</span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- . . . --&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mach-ii<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The goal is to have a perfect distribution of your application ready for you in the &#8216;dist&#8217; directory. You could easily add additional Ant tasks to deploy your application to its home directory through FTP or a direct copy.</p>
<p>It doesn&#8217;t seem like much, but with these small changes I can now modify build.properties and deploy the application wherever I see fit, under any directory. Having multiple deployments on a single server, while not ideal, is perfectly doable.</p>
<p>Ant is an extraordinarily powerful build tool. I enjoy working with it and I&#8217;ve only barely tapped into its abilities. Hopefully if you&#8217;ve never evaluated it for one of your projects, you will soon. It has really made deployment a non-issue for the projects I use it on.</p>
<p>Post #5 done. Afk bourbon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/10/mach-ii-deployment-with-apache-ant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Note to Self &#8211; Mach-II Skeleton from Subversion</title>
		<link>http://www.cansado.org/2009/11/09/note-to-self-mach-ii-skeleton-from-subversion/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=note-to-self-mach-ii-skeleton-from-subversion</link>
		<comments>http://www.cansado.org/2009/11/09/note-to-self-mach-ii-skeleton-from-subversion/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 04:56:58 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Note to Self]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=24</guid>
		<description><![CDATA[A note to myself for future development: Use the Mach-II Skeleton. Its integration with ColdSpring and the Mach-II Dashboard is fantastically easy to set up. svn co http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/skeleton/1-8-0/trunk ${name.of.project} find ${name.of.project} -type d -name &#34;.svn&#34; -exec rm -rf &#123;&#125; \; Okay, now you may develop your project.]]></description>
			<content:encoded><![CDATA[<p>A note to myself for future development:</p>
<p>Use the Mach-II Skeleton. Its integration with ColdSpring and the Mach-II Dashboard is fantastically easy to set up.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>greatbiztoolsllc.svn.cvsdude.com<span style="color: #000000; font-weight: bold;">/</span>mach-ii<span style="color: #000000; font-weight: bold;">/</span>skeleton<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1</span>-<span style="color: #000000;">8</span>-<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span>trunk <span style="color: #800000;">${name.of.project}</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #800000;">${name.of.project}</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;.svn&quot;</span> <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

<p>Okay, <b>now</b> you may develop your project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/09/note-to-self-mach-ii-skeleton-from-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TransferObject Decorators and the Mach-II Event-Bean</title>
		<link>http://www.cansado.org/2009/11/07/transferobject-decorators-and-the-mach-ii-event-bean/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=transferobject-decorators-and-the-mach-ii-event-bean</link>
		<comments>http://www.cansado.org/2009/11/07/transferobject-decorators-and-the-mach-ii-event-bean/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 00:22:03 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Mach-II]]></category>
		<category><![CDATA[Transfer ORM]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=15</guid>
		<description><![CDATA[If you&#8217;ve been following this blog, you know I&#8217;ve been trying to get TransferObjects to function as Mach-II event-beans. A problem that has been solved, I&#8217;m happy to say, with the help of Transfer Decorators. The approach I took was to supplement my TransferObjects with methods that would only be used by the event-bean during [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been following this blog, you know I&#8217;ve been trying to get TransferObjects to function as Mach-II event-beans. A problem that has been solved, I&#8217;m happy to say, with the help of <a href="http://www.transfer-orm.com">Transfer</a> <a href="http://docs.transfer-orm.com/wiki/Writing_Decorators.cfm">Decorators</a>.</p>
<p>The approach I took was to supplement my TransferObjects with methods that would only be used by the event-bean during form-to-bean population, and only for non-string methods. For example, my Course object has a &#8216;cost&#8217; associated with it, which is a numeric. I added the following to my Course decorator:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getCostString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> getCost<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setCostString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;costString&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> <span style="color: #0000FF;">isNumeric</span><span style="color: #0000FF;">&#40;</span>arguments.costString<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> setCost<span style="color: #0000FF;">&#40;</span>arguments.costString<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Note that the functions and argument both reference a <code>costString</code> instead of just a <code>cost</code>. The <code>costString</code> will only be used by the event-bean population code, which means you need to modify your form:input tag as well:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">label</span> <span style="color: #0000FF;">for</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;costString&quot;</span><span style="color: #0000FF;">&gt;</span></span>Cost to Participants<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">label</span><span style="color: #0000FF;">&gt;</span></span>
      $<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>form:input path<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;costString&quot;</span><span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Once this code is in place, the event-bean works like a charm, populating all the fields you need without throwing those pesky errors due to string-to-numeric or string-to-date mistypes. It even works for checkboxes:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">label</span> <span style="color: #0000FF;">for</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatString&quot;</span><span style="color: #0000FF;">&gt;</span></span>Education Format<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">label</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">query</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatQuery&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>form:checkbox path<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatString&quot;</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#educationFormatQuery.id#&quot;</span><span style="color: #0000FF;">/&gt;</span></span><span style="color: #0000FF;">#educationFormatQuery.format#</span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getEducationFormatString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> returnString <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> formats <span style="color: #0000FF;">=</span> getEducationFormatsArray<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ArrayLen(formats)#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> returnString <span style="color: #0000FF;">neq</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> returnString <span style="color: #0000FF;">=</span> returnString <span style="color: #0000FF;">&amp;</span> <span style="color: #009900;">&quot;,&quot;</span><span style="color: #0000FF;">/&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> returnString <span style="color: #0000FF;">=</span> returnString <span style="color: #0000FF;">&amp;</span> formats<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span>.getId<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> returnString<span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setEducationFormatString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatString&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> array <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ListToArray</span><span style="color: #0000FF;">&#40;</span>arguments.educationFormatString<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> clearEducationFormats<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ArrayLen(array)#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> addEducationFormats<span style="color: #0000FF;">&#40;</span>getTransfer<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.get<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;gorgon.EducationFormat&quot;</span>, array<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Since I&#8217;m using decorators anyway, why not just overwrite the methods for setting/getting numeric/date/checkboxes and be done with it? Well, I figured the solutions for populating event-beans and regular TransferObject usage might be completely different depending on the complexity of the bean; why go cluttering up a bean with extraneous method overloading and type-checking when I could just add a couple of methods that are only specifically used by one instance of the framework, and then ignored the rest of the time? Basically it&#8217;s a trade-off, and neither side is well explored territory so I erred on what I thought was the side of caution. I&#8217;m completely open to trying it the other way if the data suggest I made a design mistake.</p>
<p>So there you have it, after three iterations of attempts I&#8217;m finally binding forms to TransferObjects without writing too much code. Now we get to move out of the kiddy-pool and start coding for real. Hopefully this project will go forward more smoothly and will be much more maintainable now that I have what I consider a clean design from the start.</p>
<p>We shall see.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/07/transferobject-decorators-and-the-mach-ii-event-bean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You Can&#8217;t Proxy TransferObjects in ColdSpring</title>
		<link>http://www.cansado.org/2009/11/05/you-cant-proxy-transferobjects-in-coldspring/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=you-cant-proxy-transferobjects-in-coldspring</link>
		<comments>http://www.cansado.org/2009/11/05/you-cant-proxy-transferobjects-in-coldspring/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 20:04:55 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[ColdSpring]]></category>
		<category><![CDATA[Transfer ORM]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=9</guid>
		<description><![CDATA[In an attempt to use TransferObjects as event-beans I created a class called TransferObjectBindingAdvice that would wrap around the setter methods called by the Mach-II event-beans, to be installed and called via the AOP hooks in ColdSpring. I had high hopes that this proxied object would be able to take the place of the more [...]]]></description>
			<content:encoded><![CDATA[<p>In an attempt to <a href="http://www.cansado.org/2009/11/04/using-transferobjects-as-mach-ii-event-beans/">use TransferObjects as event-beans</a> I created a class called <code>TransferObjectBindingAdvice</code> that would wrap around the setter methods called by the Mach-II <code>event-bean</code>s, to be installed and called via the AOP hooks in ColdSpring. I had high hopes that this proxied object would be able to take the place of the more advanced data binding hooks that I would&#8217;ve liked to see in the upcoming 1.9 release of Mach-II.</p>
<p>I wanted to be able to verify that setters expecting a Date object would get a valid date string, sure; but I also wanted to be able to bind more complex objects to the <code>event-bean</code>s. For example, I could pass in the TransferFactory in the aspect&#8217;s declaration in the ColdSpring configuration file, and use it on a setter for a many-to-many relationship which would be represented as a checkbox group on a form. Simply loop through the list of IDs passed as that checkbox group and build your relationship, all before the controller gets called.</p>
<p>Unfortunately <a href="http://corfield.org/blog/index.cfm?">Sean Corfield</a> pointed out this approach was technically impossible. He told me that TransferObjects are generated dynamically and the methods only exist at runtime, so they can&#8217;t be proxied by ColdSpring.</p>
<p>Which brings me back to square one. What is the best way to handle form-binding cleanly in Mach-II? Do I need to create model objects and be done with it? Should I use Transfer decorators? Should I give up hope of using TransferObjects, the <code>event-bean</code> command, and the &lt;form&gt; taglib in harmony?</p>
<p>Nah. Next up: decorators!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/05/you-cant-proxy-transferobjects-in-coldspring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
