<?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; downloads</title>
	<atom:link href="http://drummondsoftware.com/blog/index.php/tag/downloads/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>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>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.319 seconds -->

