<?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; HOWTO</title>
	<atom:link href="http://www.shaafshah.com/tag/howto/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>Calling wsadmin scripts from ant</title>
		<link>http://www.shaafshah.com/2008/12/11/calling-wsadmin-scripts-from-ant/</link>
		<comments>http://www.shaafshah.com/2008/12/11/calling-wsadmin-scripts-from-ant/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 08:17:46 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Administrator]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[IBM]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[jython]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[websphere]]></category>
		<category><![CDATA[wsadmin]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=148</guid>
		<description><![CDATA[You can simply add the following to a target. For the following wsadmin should be in your PATH env. < exec dir="." executable="wsadmin.bat" logError="true" failonerror="true" output="wsconfig.out" > < arg line="-lang jython -f ../../createQFactory.py"/ > < /exec > All output will be logged to wsconfig.out]]></description>
			<content:encoded><![CDATA[<p>You can simply add the following to a target.<br />
For the following wsadmin should be in your PATH env.</p>
<p>< exec dir="." executable="wsadmin.bat" logError="true" failonerror="true" output="wsconfig.out" ><br />
   < arg line="-lang jython -f ../../createQFactory.py"/ ><br />
< /exec ></p>
<p>All output will be logged to wsconfig.out</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/12/11/calling-wsadmin-scripts-from-ant/feed/</wfw:commentRss>
		<slash:comments>1</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>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>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>wasprofile -create -delete</title>
		<link>http://www.shaafshah.com/2008/10/24/wasprofile-create-delete/</link>
		<comments>http://www.shaafshah.com/2008/10/24/wasprofile-create-delete/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 11:38:00 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Administrator]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[IBM]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[jython]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[wasprofile]]></category>
		<category><![CDATA[websphere]]></category>
		<category><![CDATA[wsadmin]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=91</guid>
		<description><![CDATA[Sometimes you require to do things silently, without any questions asked and &#8220;Just Do It&#8221; attitude is required. I often find my self with this problem. If you want to delete or create a Websphere profile from your command line try the following. (I have tried on RSA only) # deleteing a profile wasprofile -delete [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you require to do things silently, without any questions asked and &#8220;Just Do It&#8221; attitude is required.</p>
<p>I often find my self with this problem.</p>
<p>If you want to delete or create a Websphere profile from your command line try the following. (I have tried on RSA only)</p>
<p># deleteing a profile<br />
<strong>wasprofile </strong>-delete -profileName MyProfile</p>
<p>You should get the following message on deletion</p>
<p><strong>INSTCONFSUCCESS: Success: The profile no longer exists.</strong></p>
<p>Creating a websphere profile</p>
<p><strong>wasprofile </strong>-create -profileName MyProfile -profilePath \<br />
[PROFILE PATH] -templatePath \<br />
[RSA HOME]runtimes\base_v6\profileTemplates\default \<br />
-nodeName [NODE NAME] -cellName [CELL NAME] -hostName [HOSTNAME].</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/10/24/wasprofile-create-delete/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>
		<item>
		<title>SVN &#8211; some quick commands during merge.</title>
		<link>http://www.shaafshah.com/2008/08/25/svn-some-quick-commands-during-merge/</link>
		<comments>http://www.shaafshah.com/2008/08/25/svn-some-quick-commands-during-merge/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 13:55:54 +0000</pubDate>
		<dc:creator>Shaaf Shah</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://www.shaafshah.com/?p=36</guid>
		<description><![CDATA[Following are some of the frequently used svn commands during merging and branching. I used to work with tortoise for this but as soon as I learned these, it feels like a more easier space to be in. Although no points taken away from tortoise, it still works pretty good for the gui part, This [...]]]></description>
			<content:encoded><![CDATA[<p>Following are some of the frequently used svn commands during merging and branching. I used to work with tortoise for this but as soon as I learned these, it feels like a more easier space to be in. Although no points taken away from tortoise, it still works pretty good for the gui part, This article is more  targeted towards dark screen lovers.</p>
<p><strong>Create a new branch from trunk:</strong><br />
If you want to create a branch from a specific revision of Trunk following command is handy. It does a remote copy. which means the machine you are on does not need a copy of the whole tree.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> copy <span style="color: #660033;">-r</span> REVISION TRUNK_URL NEW_BRANCH_URL <span style="color: #660033;">--username</span> USERNAME <span style="color: #660033;">--password</span> PASSWORD <span style="color: #660033;">-m</span> MESSAGE</pre></div></div>

<p>An example</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> copy <span style="color: #660033;">-r</span> <span style="color: #000000;">1234</span> http:<span style="color: #000000; font-weight: bold;">//</span>shaafshah.com<span style="color: #000000; font-weight: bold;">/</span>trunk http:<span style="color: #000000; font-weight: bold;">//</span>shaafshah.com<span style="color: #000000; font-weight: bold;">/</span>branches<span style="color: #000000; font-weight: bold;">/</span>MY_BRANCH <span style="color: #660033;">--username</span> foo <span style="color: #660033;">--password</span> bar <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Remote copy&quot;</span></pre></div></div>

<p><strong>When was this branch created?</strong><br />
If you want to know the day branch was created.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> log <span style="color: #660033;">-v</span> <span style="color: #660033;">--stop-on-copy</span> BRANCH_URL</pre></div></div>

<p>The last record will show you the day the branch as created.</p>
<p><strong>List all the branches:</strong><br />
If you want to take a listing of branches or a tree</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> BRANCHES_URL</pre></div></div>

<p>e.g. http://shaafshah.com/branches</p>
<p><strong>Merge from Branch to Trunk:</strong></p>
<p>Browse to where you have checkedout trunk in the local directory.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> shaafshah.com<span style="color: #000000; font-weight: bold;">/</span>trunk</pre></div></div>

<p>Update trunk to HEAD.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> update
At revision 1234.</pre></div></div>

<p>Following will merge from branch to trunk but will not commit.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> merge <span style="color: #660033;">-r</span> BRANCH_REVISION:TRUNK_REVISION BRANCH_URL</pre></div></div>

<p>Branch_REVISION will be the revision branch was created if this is the first time you are doing the merge.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> merge <span style="color: #660033;">-r</span> <span style="color: #000000;">1233</span>:<span style="color: #000000;">1234</span> http:<span style="color: #000000; font-weight: bold;">//</span>shaafshah.com<span style="color: #000000; font-weight: bold;">/</span>branches<span style="color: #000000; font-weight: bold;">/</span>my_new_branch</pre></div></div>

<p>After this you should do an</p>
<p>svn status</p>
<p>to check the status of the files. the files will be marked with following Characters.</p>
<p>&#8216;A&#8217; Added<br />
&#8216;C&#8217; Conflicted<br />
&#8216;D&#8217; Deleted<br />
&#8216;I&#8217; Ignored<br />
&#8216;M&#8217; Modified</p>
<p>If there is any &#8216;C&#8217; in the status the files will not be committed if you try an svn commit to save the merge to the trunk.</p>
<p><strong>Merge from Trunk to Branch:</strong></p>
<p>To merge from Trunk to branch you would need to browse to the branch checked out in the local direcotry.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> shaafshah.com<span style="color: #000000; font-weight: bold;">/</span>branches<span style="color: #000000; font-weight: bold;">/</span>mybranch</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> update
At revision 1234.</pre></div></div>

<p>The following command will try merging trunk from revision 1233 i.e. the day branch was created to branch head.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">svn</span> merge <span style="color: #660033;">-r</span> <span style="color: #000000;">1233</span>:HEAD TrunkURL BRANCH_URL</pre></div></div>

<p>Hopefully this should help. However you should definitely refer to SVN Book for more detail.</p>
<p>svnbook at <a title="http://svnbook.red-bean.com/" href="http://svnbook.red-bean.com/">http://svnbook.red-bean.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaafshah.com/2008/08/25/svn-some-quick-commands-during-merge/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
