<?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>Shaaf's Blog &#187; Software</title>
	<atom:link href="http://www.shaafshah.com/tag/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaafshah.com</link>
	<description>Another bit in the wall</description>
	<lastBuildDate>Wed, 12 Aug 2009 14:28:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Automation with Selenium,Junit, Ant</title>
		<link>http://www.shaafshah.com/2009/01/19/automation-with-seleniumjunit-ant/</link>
		<comments>http://www.shaafshah.com/2009/01/19/automation-with-seleniumjunit-ant/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 14:31:52 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[automated-testing]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[continous]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[Junit]]></category>
		<category><![CDATA[scm]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=159</guid>
		<description><![CDATA[What is Selenium How does Selenium work History and how it started About Ant And Junit Much of the technologies above do not or will not need an introduction if you already know them or can read them from the links above. More over today&#8217;s article is more about how we can use all the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://seleniumhq.org/">What is Selenium</a><br />
<a href="http://seleniumhq.org/about/how.html">How does Selenium work</a><br />
<a href="http://seleniumhq.org/about/history.html">History and how it started</a><br />
<a href="http://ant.apache.org/">About Ant</a><br />
<a href="http://www.junit.org/">And Junit</a></p>
<p>Much of the technologies above do not or will not need an introduction if you already know them or can read them from the links above.</p>
<p>More over today&#8217;s article is more about how we can use all the three selenium, ant and junit to come up with an automated solution for regressive testing.</p>
<p>Please refer to the documentation links above for the basic knowledge on any of the used tools.</p>
<p>I am assuming that you know how to record a test in selenium if you dont then go <a href="http://selenium-ide.seleniumhq.org/">here</a></p>
<p>Now that you do know how to record and save the tests simply save them in any directory structure you like as long as they follow the right package convention. like com.foo.bar<br />
this would mean the file should be in directory like com/foo/bar. Conventionally and logically today that is how the TestCase is compiled through the ant script. If the package is not the right path then compile time errors will occur.</p>
<p>My calling target for running the whole procedure should look like this</p>
<pre>
< target name="build_tests" depends="clean, compile, start-server,  tests, stop-server" / >
</pre>
<p>Details of the depending targets are as follows.<br />
<strong>clean:</strong> would clean the entire build directories etc to make sure nothing from our past is carried forward into the future.</p>
<p><strong>compile:</strong> should compile</p>
<p><strong>start-server:</strong> should start the selenium server.</p>
<p><strong>tests:</strong> should run the selenium tests.</p>
<p><strong>stop-server:</strong> should stop the selenium server once all tests have been executed.</p>
<p><strong>How to start a selenium server from Ant?</strong></p>
<pre>
    < target name="start-server" >
        < java jar="lib/selenium-server.jar" fork="true" spawn="true" >
            < arg line="-timeout 30" / >
            < jvmarg value="-Dhttp.proxyHost=proxy.proxyhost.com" / >
            < jvmarg value="-Dhttp.proxyPort=44444" / >
        < / java >
    < / target >
</pre>
<p> </p>
<p>The target above is simply taking the selenium-server.jar which is in the classpath and running the main-class from it. the proxy parameters are optional.</p>
<p><strong>How to stop the server from Ant?</strong></p>
<pre>
 < target name="stop-server" >
        < get taskname="selenium-shutdown"
            src="http://localhost:4444/selenium-server/driver/?cmd=shutDown"
            dest="result.txt" ignoreerrors="true" / >
        < echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" / >
    < / target >
 </pre>
<p>The selenium server starts on port 4444 by default and to tell it to shutdown is simple, the command in the src is passed to it. cmd=shutDown<br />
That should just shutdown the server.</p>
<p><strong>Executing the test cases?</strong><br />
Selenium Test cases are Junit tests cases and that&#8217;s how they are treated in this tutorial.<br />
Thus some of you will be very much familiar with the ant targets <a href="http://ant.apache.org/manual/OptionalTasks/junit.html">junit</a> and <a href="http://ant.apache.org/manual/OptionalTasks/junitreport.html">junitreport</a>. However I will describe how the following is working.<br />
the following target will run the selenium tests and print a summary report to the ${dir}<br />
The includes and excludes, simply tell the target which files to include or exclude while running the test cases. This is typically done when you don&#8217;t want some tests cases to be included or your source for tests and the application are in the same directory and you only want to include something like Test*.class. </p>
<pre>
  < target name="tests" depends="compileonly" description="runs JUnit tests" >
    < echo message="running JUnit tests" / >
    < junit printsummary="on" dir=".." haltonfailure="off" haltonerror="off" timeout="${junit.timeout}" fork="on" maxmemory="512m" showoutput="true" >
      < formatter type="plain" usefile="false" / >
      < formatter type="xml" usefile="true" / >
      < batchtest todir="${testoutput}" filtertrace="on" >
        < fileset dir="${src}" >
          < includesfile name="${tests.include}" / >
          < excludesfile name="${tests.exclude}" / >
        < / fileset >
      < / batchtest >
      < classpath >
        < pathelement path="${classes}" / >
        < pathelement path="${build.classpath}" / >
      < / classpath >
    < / junit >
</pre>
<p>The following will take the formatted output from the lines above and generate a report out of it in xml and html and place the results in the ${reports}/index.html<br />
A sample Junit test report might look like <a href="http://studios.thoughtworks.com/cruise-continuous-integration/1.0/help/resources/images/cruise/tab-with-junit.png">this</a>.</p>
<pre>
   < echo message="running JUnit Reports" / >
   < junitreport todir="${reports}" >
      < fileset dir="${reportdir}" >
        < include name="Test*.xml" / >
      < / fileset >
      < report format="frames" todir="${reports}" / >
    < / junitreport >
    < echo message="To see your Junit results, please open ${reports}/index.html}" / >
  < / target >
</pre>
<p>In general you can add all of this to your nightly build through any of the CI servers like Cruise Control. Also as a general practice you will need to do a  little more then just executing this target every night depending on your application. For instance cleaning up of resource centers like Databases etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2009/01/19/automation-with-seleniumjunit-ant/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Generate XML &#8211; DBMS_XMLGEN</title>
		<link>http://www.shaafshah.com/2008/12/10/generate-xml-dbms_xmlgen/</link>
		<comments>http://www.shaafshah.com/2008/12/10/generate-xml-dbms_xmlgen/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 14:58:04 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[DBMS_XMLGEN]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[utils]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=137</guid>
		<description><![CDATA[On my way to my solution store just found this nice to use, old and easy feature. Possibilities endless, usage typically very easy. I used the following to generate XML from sqlplus: select dbms_xmlgen.getxml('select * from user') from dual; Output: < ROWSET > < ROW > < TNAME >Employee< / TNAME > < TABTYPE > [...]]]></description>
			<content:encoded><![CDATA[<p>On my way to my solution store just found this nice to use, old and easy feature.<br />
Possibilities endless, usage typically very easy.</p>
<p>I used the following to generate XML from sqlplus:</p>
<pre lang="SQL" line=1> select dbms_xmlgen.getxml('select * from user') from dual; </pre>
<p><strong>Output:</strong></p>
<pre lang="XML" line=1>
< ROWSET >
 < ROW >
  < TNAME >Employee< / TNAME >
  < TABTYPE > TABLE < / TABTYPE >
 < / ROW >
< / ROWSET >
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/12/10/generate-xml-dbms_xmlgen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command, Singleton, JMenuItem, JButton, AbstractButton &#8211; One Listener for the app</title>
		<link>http://www.shaafshah.com/2008/11/17/command-singleton-jmenuitem-jbutton-abstractbutton-one-listener-for-the-app/</link>
		<comments>http://www.shaafshah.com/2008/11/17/command-singleton-jmenuitem-jbutton-abstractbutton-one-listener-for-the-app/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 19:17:24 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[AbstractButton]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[GOF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JButton]]></category>
		<category><![CDATA[JMenuItem]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Singleton]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=124</guid>
		<description><![CDATA[Here I would like to demonstrate a simple use of JMenuItems being used with Single Listener for the entire system. A simple sample of use would probably be SingleInstance Desktop Application. Lets see how that is done here. 1. First lets create a OneListener class that should be able to listen to ActionEvents and also [...]]]></description>
			<content:encoded><![CDATA[<p>Here I would like to demonstrate a simple use of JMenuItems being used with Single Listener for the entire system.<br />
A simple sample of use would probably be SingleInstance Desktop Application.</p>
<p>Lets see how that is done here.</p>
<p>1. First lets create a OneListener class that should be able to listen to ActionEvents and also be able to add Commands to itself. Please refer to my previous post on Command,Singleton if you would like to see more about this patterns and there usage.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.shaafshah.jmenus</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.ActionEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.ActionListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.AbstractButton</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Implements the ActionListener and is a Singleton also.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> OneListener <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">ActionListener</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> OneListener oneListener <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Holds the list of all commands registered to this listener</span>
	<span style="color: #000000; font-weight: bold;">private</span> ArrayList<span style="color: #339933;">&lt;</span>Command<span style="color: #339933;">&gt;</span> commandList <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// A private constructor</span>
	<span style="color: #000000; font-weight: bold;">private</span> OneListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		commandList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Command<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Ensuring one instance.</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> OneListener getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>oneListener <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>	
			<span style="color: #000000; font-weight: bold;">return</span> oneListener<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">return</span> oneListener <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OneListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Add the command and add myself as the listener</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addCommand<span style="color: #009900;">&#40;</span>Command command<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			commandList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>command<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">AbstractButton</span><span style="color: #009900;">&#41;</span>command<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #666666; font-style: italic;">// All Events hit here.</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actionPerformed<span style="color: #009900;">&#40;</span><span style="color: #003399;">ActionEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Command<span style="color: #009900;">&#41;</span>e.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the above code, the addCommand method adds the command Object and adds a listener to it.<br />
Now how is that possible.<br />
Basically because I am categorizing my UI objects as Commands with in the system having some UI. And I am also assuming that these commands are Currently AbstractButton i.e. JMenuItem, JButton. Lets have a look at the Command Interface and its Implementation.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Command <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And the implementation, note that the Command is an interface where as the class is still extending a UI object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JMenuItem</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestCmd <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">JMenuItem</span> <span style="color: #000000; font-weight: bold;">implements</span> Command<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> TestCmd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		OneListener.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HelloWorld&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Personally don&#8217;t like calling the OneListener in the constructor of the class but just for the sake of simplicity of this post I have left it that way. There are many different ways to omit it.</p>
<p>So the TestCmd is a JMenuItem but is also a Command and thats what the OneListener understands.<br />
As this commads Listener is also OneListener all ActionEvents are thrown there and from there only the Command.execute is called on.</p>
<p>So now you dont have to worry about what listeners are you in. The only thing you know is that when execute is called you need to do your stuff.</p>
<p>You can download the code from <a href='http://www.shaafshah.com/wp-content/uploads/2008/11/jmenus.zip'>Here</a>.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/11/17/command-singleton-jmenuitem-jbutton-abstractbutton-one-listener-for-the-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Continous Integration &#8211; A blast from the past</title>
		<link>http://www.shaafshah.com/2008/11/12/continous-integration-a-blast-from-the-past/</link>
		<comments>http://www.shaafshah.com/2008/11/12/continous-integration-a-blast-from-the-past/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 18:00:16 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[continous]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[scm]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=117</guid>
		<description><![CDATA[Although this didn&#8217;t happen a decade ago but still has been a good case for me to learn and realize how Continuous Integration brings value addition to our work. As I recall it was like this when they were teenagers Few teams working on different modules of same application, deployed together. No build process formalized [...]]]></description>
			<content:encoded><![CDATA[<p>Although this didn&#8217;t happen a decade ago but still has been a good case for me to learn and realize how Continuous Integration brings value addition to our work.</p>
<p>As I recall it was like this when they were teenagers <img src='http://www.shaafshah.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
Few teams working on different modules of same application, deployed together.<br />
No build process formalized<br />
No builds except for the ones that need major milestone deployments.<br />
No feedback, reports, reviews etc.</p>
<p>So virtually there was no build eco system.</p>
<p>Which meant hideous amounts of communication, tons of trouble shooting, last minute show stoppers, And extermely unhappy end users/stake holders.</p>
<p>So what exactly was going wrong.</p>
<p>There was no Configuration Control i.e. No way to figure out the changes that will be part of the release and no controls to include or exclude them.<br />
No Status accounting i.e. No feedback or status of anything as a whole product.<br />
No management of Environment meant no one knew what hardware/software they were using and sometimes why?<br />
No team work whatsoever meant no guided processes, reviews or tracebility of issues and pitfalls.</p>
<p>So virtually a release day was the doomsday!</p>
<p>It took some time for developers to realize that how important the following were.<br />
    * Configuration identification &#8211; What code are we working with?<br />
    * Configuration control &#8211; Controlling the release of a product and its changes.<br />
    * Status accounting &#8211; Recording and reporting the status of components.<br />
    * Review &#8211; Ensuring completeness and consistency among components.<br />
    * Build management &#8211; Managing the process and tools used for builds.<br />
    * Process management &#8211; Ensuring adherence to the organization&#8217;s development process.<br />
    * Environment management &#8211; Managing the software and hardware that host our system.<br />
    * Teamwork &#8211; Facilitate team interactions related to the process.<br />
    * Defect tracking &#8211; Making sure every defect has traceability back to the source</p>
<p>And after all it takes some time but the day to day flow looked like the figure below.</p>
<div id="attachment_118" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.shaafshah.com/wp-content/uploads/2008/11/build.png"><img src="http://www.shaafshah.com/wp-content/uploads/2008/11/build-300x221.png" alt="Build Management" title="Continous Integration" width="300" height="221" class="size-medium wp-image-118" /></a><p class="wp-caption-text">Build Management</p></div>
<p>Importantly<br />
Developers are distributed on different locations in different teams.<br />
There is an SCM team that takes care of the SCM activities i.e. Configuration Identification, Control, Build Management etc.<br />
There is one single repository for all developers.<br />
A process is defined for Product integration and its checked whenever some one checks in.<br />
And hourly build is dont to check the sanity of the system with the unit tests.<br />
A Nightly build is done with all full blown unit tests, coverage reports, Automated tests and installers and upgrades.<br />
More over all of the above is shown on an FTP/HTTP site. FTP for installer/binary/archive pickup and HTTP for detailed view of builds/feedbacks etc.</p>
<p>All of the above meant strength and health of the build eco system. And more trust in the system that it will report failures along the way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/11/12/continous-integration-a-blast-from-the-past/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing the Locale &#8211; Danmark</title>
		<link>http://www.shaafshah.com/2008/11/12/doing-the-locale-danmark/</link>
		<comments>http://www.shaafshah.com/2008/11/12/doing-the-locale-danmark/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 12:52:08 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[locale]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[utils]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=110</guid>
		<description><![CDATA[The following illustrates how to get the Number format working with a danish locale. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import java.text.NumberFormat; import java.util.Currency; import java.util.Locale; &#160; &#160; public class TestLocale &#123; &#160; public static void main&#40;String [...]]]></description>
			<content:encoded><![CDATA[<p>The following illustrates how to get the Number format working with a danish locale.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.NumberFormat</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Currency</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Locale</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestLocale <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">// Create a Locale for Danmark</span>
 <span style="color: #003399;">Locale</span> DANMARK <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Locale</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;da&quot;</span>,<span style="color: #0000ff;">&quot;DK&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// get the currency instance for this locale.</span>
 Currency krone <span style="color: #339933;">=</span> Currency.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>DANMARK<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">// Get a Number format for the locale.</span>
 <span style="color: #003399;">NumberFormat</span> krFormat <span style="color: #339933;">=</span> <span style="color: #003399;">NumberFormat</span>.<span style="color: #006633;">getCurrencyInstance</span><span style="color: #009900;">&#40;</span>DANMARK<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">// A symbol for the currency</span>
 <span style="color: #003399;">String</span> symbol <span style="color: #339933;">=</span> krFormat.<span style="color: #006633;">getCurrency</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSymbol</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">// A double amount</span>
 <span style="color: #000066; font-weight: bold;">double</span> amount <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10000.25</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// print it out after formatting.</span>
 <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>krFormat.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>amount<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/11/12/doing-the-locale-danmark/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>That thing about CI &#8211; Continous Integration</title>
		<link>http://www.shaafshah.com/2008/11/12/that-thing-about-ci-continous-integration/</link>
		<comments>http://www.shaafshah.com/2008/11/12/that-thing-about-ci-continous-integration/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 12:11:18 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[continous]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=13</guid>
		<description><![CDATA[Challenging Business requirements and the need for software development teams to remain agile and competitive while managing parallel development and releases requires a system which is adaptive to these demands. Our approach to SCM enables unlimited and adaptable process models, which are ideally suited for parallel, distributed, and agile software development. Using state of the [...]]]></description>
			<content:encoded><![CDATA[<p>Challenging Business requirements and the need for software development teams to remain agile and competitive while managing parallel development and releases requires a system which is adaptive to these demands.</p>
<p>Our approach to SCM enables unlimited and adaptable process models, which are ideally suited for parallel, distributed, and agile software development. Using state of the Art technologies from various vendors to automate processes such as branching, merging, build, and release keeps you a click away from software delivery.</p>
<p>The real matter then is the sanity of your application and that&#8217;s the challenge we all need to address. We can have cute products right of the shelf to get it up and going but the whole challenge lies in the statement &#8220;up and going&#8221;. It takes a ton of energy and effort to come up with the right process and the right tool. I have not seen alot of CI projects failing strictly. But I do have seen extra efforts into things that should not be really there. failure would then mean the amounts of efforts spent on doing not so trivial stuff and on the other end if you are spending alot of time doing the major flows then definately something is wrong.</p>
<p>Automation does solve most parts of the problems but things that really need to be taken care of to get it right in the sweet spot are the ones Martin Fowler described in one of his articles.</p>
<p>* <strong>Maintain a Single Source Repository</strong><br />
Keep everyone together, at the end of the day we all work together dont we?</p>
<p>* <strong>Automate the Build</strong><br />
Automation of the build helps you.</p>
<p>* <strong>Make Your Build Self-Testing</strong><br />
<strong></strong>Self testing build tells you exactly what you did and what you broke. So I can come up with this statement to my Lead. &#8220;If I commit this, it might break alot of stuff&#8221;. Well Sir, try running the Unit Test, You will know for sure! But then again honesty on the test cases really doest matter!</p>
<p>* <strong>Everyone Commits Every Day</strong><br />
Typically in a Agile environment helps alot, and forces you not to break the build. Better organization I must say.</p>
<p>* <strong>Every Commit Should Build the Mainline on an Integration Machine</strong><br />
Sanity checking of your commits. So often we commit without realiazing that we break something else.</p>
<p>* <strong>Keep the Build Fast</strong><br />
I usually commit before leaving for home. It helps great deal when you get the feedback within 5 mins. kind of a benchmark but depends.</p>
<p>* <strong>Make it Easy for Anyone to Get the Latest Executable</strong><br />
Keep all the build results and one sharable place. We did that on one of the http servers some time back</p>
<p>* <strong>Everyone can see what&#8217;s happening</strong><br />
Importantly that all results are published for all of us to know.</p>
<p>* <strong>Automate Deployment</strong><br />
Deployment automation means that my buddy X on the other side doesnt screw up the server for even a 1 min. Only deploys when build successfull.</p>
<p>Hope this helps.</p>
<p><strong>Resources:</strong></p>
<p><a title="http://martinfowler.com/articles/continuousIntegration.html" href="http://martinfowler.com/articles/continuousIntegration.html">http://martinfowler.com/articles/continuousIntegration.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/11/12/that-thing-about-ci-continous-integration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to read a file from the JAR?</title>
		<link>http://www.shaafshah.com/2008/10/31/how-to-read-a-file-from-the-jar/</link>
		<comments>http://www.shaafshah.com/2008/10/31/how-to-read-a-file-from-the-jar/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 18:57:54 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[utils]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=103</guid>
		<description><![CDATA[Someone just asked me this question today. And I thought might as well put it down for info. 1 2 3 4 public TestReadFileFromJar&#40;&#41; throws FileNotFoundException, IOException &#123; InputStream is = getClass&#40;&#41;.getResource&#40;&#34;txtData/states.properties&#34;&#41;; read&#40;is&#41;; &#125; In the case above txtData is placed in the jar on the root. Remmember to add the path with the /]]></description>
			<content:encoded><![CDATA[<p>Someone just asked me this question today. And I thought might as well put it down for info.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> TestReadFileFromJar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">FileNotFoundException</span>, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">InputStream</span> is <span style="color: #339933;">=</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;txtData/states.properties&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        read<span style="color: #009900;">&#40;</span>is<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the case above txtData is placed in the jar on the root. Remmember to add the path with the /</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/10/31/how-to-read-a-file-from-the-jar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Command</title>
		<link>http://www.shaafshah.com/2008/10/31/command/</link>
		<comments>http://www.shaafshah.com/2008/10/31/command/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 18:45:04 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[GOF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=14</guid>
		<description><![CDATA[By using the command pattern you are seperating the operation from the invoking object. And just because of that it becomes easier to change the command without chagning the caller/s. This means that you could use Command pattern when you might have the following situation You want to parameterize objects to perform an action You [...]]]></description>
			<content:encoded><![CDATA[<p>By using the command pattern you are seperating the operation from the invoking object. And just because of that it becomes easier to change the command without chagning the caller/s.<br />
This means that you could use Command pattern when you might have the following situation</p>
<p>You want to parameterize objects to perform an action<br />
You want to specify, execute and queue requests at different times.</p>
<p>Just to quickly start you need a command object, An interface will keep it easy going in this case, thus providing you with the option of extending other classes e.g. Swing MenuItem or Button.<br />
Below the execute Method is the one invoked to do something when this command is called or asked to do its stuff.<br />
Where as the getCommandName is assumed as a unique name how ever I am sure we can always come up with a better implementation for uniqueness.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Command <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCommandName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And example implementation of the Command should look as follows<br />
A Command Name, and and execute Method to tell what happens when this command is called.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ForwardCmd <span style="color: #000000; font-weight: bold;">implements</span> Command <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> COMMAND_NAME <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Back&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> BackCmd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCommandName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">return</span> COMMAND_NAME<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Your wish, my command&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The command manager is the controller in this case. It registers command objects. the &#8220;registerCommand&#8221; will simply take a command and store it in a list or something alike. This means you could load it out of a jar file, or an xml or path and just pass the object to the &#8220;registerCommand&#8221; AS a command offcourse.</p>
<p>the &#8220;execute&#8221; Command will simply execute the Command passed to it. </p>
<p>And the &#8220;getCommand&#8221; returns a command by looking up a COMMAND_NAME. So if you provide a name to it through you system it should give you an object of type Command and simple pass it to execute. Again this would be a controller logic and not the client one.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractCommandManager <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> registerCommand<span style="color: #009900;">&#40;</span>Command command<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">Collection</span> getAllCommands<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span>Command command<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> Command getCommand<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/10/31/command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing the adapter</title>
		<link>http://www.shaafshah.com/2008/10/29/implementing-the-adapter/</link>
		<comments>http://www.shaafshah.com/2008/10/29/implementing-the-adapter/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 18:47:56 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[adapter pattern]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[GOF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=94</guid>
		<description><![CDATA[Typically when implementing an interface you would have to implement all the methods that exist in that interface. A very good example is the MouseListener in the java Swing. When you need to implement more then one method where as typically you might be catching only one of them. Saying that you would also find [...]]]></description>
			<content:encoded><![CDATA[<p>Typically when implementing an interface you would have to implement all the methods that exist in that interface.  A very good example is the MouseListener in the java Swing. When you need to implement more then one method where as typically you might be catching only one of them.  Saying that you would also find a Mouse Adapter provided as well. Some of us use that often. And that is part of the Adapter pattern. It makes life easier for me sometimes.</p>
<p>Adapter a structural pattern will let you adapt to a different environment. The joining between different environment is called Adapter. Thus basically giving others the interface that they expect or vice versa when your program becomes the client.</p>
<p>For example the following class expects that the implementing class should be implementing all three methods.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> RecordListener <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPrePerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPostPerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So lets say our implementing class is a rude one and only wants to implement one method. What do you do as an API designer. hmmm</p>
<p>Thats where we step in with the Adapter.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> RecordAdapter <span style="color: #000000; font-weight: bold;">implements</span> RecordListener <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPrePerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPostPerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> MyAdapterImpl <span style="color: #000000; font-weight: bold;">extends</span> RecordAdapter<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> eventPerformed<span style="color: #009900;">&#40;</span>RecordEvent recordEvent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now the only thing left to do is use the adapter. And override any method that you might need .</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> MyClientClass <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> MyClientClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">addRecordListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MyAdapterImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/10/29/implementing-the-adapter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Abstract Factory pattern</title>
		<link>http://www.shaafshah.com/2008/10/10/abstract-factory-pattern/</link>
		<comments>http://www.shaafshah.com/2008/10/10/abstract-factory-pattern/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 08:20:10 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[GOF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Singleton]]></category>
		<category><![CDATA[Singleton Pattern]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=76</guid>
		<description><![CDATA[Factories have been a key pattern in building applications, its fascinatingly simple, effective and to the point. When starting to learn a design oriented approach to applications or API, I would always recommend a factory pattern as one of the key starting notes of highlight in your design. So today I am talking about the Abstract Factory [...]]]></description>
			<content:encoded><![CDATA[<p>Factories have been a key pattern in building applications, its fascinatingly simple, effective and to the point. When starting to learn a design oriented approach to applications or API, I would always recommend a factory pattern as one of the key starting notes of highlight in your design.</p>
<p>So today I am talking about the Abstract Factory pattern. Its not an &#8220;abstract&#8221; class or object that you call a pattern. But its a Factory of facotries and that is what exactly makes it so much wordingly abstract. Having &#8220;abstract&#8221; classes is there but just some other side of the coin.</p>
<p><strong>When should I use an Abstract Factory:</strong></p>
<ul>
<li>Independence of how products are created, composed or represented</li>
<li>Should be configurable with one of the multiple families or products</li>
<li>You need enforcable constraints for the products used as a group</li>
<li>You need to reveal only the interfaces of products and not thier implementation as part of a bigger picture.</li>
</ul>
<p>So lets begin with the fun.</p>
<p><strong>This is how I plan to implement it:</strong><br />
Has A:<br />
Product has a Specification<br />
Factory has a Product<br />
FactoryManager has FactoryConstants<br />
FactoryManager has ComputerFactory</p>
<p>Is A:<br />
BFactory is a ComputerFactory<br />
AFactory is a ComputerFactory</p>
<p>Not shown.<br />
ProductA is a Product<br />
ProductB is a Product</p>
<p>Diagram:<br />
<div id="attachment_84" class="wp-caption alignnone" style="width: 310px"><a href="http://www.shaafshah.com/wp-content/uploads/2008/10/abstractfactory.jpeg"><img src="http://www.shaafshah.com/wp-content/uploads/2008/10/abstractfactory-300x180.jpg" alt="AbstractFactory" title="AbstractFactory" width="300" height="180" class="size-medium wp-image-84" /></a><p class="wp-caption-text">AbstractFactory</p></div></p>
<p>Creating a simple factory that returns products.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> ComputerFactory <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> Product<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getProducts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> Product getProduct<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> ProductID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Implementation of the ComputerFactory</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AFactory <span style="color: #000000; font-weight: bold;">extends</span> ComputerFactory <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;A&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> Product<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> getProducts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> Product getProduct<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> productID<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>productID<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ProductA<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ProductB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sorry you hit the wrong factory, we closed down in 1600 BC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A register base for factories. Refer to the main method for use later in this post.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> FactoryConstants <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> A <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> B <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The main Entrant class. the Factory Manager that will give the ComputerFactory resultant. Its assumed to be a Singleton as it registers as a Creator in the system (assumption).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FactoryManager<span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> FactoryManager factoryManager <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> FactoryManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> FactoryManager getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>factoryManager <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">return</span> factoryManager<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">return</span> factoryManager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FactoryManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> ComputerFactory getFactory<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> factory<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>factory<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">case</span> FactoryConstants.<span style="color: #006633;">A</span><span style="color: #339933;">:</span>
   <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> IBMFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">case</span> FactoryConstants.<span style="color: #006633;">B</span><span style="color: #339933;">:</span>
   <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> SUNFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
   <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sorry you hit the wrong factory, we closed down in 1600 BC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A main method to test the AbstractFactory</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>FactoryManager.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFactory</span><span style="color: #009900;">&#40;</span>FactoryConstants.<span style="color: #006633;">A</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>FactoryManager.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFactory</span><span style="color: #009900;">&#40;</span>FactoryConstants.<span style="color: #006633;">B</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>FactoryManager.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFactory</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You can find the complete code listing here:<br />
<a href='http://www.shaafshah.com/wp-content/uploads/2008/10/abstractfactory.zip'>AbstractFactory source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/10/10/abstract-factory-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
