<?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>Jay Drummond's - Blog &#187; Programming</title>
	<atom:link href="http://drummondsoftware.com/blog/index.php/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://drummondsoftware.com/blog</link>
	<description>WordPress weblog</description>
	<lastBuildDate>Sat, 11 Sep 2010 13:09:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Don&#8217;t have programs open in Ubuntu during system update&#8230;</title>
		<link>http://drummondsoftware.com/blog/2010/09/11/dont-have-programs-open-in-ubuntu-during-system-update/</link>
		<comments>http://drummondsoftware.com/blog/2010/09/11/dont-have-programs-open-in-ubuntu-during-system-update/#comments</comments>
		<pubDate>Sat, 11 Sep 2010 13:09:56 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[computing]]></category>

		<guid isPermaLink="false">http://drummondsoftware.com/blog/?p=195</guid>
		<description><![CDATA[Ran into an issue because I wanted to work on my computer while a system update was going on. I had the browser open and was making database changes in my LAMP environment. 
I was using phpMyAdmin to create a new table. I did that and closed the browser (without logging off) and rebooted after [...]]]></description>
			<content:encoded><![CDATA[<p>Ran into an issue because I wanted to work on my computer while a system update was going on. I had the browser open and was making database changes in my LAMP environment. </p>
<p>I was using phpMyAdmin to create a new table. I did that and closed the browser (without logging off) and rebooted after the kernel update. </p>
<p>Then logged back into phpMyAdmin to make more changes. The signin page came up fine. I entered my credentials and I was greeted by the following error:</p>
<p>phpMyAdmin &#8211; Error</p>
<p>Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.</p>
<div id="attachment_198" class="wp-caption aligncenter" style="width: 731px"><img src="http://drummondsoftware.com/blog/wp-content/uploads/2010/09/phpMyAdminError.png" alt="phpMyAdmin - Error" title="phpMyAdminError" width="721" height="95" class="size-full wp-image-198" /><p class="wp-caption-text">phpMyAdmin - Error</p></div>
<p>A quick search and I found an article that gave me the clue I needed: </p>
<p>As Root:<br />
<code><br />
root@jdrummond-laptop:~# cd /var/lib/php5<br />
root@jdrummond-laptop:/var/lib/php5# ls -l<br />
total 40<br />
-rw------- 1 www-data www-data 37673 2010-09-11 08:25 sess_f3pq4jcastnul23laj48ot92684u414p<br />
root@jdrummond-laptop:/var/lib/php5# rm sess_f3pq4jcastnul23laj48ot92684u414p<br />
</code></p>
<p>Looks like a session got stranded in the folder and had some bogus data in it. </p>
<p>To fix this I removed the old session file and then phpMyAdmin was able to make new session files with no problem. </p>
<p>Here&#8217;s what the directory looked like after I got rid of the session that was blocking my login, and was in fact logged in.<br />
<code><br />
root@jdrummond-laptop:/var/lib/php5# ls -l<br />
total 76<br />
-rw------- 1 www-data www-data 17305 2010-09-11 08:31 sess_5jc4klqbfsp5r53s7410n61o64dchjot<br />
-rw------- 1 www-data www-data 34934 2010-09-11 08:31 sess_f3pq4jcastnul23laj48ot92684u414p<br />
-rw------- 1 www-data www-data 17305 2010-09-11 08:31 sess_tgfla0dqoj33m2mrqvm08r7t3npvhhsh<br />
</code></p>
<p>If I hadn&#8217;t had files open during the update, I could have saved some headaches. Moral of the story is. Close all programs before updating your Ubuntu system.</p>
<p>References:<br />
<a href="http://www.electrictoolbox.com/phpmyadmin-cannot-start-session-without-errors/">http://www.electrictoolbox.com/phpmyadmin-cannot-start-session-without-errors/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://drummondsoftware.com/blog/2010/09/11/dont-have-programs-open-in-ubuntu-during-system-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>World Community Grid Statisics</title>
		<link>http://drummondsoftware.com/blog/2009/09/28/world-community-grid-statisics/</link>
		<comments>http://drummondsoftware.com/blog/2009/09/28/world-community-grid-statisics/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 13:27:06 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[computing]]></category>

		<guid isPermaLink="false">http://drummondsoftware.com/blog/?p=185</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div id="attachment_186" class="wp-caption alignnone" style="width: 589px"><a href="http://drummondsoftware.com/blog/wp-content/uploads/2009/09/mygridprogress20090928.png"><img src="http://drummondsoftware.com/blog/wp-content/uploads/2009/09/mygridprogress20090928.png" alt="mygridprogress20090928" title="mygridprogress20090928" width="579" height="559" class="size-medium wp-image-186" /></a><p class="wp-caption-text">mygridprogress20090928</p></div>
]]></content:encoded>
			<wfw:commentRss>http://drummondsoftware.com/blog/2009/09/28/world-community-grid-statisics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Training Course Development Platform</title>
		<link>http://drummondsoftware.com/blog/2009/07/19/java-training-course-development-platform/</link>
		<comments>http://drummondsoftware.com/blog/2009/07/19/java-training-course-development-platform/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 01:36:33 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[VMWare]]></category>

		<guid isPermaLink="false">http://drummondsoftware.com/blog/?p=135</guid>
		<description><![CDATA[This post hold information about a VMware image that I created for a report that I am working on in my Technical Communications course at Capella University. The report is on Java training for beginners. This image contains software that is pre-installed on a student&#8217;s classroom PC. For those who don&#8217;t have access to the [...]]]></description>
			<content:encoded><![CDATA[<p>This post hold information about a VMware image that I created for a report that I am working on in my Technical Communications course at <a href="http://www.capella.edu">Capella University</a>. The report is on Java training for beginners. This image contains software that is pre-installed on a student&#8217;s classroom PC. For those who don&#8217;t have access to the physical classroom, this image can be used to follow along with the course. </p>
<p>System Requirements<br />
 &#8211; 2 gigs of RAM<br />
 &#8211; 10 gigs of hard drive space</p>
<p>Windows or Linux &#8211; <a href="http://www.vmware.com/products/player/">the VMware Player.</a> Free.<br />
Mac OSx &#8211; <a href="http://www.vmware.com/products/fusion/">VMware Fusion.</a> Free 30day trial.</p>
<p>The software list follows:<br />
This starts with a LAMP setup.  LAMP is an acronym for Linux, Apache, MySQL, and PHP. This combination of software is a common configuration for running PHP web applications. This has little to do with running Java, but does allow phpmyadmmin to be run. This is a web based MySQL database administration application. It&#8217;s easy to use and popular for administering a database from a remote site.</p>
<p><a href="http://www.ubuntu.com/">Ubuntu 8.10</a> &#8211; updated July 18th with all patches and fixes. </p>
<p><a href="http://www.apache.org/">Apache 2.0</a> &#8211; web server</p>
<p><a href="http://www.mysql.com/">MySQL</a> &#8211; version 5.0 &#8211; Version 5.0.67-0ubuntu</p>
<p><a href="http://www.php.net/">PHP</a> version 5 &#8211; a web application programming language. </p>
<p><a href="http://www.phpmyadmin.net">phpmyadmin</a> &#8211; A PHP based web application for administrating MySQL </p>
<p><a href="http://www.eclipse.org/europa/">Eclipse Europa</a>. &#8211; This is the base version of eclipse with few plugins. </p>
<p><a href="http://www.jboss.org/community/wiki/InstallingJBossTools">JBoss Developer Studio </a> Community Edition &#8211; If you like this version the release is available for a mere $99 from <a href="http://www.jboss.com/products/devstudio/">here.</a></p>
<p><a href="http://java.sun.com/javase/downloads/index.jsp"><br />
jre 1.6.0 update 14</a><br />
Installed to /usr/java/jre1.6.0_14</p>
<p><a href="http://java.sun.com/javaee/downloads/index.jsp?userOsIndex=1&#038;userOsId=linux&#038;userOsName=Linux">Java EE 5 SDK</a> with jdk 1.6.0 update 14<br />
Installed to /usr/java/SDK</p>
<p><a href="http://subversion.tigris.org/">Subversion</a> version 1.5  &#8211; a source code control system.</p>
<p><a href="http://subclipse.tigris.org/">subclipse</a> version 1.4 &#8211; integration of subversion into eclipse. </p>
<hr />
To gain access to the VMware image, send me an email and ask me for the username and password.<br />
Download the VMware Appliance here: <a href="ftp://ftp.jxfs.org/vmware/Ubuntu.tar.gz">Download</a><br />
File size: 2,271,743,211<br />
The md5sum sum: eb36f88c6bcdd06c8b46d204c580cf3e</p>
<hr />
<p>Once the file has downloaded, extract the files contained in the Ubuntu.tar.gz archive. To do this, on windows use winzip. On Linux and MAC use tar like this: tar -xvf Ubuntu.tar.gz</p>
<p>Inside the archive are two files. </p>
<ol>
<li>Ubuntu-disk1.vmdk
<li>Ubuntu.vmx
</ol>
<p>Next run the VMware player. Once the program loads, click &#8220;Open Existing Virtual Machine&#8221;, and browse to the directory where you extracted the files from the archive. Select UBuntu.vmx and click Open.</p>
<hr />
]]></content:encoded>
			<wfw:commentRss>http://drummondsoftware.com/blog/2009/07/19/java-training-course-development-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEAM In Action &#8211; MySql DDL</title>
		<link>http://drummondsoftware.com/blog/2009/03/06/seam-in-action-mysql-ddl/</link>
		<comments>http://drummondsoftware.com/blog/2009/03/06/seam-in-action-mysql-ddl/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 11:29:22 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[downloads]]></category>

		<guid isPermaLink="false">http://drummondsoftware.com/blog/?p=22</guid>
		<description><![CDATA[I have been going through the book &#8220;SEAM in Action&#8221; by  Dan Allen.

I typically use MySQL databases and so I created the example database that is used in the book. Download it here: open18-mysql.tar.gz
While going through the book, I also chose to use JBoss Developer Studio  (Version 2.0 CR2 beta). Some of the [...]]]></description>
			<content:encoded><![CDATA[<p>I have been going through the book &#8220;SEAM in Action&#8221; by  Dan Allen.</p>
<p><iframe src="http://rcm.amazon.com/e/cm?t=drummsoftw-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=1933988401&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>
<p>I typically use <a href="http://www.mysql.com/">MySQL</a> databases and so I created the example database that is used in the book. Download it here: <a href="http://drummondsoftware.com/hpi/open18-mysql.tar.gz">open18-mysql.tar.gz</a></p>
<p>While going through the book, I also chose to use <a href="http://www.redhat.com/developer_studio/">JBoss Developer Studio</a>  (Version 2.0 CR2 beta). Some of the SEAM Gen, generated code is a bit different than what the Author shows in the book. For example, some of the fancier editing of referentially defined data doesn&#8217;t seem to be present. I don&#8217;t know if this is because of my DDL or the SEAM generating that&#8217;s available in JBoss Developer Studio. </p>
<hr />
<iframe src="http://rcm.amazon.com/e/cm?t=drummsoftw-20&#038;o=1&#038;p=13&#038;l=ur1&#038;category=electronics&#038;banner=0JS3Z2NDQ4D78G5E5CG2&#038;f=ifr" width="468" height="60" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe></p>
<hr />
]]></content:encoded>
			<wfw:commentRss>http://drummondsoftware.com/blog/2009/03/06/seam-in-action-mysql-ddl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ANT Tasks for RetroGuard</title>
		<link>http://drummondsoftware.com/blog/2009/03/05/ant-tasks-for-retroguard/</link>
		<comments>http://drummondsoftware.com/blog/2009/03/05/ant-tasks-for-retroguard/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 11:00:33 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://drummondsoftware.com/blog/?p=31</guid>
		<description><![CDATA[I found this really cool thing known as RetroGuard java byte code obfuscation. Except that, I wanted to be able to call it from an ANT task. So I wrote some ANT tasks to allow RetroGuard to be invoked. Now I can make obfuscated code from any part of my build process. 
I had these [...]]]></description>
			<content:encoded><![CDATA[<p>I found this really cool thing known as <a href="http://www.retrologic.com/">RetroGuard java byte code obfuscation</a>. Except that, I wanted to be able to call it from an ANT task. So I wrote some ANT tasks to allow RetroGuard to be invoked. Now I can make obfuscated code from any part of my build process. </p>
<p>I had these available for download, but noticed that the RetroGuard folks integrated my code into their deliverables, pretty much line for line.  So if you need this, you can just download from the RetroGuard site: <a href="http://www.retrologic.com/retroguard-main.html">RetroGuard java byte code obfuscation.</a></p>
<p>I had asked them to acknowledge my contribution, but so far they haven&#8217;t. </p>
<hr />
<iframe src="http://rcm.amazon.com/e/cm?t=drummsoftw-20&#038;o=1&#038;p=13&#038;l=ur1&#038;category=games&#038;banner=0SHM20AGDF3RTX3R3DG2&#038;f=ifr" width="468" height="60" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe></p>
<hr />
]]></content:encoded>
			<wfw:commentRss>http://drummondsoftware.com/blog/2009/03/05/ant-tasks-for-retroguard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOW TO &#8211; merge Spring Framework and COMMONS Chain ( &#8220;Chain of Responsibility&#8221; )</title>
		<link>http://drummondsoftware.com/blog/2009/03/03/how-to-merge-spring-framework-and-commons-chain-chain-of-responsibility/</link>
		<comments>http://drummondsoftware.com/blog/2009/03/03/how-to-merge-spring-framework-and-commons-chain-chain-of-responsibility/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 22:20:00 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[commons]]></category>
		<category><![CDATA[designPattern]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://drummondsoftware.com/blog/?p=10</guid>
		<description><![CDATA[Jakarta Commons Chain project is a gang of four design pattern for &#8220;Chain of Responsibility&#8221;.
Spring Framework is an open source project that is hosted on Source Forge. It can be summed up as a framework that implements the factory pattern who&#8217;s objects  are configured with XML documents.
This white paper shows how these two frameworks [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://commons.apache.org/chain/">Jakarta Commons Chain</a> project is a gang of four design pattern for &#8220;Chain of Responsibility&#8221;.</p>
<p><a href="http://www.springsource.org/">Spring Framework</a> is an open source project that is hosted on <a href="http://sourceforge.net/projects/springframework/">Source Forge</a>. It can be summed up as a framework that implements the factory pattern who&#8217;s objects  are configured with XML documents.</p>
<p>This white paper shows how these two frameworks can be used together. So if you already use Spring and want to add Commons Chain, or if you use Commons Chain and are not quite happy with the supplied catalogue for creating a chain. Then read on. </p>
<hr />
<h3>Goal<a name="Goal"></a>:</h3>
<p>Build some simple examples, step by step, that will allow an understanding of how you can combine <a href="http://jakarta.apache.org/commons/chain/">Jakarta Commons Chain</a> objects and the <a href="http://www.springframework.org/">Spring Framework</a>. At the completion of these examples you should be able to create <em>Commands</em> and <em>Chains</em> along with your other Spring managed objects. </p>
<h3>Prerequisites:<a name="Prerequisites"></a></h3>
<ul>
<li>This paper assumes a basic knowledge of <a href="http://java.sun.com">Java</a> and <a href="http://www.eclipse.org">Eclipse</a>. </li>
<li>You should have Eclipse and an Java SDK installed and working.</li>
<li>Download the binary distributions of the <a href="http://sourceforge.net/project/showfiles.php?group_id=73357">Spring Framework</a> (the one with dependencies) and  <a href="http://commons.apache.org/downloads/download_chain.cgi">Jakarta Commons Chain</a> and unzip them into a directory. This white paper uses the Spring Framework version 1.2.3 and Commons Chain version 1.0. </li>
<li>Other jars needed: log4j, Commons Collections, Commons Pool, Commons Dbcp, Commons Lang, and MySql JDBC driver. </li>
</ul>
<h3>Create a project to build examples:<a name="Createaprojecttobuildexamples"></a></h3>
<p>Start your Eclipse IDE and open a workspace where we can create a project to start playing with Spring and Chain frameworks. </p>
<p>Call the project SpringChain as shown in <a href="/WhitePapers/SpringChain/images/mkProjectP1.png">figure 1</a>. Then click next and click &quot;add Folder&quot; to associate a source directory called src with the project. When prompted for the &quot;New Source Folder&quot;  type src as the folder name and click OK. Answer yes to the dialog about using a SpringChain/bin  directory as the output directory. Your project should look like this now: <a href="/WhitePapers/SpringChain/images/mkProjectP2.png">figure 2</a>. Click Finished.</p>
<p>Add external jar file references to the project. Right click on the<br />
SpringChain<br />
project in the Java perspective. Click properties. In the dialog for the &quot;Properties for SpringChain &quot;, click the &quot;Java Build Path&quot; item and then the libraries tab. Your screen should look like <a href="/WhitePapers/SpringChain/images/projectSetupP1.png">figure 3</a>. Click the &quot;Add External JARS..: button. Add the following jar from the Commons Chain distribution &quot; commons-chain-1.0.jar&quot; Add the following jar from the Spring Framework distribution, spring.jar. Also add the other jar files mentioned in the prerequisites. Your project properties should look something like <a href="/WhitePapers/SpringChain/images/projectSetupP2.png">figure 4</a>. Click OK.</p>
<h3>Install the sample code<a name="InstallSampleCode" id="InstallSampleCode">:</a></h3>
<p>Download the samples and unzip into the SpringChain project that you created. <a href="/WhitePapers/SpringChain/download/SpringChainSample.zip">Click here to download</a>. Right mouse click on the project and select refresh. </p>
<p>Each sample is contained in it&#8217;s own package. In each package you&#8217;ll see a class called, RunSample. This class has a main entry point to run the the sample. </p>
<p>Hopefully, you now have a project that looks like the one below:</p>
<p>
<img src="/WhitePapers/SpringChain/images/projectLook.png" width="360" height="176" border="1"  alt="Project Look"></p>
</p>
<h3>Sample 1 &#8211; A simple command<a name="Createasimplecommand">:</a></h3>
<p>This sample will show how to create a simple command and execute it after creating it through spring. </p>
<p>First let&#8217;s setup Eclipse to debug our Sample.</p>
<p>Open sample1 package by clicking the plus to the left of the package name. Right mouse click on the RunSample source file. From the context menu that pops up, select &quot;Debug As &#8230;&quot; then select &quot;Debug&quot;. With the &quot;Java Application&quot; item selected in the configurations window, click New. See below:</p>
<p><img src="/WhitePapers/SpringChain/images/sample1Setup.png" width="669" height="581"> </p>
<p>In the dialog that appears next, check the stop in main option.</p>
<p><img src="/WhitePapers/SpringChain/images/sample1Setup2.png" width="500" height="298"></p>
<p>Setup log4j logging. Click the Arguments tab. Add the following line to the VM Arguments. </p>
<p>-Dlog4j.configuration=file:///${project_loc}/log4j.xml</p>
<p>See below. </p>
<p><img src="/WhitePapers/SpringChain/images/sample1Setup3.png" width="495" height="476"></p>
<p>Click debug to step through the sample.</p>
<p>Now back to the sample code. The following files are found in this sample:</p>
<p>HelloWorld &#8211; a class that implements a Command interface. This will be created with the spring framework. </p>
<p>RunSample &#8211; a class that loads the Spring configuration file.</p>
<p>beans.xml &#8211; the Spring configuration file that defines the beans that are going to be created in the sample. </p>
<p>&nbsp;</p>
<p>Beans.xml defines the Command as follows:</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
       &lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot; &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;

       &lt;beans&gt;
 &lt;bean id=&quot;testBean&quot; class=&quot;com.drummondsoftware.sample1.HelloWorld&quot; singleton=&quot;true&quot;&gt;
 &lt;/bean&gt;
&lt;/beans&gt;</pre>
<p>As you can see there&#8217;s nothing complex about creating HelloWorld. Just define the bead id  and the class. </p>
<p>The HelloWorld class is simply going to print the message &quot;Hello World&quot; when the command executes. </p>
<pre>public class HelloWorld implements Command {
 String message = &quot;Hello World&quot;; </pre>
<pre> /* (non-Javadoc)
   * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
   */
   public boolean execute(Context arg0) throws Exception {
   System.out.println(message);
   return true;
   }
 }</pre>
<p>The RunSample class will initialize the spring framework and then pass control the an exec method where the spring factory creates a Commons Command and executes it.</p>
<pre>public class RunSample {
 private XmlBeanFactory factory;

 /**
 * here's where the fun starts
 *
 */
 private void exec() {
   Command cmd = (Command) getFactory().getBean(&quot;testBean&quot;);

   try {
    cmd.execute(null);
   } catch (Exception e) {
    e.printStackTrace();
   }
 }

 public static void main(String[] args) {
   XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource(&quot;src/com/drummondsoftware/sample1/beans.xml&quot;));

   RunSample loadSome = new RunSample();
   loadSome.setFactory(factory);
   loadSome.exec();
 }</pre>
<p>&nbsp;</p>
<h3>Sample 2 &#8211; Chains<a name="Chains" id="Chains">:</a></h3>
<p>This sample will show how to put commands together into chains. The chains also get created from Spring. </p>
<p>Start by setting up Eclipse for debugging this sample just like was done in Sample 1. </p>
<p>&nbsp;</p>
<p>In the Beans.xml we define 4 commands that will be chained together. </p>
<p><img src="/WhitePapers/SpringChain/images/sample2Commands.png" width="604" height="215" border="1"></p>
<p>Command 1 &#8211; 3 are simple commands. They simply log the classname to the logger. </p>
<p>Command 4 is a command that creates another command or chain and runs it. The chainName is set by Spring when the command is created. </p>
<p>Now let&#8217;s examine a chain definition. Lines 14 through 21 of Beans.xml define  test Chain object. This is shown below. </p>
<p><img src="/WhitePapers/SpringChain/images/sample2Chain1.png" width="613" height="146" border="1"></p>
<p>The class in this definition is a Commons Chain class. It&#8217;s the ChainBase class that holds a list of commands to be run. The list is specified in a Spring constructor definition. This simply makes reference to the commands we defined earlier. So when testChain runs it will call command1 followed by command2.</p>
<p>testChain2 &#8211; is similar to testChain. </p>
<p><img src="/WhitePapers/SpringChain/images/sample2Chain2.png" width="618" height="174" border="1"></p>
<p>testChain3 &#8211; runs a command and then runs testChain and testChain2. This shows that chains can be added to a chain. </p>
<p><img src="/WhitePapers/SpringChain/images/sample2Chain3.png" width="605" height="178" border="1"></p>
<p>testChain4 &#8211; runs command4 which is the indirect chain runner. </p>
<p><img src="/WhitePapers/SpringChain/images/sample2Chain4.png" width="606" height="135" border="1"></p>
<p>RunSample shown below simply loads the spring configuration file and run the chains in order:</p>
<p><img src="/WhitePapers/SpringChain/images/sample2RunSample.png" width="604" height="358" border="1"> </p>
<p>&nbsp;</p>
<h3>Sample 3 &#8211; Contexts and datasource<a name="Contexts" id="Contexts">:</a></h3>
<p>This sample will show how to add context class creation to the Spring beans definitions. I also have add a datasource to the mix to show how easy it is to use other Spring objects in your commands. </p>
<p>Start by setting up Eclipse for debugging this sample just like was done in Sample 1. </p>
<p>In the Beans.xml we define the same 4 commands that will be chained together. Command 2 gets a datasource. </p>
<p><img src="/WhitePapers/SpringChain/images/sample3Commands.png" width="658" height="515" border="1"></p>
<p>Two contexts are defined. Both of these are the Common Chain base class implementations. The spring framework loads the context object up with keyword value pairs contained in a Map. </p>
<p><img src="/WhitePapers/SpringChain/images/sample3Contexts.png" width="651" height="393" border="1"> </p>
<p>The Chains defined in the Beans.xml file are unchanged from the last sample.</p>
<p>The RunSample class initializes the Spring factory. It also loads a property file that configures the datasource connection settings. </p>
<p><img src="/WhitePapers/SpringChain/images/sample3RunSample1.png" width="663" height="343" border="1"></p>
<p>Control is passed to the exec method where now the context objects are created and passed into the chains when they are run. </p>
<p><img src="/WhitePapers/SpringChain/images/sample3RunSample2.png" width="575" height="400" border="1"></p>
<p>Step through this sample and watch the trace output. </p>
<p>Hopefully this helps you get a quick start into use of Commons Chains and and Spring framework together. </p>
<table width="100%"  border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="24%"><img src="/images/clearpixel.gif" width="50" height="2"></td>
<td width="19%"><img src="/images/hrlong.gif" width="350" height="1"></td>
<td width="57%">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<div align="center">Table of Contents </div>
</td>
<td>
<div align="center"></div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<ul>
<li><a href="#Goal">Goals</a></li>
<li><a href="#Prerequisites">Prerequisites</a></li>
<li><a href="#Createaprojecttobuildexamples">Create a project to build examples.</a></li>
<li><a href="#InstallSampleCode">Install the sample code.</a> </li>
<li> <a href="#Createasimplecommand">Sample 1 &#8211; A simple command</a>.</li>
<li><a href="#Chains">Sample 2 &#8211; Chains.</a></li>
<li><a href="#Contexts">Sample 3 &#8211; Contexts and datasource.</a></li>
</ul>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><img src="/images/hrlong.gif" width="350" height="1"></td>
<td>&nbsp;</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://drummondsoftware.com/blog/2009/03/03/how-to-merge-spring-framework-and-commons-chain-chain-of-responsibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.271 seconds -->

