<?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>Vinothbabu's Desk!</title>
	<atom:link href="http://vinothbabu.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://vinothbabu.com</link>
	<description>When Smart is Dumb</description>
	<lastBuildDate>Fri, 16 Jul 2010 10:14:41 +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>Singletons in Java</title>
		<link>http://vinothbabu.com/2010/07/16/singletons-in-java/</link>
		<comments>http://vinothbabu.com/2010/07/16/singletons-in-java/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 10:14:41 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[JAVA/J2EE]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=306</guid>
		<description><![CDATA[Singletons are the design pattern when you want only one instance of a class created. You make the constructor private, and give access to the instantiated object via a static instance method that creates the object if it has not been created already. The singleton class is threadsafe lazy instantiation. I hope many would be [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/306.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<div><span style="font-size: x-small;">Singletons are the design pattern when you want only one instance of a class created. You make the constructor private, and give access to the instantiated object via a static <em>instance</em> method that creates the object if it has not been created already.<span id="more-306"></span></span></div>
<p><span style="font-size: x-small;">The singleton class is threadsafe lazy instantiation. I hope many would be knowing on lazy instantiation. With lazy instantiation, a program refrains from creating certain resources until the resource is first needed &#8212; freeing valuable memory space. In lame man words, loading the resource only when its needed.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="java5" style="font-family:monospace;"><span class="kw2">public</span> <span class="kw2">class</span> YourSingletonClass<span class="br0">&#123;</span>
&nbsp;
<span class="kw2">private</span> <span class="kw2">static</span> YourSingletonClassinstance = <span class="kw2">new</span> YourSingletonClass<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">public</span> <span class="kw2">static</span> YourSingletonClass getInstance<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="kw2">return</span> instance<span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw2">private</span> YourSingletonClass<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="br0">&#125;</span></pre></div></div>
<div><span><strong>How do we ensure only one the same instance is </strong></span></div>
<p><span><strong><span lang="EN">returned</span><span>?</span></strong></p>
<div><span lang="EN">We write a public static getter or access method to get the instance of the Singleton Object at runtime. First time the object is created inside this method as it is null. Subsequent calls to this method returns the same object created as the object is globally declared (private) and the hence the same referenced object is returned.</span></div>
<p></span><span lang="EN"> </p>
<p></span></p>
<div><span style="font-size: x-small;"> </span></div>
<p><span style="font-size: x-small;"> </p>
<p></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/07/16/singletons-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating flex components in runtime using XML</title>
		<link>http://vinothbabu.com/2010/05/18/creating-flex-components-in-runtime-using-xml/</link>
		<comments>http://vinothbabu.com/2010/05/18/creating-flex-components-in-runtime-using-xml/#comments</comments>
		<pubDate>Tue, 18 May 2010 20:36:22 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[My World]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=296</guid>
		<description><![CDATA[Today i was going through an requirement on how to create components in runtime where we have parse an XML as input and then create components in the stage. Live Demo Application source]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/296.png&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>Today i was going through an requirement on how to create components in runtime where we have parse an XML as input and then create components in the stage.<span id="more-296"></span><div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><span class="sy0">&lt;?</span>xml <span class="kw7">version</span>=<span class="st0">&quot;1.0&quot;</span> encoding=<span class="st0">&quot;utf-8&quot;</span><span class="sy0">?&gt;</span><br />
<span class="sy0">&lt;</span>mx<span class="sy0">:</span>Application xmlns<span class="sy0">:</span>mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp;creationComplete=<span class="st0">&quot;creationCompleteHandler()&quot;</span><span class="sy0">&gt;</span><br />
<br />
&nbsp;<span class="sy0">&lt;</span>mx<span class="sy0">:</span>Script<span class="sy0">&gt;</span><br />
&nbsp;<span class="sy0">&lt;!</span><span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span><br />
<br />
&nbsp;<span class="kw1">import</span> <span class="kw6">flash.display</span><span class="sy0">.</span><a href="http://www.google.com/search?q=displayobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:displayobject.html"><span class="kw5">DisplayObject</span></a><span class="sy0">;</span><br />
&nbsp;<span class="kw1">import</span> mx<span class="sy0">.</span>core<span class="sy0">.</span>UIComponent<span class="sy0">;</span><br />
&nbsp;<span class="kw1">import</span> mx<span class="sy0">.</span>controls<span class="sy0">.</span>ComboBox<span class="sy0">;</span> ComboBox<span class="sy0">;</span><br />
&nbsp;<span class="kw1">import</span> mx<span class="sy0">.</span>controls<span class="sy0">.</span>RadioButton<span class="sy0">;</span> RadioButton<span class="sy0">;</span><br />
&nbsp;<span class="kw1">import</span> mx<span class="sy0">.</span>controls<span class="sy0">.</span>CheckBox<span class="sy0">;</span> CheckBox<span class="sy0">;</span><br />
&nbsp;<span class="kw1">import</span> mx<span class="sy0">.</span>controls<span class="sy0">.</span>TextArea<span class="sy0">;</span> TextArea<span class="sy0">;</span><br />
<br />
&nbsp;<span class="kw1">protected</span> <span class="kw3">function</span> creationCompleteHandler<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp;<span class="kw2">var</span> components<span class="sy0">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span class="kw5">Array</span></a> = getComponentsFromXML<span class="br0">&#40;</span>xml<span class="sy0">.</span>component<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> i<span class="sy0">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span class="kw5">int</span></a> = <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> n<span class="sy0">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span class="kw5">int</span></a> = components<span class="sy0">.</span><span class="kw7">length</span><span class="sy0">;</span><br />
&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span>i<span class="sy0">;</span> i <span class="sy0">&lt;</span> n<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp;panel<span class="sy0">.</span><span class="kw7">addChild</span><span class="br0">&#40;</span>components<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="kw1">as</span> <a href="http://www.google.com/search?q=displayobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:displayobject.html"><span class="kw5">DisplayObject</span></a><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<br />
&nbsp;<span class="coMULTI">/**<br />
&nbsp;*  Parses an XML string, returns array of new components.<br />
&nbsp;*/</span><br />
&nbsp;<span class="kw1">public</span> <span class="kw3">function</span> getComponentsFromXML<span class="br0">&#40;</span>components<span class="sy0">:</span><a href="http://www.google.com/search?q=xmllist%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xmllist.html"><span class="kw5">XMLList</span></a><span class="br0">&#41;</span><span class="sy0">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span class="kw5">Array</span></a><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp;<span class="kw2">var</span> result<span class="sy0">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span class="kw5">Array</span></a> = <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> <span class="kw7">child</span><span class="sy0">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span class="kw5">Object</span></a><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> component<span class="sy0">:</span>UIComponent<span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> <span class="kw7">type</span><span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> clazz<span class="sy0">:</span><a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span class="kw5">Class</span></a><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> i<span class="sy0">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span class="kw5">int</span></a> = <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> n<span class="sy0">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span class="kw5">int</span></a> = components<span class="sy0">.</span><span class="kw7">length</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span>i<span class="sy0">;</span> i <span class="sy0">&lt;</span> n<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp;<span class="kw7">child</span> = components<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw7">type</span> = <span class="kw7">child</span><span class="sy0">.</span>@<span class="kw7">type</span><span class="sy0">;</span><br />
&nbsp;<span class="kw1">try</span> <span class="br0">&#123;</span><br />
&nbsp;clazz = <span class="kw6">flash.utils</span><span class="sy0">.</span><span class="kw7">getDefinitionByName</span><span class="br0">&#40;</span><span class="kw7">type</span><span class="br0">&#41;</span> <span class="kw1">as</span> <a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span class="kw5">Class</span></a><span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span> <span class="kw1">catch</span> <span class="br0">&#40;</span><span class="kw7">error</span><span class="sy0">:</span><a href="http://www.google.com/search?q=referenceerror%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:referenceerror.html"><span class="kw5">ReferenceError</span></a><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp;traceImportError<span class="br0">&#40;</span><span class="kw7">type</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<br />
&nbsp;component = <span class="kw1">new</span> clazz<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// dynamic</span><br />
<br />
&nbsp;<span class="kw2">var</span> properties<span class="sy0">:</span><a href="http://www.google.com/search?q=xmllist%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xmllist.html"><span class="kw5">XMLList</span></a> = <span class="kw7">child</span><span class="sy0">.</span><span class="kw7">elements</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> property<span class="sy0">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span class="kw5">XML</span></a><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> <span class="kw7">name</span><span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> <span class="kw7">value</span><span class="sy0">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span class="kw5">Object</span></a><span class="sy0">;</span><br />
<br />
&nbsp;<span class="co1">// for each child node</span><br />
&nbsp;<span class="kw1">for</span> <span class="kw1">each</span> <span class="br0">&#40;</span>property <span class="kw1">in</span> properties<span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp;<span class="kw7">name</span> = property<span class="sy0">.</span><span class="kw7">localName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw7">value</span> = property<span class="sy0">.</span><span class="kw7">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="co1">// create a more generic method to convert</span><br />
&nbsp;<span class="co1">// strings to numbers and whatnot</span><br />
&nbsp;<span class="co1">// this is a regular expression matching any digit</span><br />
&nbsp;<span class="co1">// check out rubular.com</span><br />
&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="co2">/\d+/</span><span class="sy0">.</span><span class="kw7">test</span><span class="br0">&#40;</span><span class="kw7">value</span><span class="sy0">.</span><span class="kw7">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp;<span class="kw7">value</span> = <a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span class="kw5">Number</span></a><span class="br0">&#40;</span><span class="kw7">value</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>property<span class="sy0">.</span><span class="kw7">attribute</span><span class="br0">&#40;</span><span class="st0">&quot;isStyle&quot;</span><span class="br0">&#41;</span> == <span class="st0">&quot;true&quot;</span><span class="br0">&#41;</span><br />
&nbsp;component<span class="sy0">.</span><span class="kw7">setStyle</span><span class="br0">&#40;</span><span class="kw7">name</span><span class="sy0">,</span> <span class="kw7">value</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw1">else</span><br />
&nbsp;component<span class="br0">&#91;</span><span class="kw7">name</span><span class="br0">&#93;</span> = <span class="kw7">value</span><span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
&nbsp;result<span class="sy0">.</span><span class="kw7">push</span><span class="br0">&#40;</span>component<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
&nbsp;<span class="kw1">return</span> result<span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<br />
&nbsp;<span class="kw1">protected</span> <span class="kw3">function</span> traceImportError<span class="br0">&#40;</span><span class="kw7">type</span><span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp;<span class="kw7">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Please include the class '&quot;</span> <span class="sy0">+</span> <span class="kw7">type</span> <span class="sy0">+</span> <span class="st0">&quot;' in the swf.&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> <span class="kw7">names</span><span class="sy0">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span class="kw5">Array</span></a> = <span class="kw7">type</span><span class="sy0">.</span><span class="kw7">split</span><span class="br0">&#40;</span><span class="st0">&quot;.&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw2">var</span> last<span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a> = <span class="kw7">names</span><span class="br0">&#91;</span><span class="kw7">names</span><span class="sy0">.</span><span class="kw7">length</span> <span class="sy0">-</span> 1<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw7">trace</span><span class="br0">&#40;</span><span class="st0">&quot;import &quot;</span> <span class="sy0">+</span> <span class="kw7">type</span> <span class="sy0">+</span> <span class="st0">&quot;; &quot;</span> <span class="sy0">+</span> last <span class="sy0">+</span> <span class="st0">&quot;;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<br />
&nbsp;<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">&gt;</span><br />
&nbsp;<span class="sy0">&lt;/</span>mx<span class="sy0">:</span>Script<span class="sy0">&gt;</span><br />
<br />
&nbsp;<span class="sy0">&lt;!--</span> sample <span class="kw7">data</span> <span class="sy0">--&gt;</span><br />
&nbsp;<span class="sy0">&lt;</span>mx<span class="sy0">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span class="kw5">XML</span></a> id=<span class="st0">&quot;xml&quot;</span> <span class="kw7">source</span>=<span class="st0">&quot;components.xml&quot;</span> <span class="sy0">/&gt;</span><br />
<br />
&nbsp;<span class="sy0">&lt;!--</span> sample container <span class="sy0">--&gt;</span><br />
&nbsp;<span class="sy0">&lt;</span>mx<span class="sy0">:</span>Panel id=<span class="st0">&quot;panel&quot;</span> <span class="kw7">width</span>=<span class="st0">&quot;100%&quot;</span> <span class="kw7">height</span>=<span class="st0">&quot;100%&quot;</span><span class="sy0">/&gt;</span><br />
<br />
<span class="sy0">&lt;/</span>mx<span class="sy0">:</span>Application<span class="sy0">&gt;</span></div></div></p>
<p><a href="http://www.vinothbabu.com/Flex-Samples/creatingComponentsFromXML/creatingComponentsFromXML.html" target="_blank">Live Demo</a></p>
<p><a href="http://www.vinothbabu.com/Flex-Samples/creatingComponentsFromXML.zip" target="_self">Application source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/05/18/creating-flex-components-in-runtime-using-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPDATE and INSERT differences in syntax is an inconvenience</title>
		<link>http://vinothbabu.com/2010/05/08/update-and-insert-differences-in-syntax-is-an-inconvenience/</link>
		<comments>http://vinothbabu.com/2010/05/08/update-and-insert-differences-in-syntax-is-an-inconvenience/#comments</comments>
		<pubDate>Sat, 08 May 2010 17:23:34 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[mys]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[queries]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=288</guid>
		<description><![CDATA[An associative array is the conventional workaround of the coding world.. In an associative array, we can associate any key or index we want with each value. escape_arr.php Although the above code is elegant, an associative array forces me to think of my queries as objects. After putting my head to work, I found that [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/288.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>An associative array is the conventional workaround of the coding world.. In an associative array, we can associate any key or index we want with each value.<span id="more-288"></span></p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="kw1">include</span><span class="br0">&#40;</span><span class="st_h">'escape_arr.php'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">//create an array</span>
<span class="re0">$sets</span><span class="sy0">=</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span>
<span class="st_h">'userid'</span><span class="sy0">=&gt;</span><span class="re0">$userid</span><span class="sy0">,</span>
<span class="st_h">'mimetype'</span><span class="sy0">=&gt;</span><span class="re0">$mimetype</span><span class="sy0">,</span>
<span class="st_h">'bytesize'</span><span class="sy0">=&gt;</span><span class="re0">$bytesize</span><span class="sy0">,</span>
<span class="st_h">'filename'</span><span class="sy0">=&gt;</span><span class="re0">$filename</span><span class="sy0">,</span>
<span class="st_h">'extension'</span><span class="sy0">=&gt;</span><span class="re0">$ext</span><span class="sy0">,</span>
<span class="st_h">'lastmodified'</span><span class="sy0">=&gt;</span>time<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
<span class="st_h">'height'</span><span class="sy0">=&gt;</span><span class="re0">$height</span><span class="sy0">,</span>
<span class="st_h">'width'</span><span class="sy0">=&gt;</span><span class="re0">$width</span><span class="sy0">,</span>
<span class="st_h">'binarydata'</span><span class="sy0">=&gt;</span><span class="re0">$data</span>
<span class="br0">&#41;</span><span class="sy0">;</span>
<a href="http://www.php.net/list"><span class="kw3">list</span></a><span class="br0">&#40;</span><span class="re0">$sets</span><span class="sy0">,</span><span class="re0">$cols</span><span class="sy0">,</span><span class="re0">$values</span><span class="br0">&#41;</span><span class="sy0">=</span>escape_arr<span class="br0">&#40;</span><span class="re0">$sets</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$insert_sql</span><span class="sy0">=</span><span class="st0">&quot;INSERT INTO `avatars` &quot;</span><span class="sy0">.</span><a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">&#40;</span><span class="st_h">','</span><span class="sy0">,</span><span class="re0">$cols</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot; VALUES(&quot;</span><span class="sy0">.</span><a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">&#40;</span><span class="st_h">','</span><span class="sy0">,</span><span class="re0">$values</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;)&quot;</span><span class="sy0">;</span>
<span class="re0">$update_sql</span><span class="sy0">=</span><span class="st0">&quot;UPDATE `avatars` SET &quot;</span><span class="sy0">.</span><a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">&#40;</span><span class="st_h">','</span><span class="sy0">,</span><span class="re0">$sets</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot; WHERE userid=<span class="es4">$userid</span> LIMIT 1&quot;</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$avatar_exists</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
<span class="re0">$result</span><span class="sy0">=</span><a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$insert_sql</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Insert query failed!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span>
<span class="re0">$result</span><span class="sy0">=</span><a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$update_sql</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Update query failed!&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">echo</span> <span class="st_h">'Avatar updated!'</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span>
escape_arr.php
<span class="kw2">&lt;?php</span>
<span class="kw2">function</span> escape_arr<span class="br0">&#40;</span><span class="re0">$arr</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
<span class="re0">$out</span><span class="sy0">=</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$sets</span><span class="sy0">=</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$arr</span> <span class="kw1">as</span> <span class="re0">$key</span> <span class="sy0">=&gt;</span> <span class="re0">$value</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
<span class="re0">$k</span><span class="sy0">=</span><span class="st0">&quot;`<span class="es4">$key</span>`&quot;</span><span class="sy0">;</span>
<span class="re0">$v</span><span class="sy0">=</span><span class="st0">&quot;'&quot;</span><span class="sy0">.</span><a href="http://www.php.net/mysql_real_escape_string"><span class="kw3">mysql_real_escape_string</span></a><span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;'&quot;</span><span class="sy0">;</span>
<span class="re0">$out</span><span class="br0">&#91;</span><span class="re0">$k</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$v</span><span class="sy0">;</span>
<span class="re0">$sets</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">=</span><span class="st0">&quot;<span class="es4">$k</span> = <span class="es4">$v</span>&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">return</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$sets</span><span class="sy0">,</span> <a href="http://www.php.net/array_keys"><span class="kw3">array_keys</span></a><span class="br0">&#40;</span><span class="re0">$out</span><span class="br0">&#41;</span><span class="sy0">,</span> <a href="http://www.php.net/array_values"><span class="kw3">array_values</span></a><span class="br0">&#40;</span><span class="re0">$out</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>
<p><strong>escape_arr.php</strong></p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="kw2">function</span> escape_arr<span class="br0">&#40;</span><span class="re0">$arr</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
<span class="re0">$out</span><span class="sy0">=</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$sets</span><span class="sy0">=</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$arr</span> <span class="kw1">as</span> <span class="re0">$key</span> <span class="sy0">=&gt;</span> <span class="re0">$value</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
<span class="re0">$k</span><span class="sy0">=</span><span class="st0">&quot;`<span class="es4">$key</span>`&quot;</span><span class="sy0">;</span>
<span class="re0">$v</span><span class="sy0">=</span><span class="st0">&quot;'&quot;</span><span class="sy0">.</span><a href="http://www.php.net/mysql_real_escape_string"><span class="kw3">mysql_real_escape_string</span></a><span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&quot;'&quot;</span><span class="sy0">;</span>
<span class="re0">$out</span><span class="br0">&#91;</span><span class="re0">$k</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$v</span><span class="sy0">;</span>
<span class="re0">$sets</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">=</span><span class="st0">&quot;<span class="es4">$k</span> = <span class="es4">$v</span>&quot;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="kw1">return</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$sets</span><span class="sy0">,</span> <a href="http://www.php.net/array_keys"><span class="kw3">array_keys</span></a><span class="br0">&#40;</span><span class="re0">$out</span><span class="br0">&#41;</span><span class="sy0">,</span> <a href="http://www.php.net/array_values"><span class="kw3">array_values</span></a><span class="br0">&#40;</span><span class="re0">$out</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre></div></div>
<p>Although the above code is elegant, an associative array forces me to think of my queries as objects. After putting my head to work, I found that a blank INSERT could put my mind at ease.</p>
<blockquote><div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://vinothbabu.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
<span class="re0">$sql</span><span class="sy0">=</span><span class="st0">&quot;INSERT INTO `tbl` (`id`) VALUES(NULL);&quot;</span><span class="sy0">;</span>
<span class="re0">$sql</span><span class="sy0">.=</span><span class="st0">&quot;UPDATE `tbl` SET `f1`='v1',`f2`='v2' WHERE id = LAST_INSERT_ID();&quot;</span><span class="sy0">;</span>
<a href="http://www.php.net/mysql_query"><span class="kw3">mysql_query</span></a><span class="br0">&#40;</span><span class="re0">$sql</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><a href="http://www.php.net/mysql_error"><span class="kw3">mysql_error</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span></pre></div></div></blockquote>
<p>Conclusion: both solutions are equally valid. You may also hard-code your queries but such coding is bad practice. There are many drawbacks for using this approach.</p>
<ol>
<li>First of all, such strings can span several lines of code and make your PHP file hard to read and understand.</li>
<li>Secondly each one of your strings becomes a debugging red-flag.</li>
<li>And thirdly if you ever decided to add a new field to your table &#8211; say “birthdate” &#8211; then you will have to run through each of your hard-coded strings and add-in a field name and value for each of the strings respectively. Each string will then have an added chance for a syntax errors and make debugging harder. And since such coding practice lacks versatility, a simple task such as adding a “birthdate” field later in the future can become a nightmare.</li>
</ol>
<p>One could also use REPLACE. However I strongly advise against using this approach since it reserves the potential to wipe your database clean due to its DELETE + INSERT logic. A better solution would be INSERT … ON DUPLICATE KEY UPDATE. However this query doesn’t address my syntax difference emphasis.</p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/05/08/update-and-insert-differences-in-syntax-is-an-inconvenience/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Design Patterns : Singleton Pattern</title>
		<link>http://vinothbabu.com/2010/04/15/design-patterns-singleton-pattern/</link>
		<comments>http://vinothbabu.com/2010/04/15/design-patterns-singleton-pattern/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 04:40:59 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Chess board]]></category>
		<category><![CDATA[Singleton Pattern]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=283</guid>
		<description><![CDATA[The Singleton pattern is very similar to creator pattern. This is very widely used pattern. Now a question might raise in the mind that why do we need this pattern and when it should be applied. Let us take a situation where you want to build a chess game. Where does the Singleton Pattern apply [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/283.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>The Singleton pattern is very similar to creator pattern. This is very widely used pattern. Now a question might raise in the mind that why do we need this pattern and when it should be applied. Let us take a situation where you want to build a chess game. Where does the Singleton Pattern apply here?<span id="more-283"></span></p>
<p>chessboard is one, which is a square-checkered board with 64 squares arranged in an eight-by-eight grid. At the start, each player controls sixteen pieces: one king, one queen, two rooks, two knights, two bishops, and eight pawns. The object of the game is to checkmate  the opponent&#8217;s king, whereby the king is under immediate attack (in &#8220;check&#8221;) and there is no way to remove or defend it from attack on the next move.</p>
<p>Here your chessboard is Singleton class as its state should never change. It means even at nth movement, the board should hold all the records of pieces moved and its state. Let us now drive back to technical discussion.</p>
<p>The Singleton pattern allows a class to only one instance and it does provide a global access to the instance. How do we go on to make a Singleton class.</p>
<blockquote><p>Sample code : SingletonClass.as</p>
<p>package com.sophiacom.as3.designpatterns.creational.singleton<br />
{<br />
public class SingletonClass<br />
{<br />
private static var _instance:SingletonClass;</p>
<p>public function SingletonClass(enforcer:SingletonEnforcer) {}</p>
<p>public static function getInstance():SingletonClass {<br />
if (SingletonClass._instance == null) {<br />
SingletonClass._instance = new SingletonClass(new SingletonEnforcer());<br />
}<br />
return SingletonClass._instance;<br />
}<br />
}<br />
}</p>
<p>class SingletonEnforcer {}</p></blockquote>
<p>First we are defining a private static property that holds the single instance of the class.<br />
Then we go with a public static function that provides access to the single instance created.<br />
A private constructor that restrict access in instantiating the class.</p>
<p>Oops ActionScript 3.0 does not have a private constructor! So, to do this, the solution is to force a parameter in the constructor while type isn&#8217;t accessible. Just with a class outer the package of the class but defined in the same file, because in ActionScript 3, only one class can be visible.</p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/04/15/design-patterns-singleton-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom color in Flex bar Chart</title>
		<link>http://vinothbabu.com/2010/04/13/flex-bar-chart-with-different-colors/</link>
		<comments>http://vinothbabu.com/2010/04/13/flex-bar-chart-with-different-colors/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 02:00:54 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Flex Charts]]></category>
		<category><![CDATA[Bar Chart]]></category>
		<category><![CDATA[Color Component]]></category>
		<category><![CDATA[Custom component]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=276</guid>
		<description><![CDATA[Today one of my friend asked me on how to have a bar chart with different colors for each series. I thought of putting up this code online that someone can use it up or extend for more functionality too. Link to the Application [ View Source enabled ]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/276.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>Today one of my friend asked me on how to have a bar chart with different colors for each series. I thought of putting up this code online that someone can use it up or extend for more functionality too.<span id="more-276"></span><a href="http://vinothbabu.com/Flex-Samples/FlexBarChart/FlexBarChart.html" target="_blank"></a></p>
<p><a href="http://vinothbabu.com/Flex-Samples/FlexBarChart/FlexBarChart.html" target="_blank">Link to the Application</a> [ View Source enabled ]</p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/04/13/flex-bar-chart-with-different-colors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatting the SelectedDate in DateChooser</title>
		<link>http://vinothbabu.com/2010/03/31/formatting-the-selecteddate-in-datechooser/</link>
		<comments>http://vinothbabu.com/2010/03/31/formatting-the-selecteddate-in-datechooser/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 15:26:10 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=252</guid>
		<description><![CDATA[I was suddenly struck up with this DateChooser as my the date object doesn&#8217;t recognize the dash as a valid separator. var date:Date = new Date("2009/12/30"); myDateChooser.selectedDate = date; The above one works, but if you take the below one it does not work. var date:Date = new Date(&#8220;2009-12-30&#8243;); myDateChooser.selectedDate = date; The solution for [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/252.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>I was suddenly struck up with this DateChooser as my the date object doesn&#8217;t recognize the dash as a valid  separator.<span id="more-252"></span></p>
<blockquote>
<pre>var date:Date = new Date("2009/12/30");
myDateChooser.selectedDate = date;</pre>
</blockquote>
<p>The above one works, but if you take the below one it does not work.</p>
<blockquote><p>var date:Date = new Date(&#8220;2009-12-30&#8243;);<br />
myDateChooser.selectedDate = date;</p></blockquote>
<p>The solution for this is DateFormatter.</p>
<blockquote><p>var DateStr:String = dateFormatter.format(&#8220;2009-12-30&#8243;);<br />
DateChooser.selectedDate = new Date(DateStr);</p>
<p>&lt;mx:DateFormatter id=&#8221;dateFormatter&#8221; formatString=&#8221;MMM D, YYYY&#8221;/&gt;</p>
<p>&lt;mx:DateChooser showToday=&#8221;false&#8221; id=&#8221;DateChooser&#8221; x=&#8221;130&#8243; y=&#8221;55&#8243;  width=&#8221;159&#8243;&gt;&lt;/mx:DateChooser&gt;</p></blockquote>
<p>This will solve your problem. Have a nice day.</p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/03/31/formatting-the-selecteddate-in-datechooser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introduction to MVP for Flex</title>
		<link>http://vinothbabu.com/2010/03/29/introduction-to-mvp-for-flex/</link>
		<comments>http://vinothbabu.com/2010/03/29/introduction-to-mvp-for-flex/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 13:46:00 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[MVP]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=231</guid>
		<description><![CDATA[I was today having a discussion with my amigos on the various design patterns and we were usually struck with mind blowing MVP pattern. I did a Bing on reseearch but could not eventually find a single article which explains the users very clear of this pattern. That&#8217;s the reason of this post. Many people [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/231.jpeg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>I was today having a discussion with my amigos on the various design patterns and we were usually struck with mind blowing MVP pattern. I did a Bing on reseearch but could not eventually find a single article which explains the users very clear of this pattern. That&#8217;s the reason of this post.<span id="more-231"></span></p>
<p>Many people might initially get confused over the MVC [ Model, view and Controller ] and the MVP [ Model, View and Presenter ] pattern. There is a slight variation, but this pattern reduces the coupling.</p>
<p><strong>Model View and Control Pattern</strong></p>
<p><img class="aligncenter size-full wp-image-232" title="mvc" src="http://vinothbabu.com/wp-content/uploads/2010/03/mvc.png" alt="mvc" width="323" height="310" /><br />
In this pattern, view dispatches the events to the controller which in turn interacts with business logic of the application and the data binding techniques which updates the view automatically when ever there is a change in our model.</p>
<p><strong>Model View and Presenter Pattern</strong></p>
<p><img class="aligncenter size-full wp-image-233" title="MVP_Model4" src="http://vinothbabu.com/wp-content/uploads/2010/03/MVP_Model4.jpg" alt="MVP_Model4" width="400" height="228" /><br />
In this pattern, controller plays a major role in handling the user input and also an interaction with business logic also responsible of the update of the view. In this way there remains now link of view with Model and it totally relies on controller for all the presentation logic. As a result, there is no dependencies in either direction between the view and the model.</p>
<p>Let us now go through an example in RajiniKanth style. The below defines the the structure of our application.</p>
<p><img class="alignright size-medium wp-image-242" title="Structure" src="http://vinothbabu.com/wp-content/uploads/2010/03/Structure-300x230.jpg" alt="Structure" width="300" height="230" />The presenter folder contains the AdditionPresenter which acts as a controller handling the input and also does the business logic.</p>
<p>The view is area where our form is displayed with an <strong>Interface </strong>IAddView (implemented by the AdditionForm.mxml file) define  the methods we need in order to update the view and get the the numbers from the view to complete our <strong>Addition </strong>operation.</p>
<p>The <strong>MVPAddition.mxml</strong> is the main file, it only defines the custom component view.</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br />
&lt;mx:Application xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; xmlns:view=&#8221;com.vinoth.MVP.view.*&#8221;&gt;<br />
&lt;view:AdditionForm/&gt;<br />
&lt;/mx:Application&gt;</p></blockquote>
<p>The Interfact IAddView defines the methods we need in order to update the view and get the numbers from the view. It is implemented by the AdditionForm.mxml</p>
<blockquote><p>package com.vinoth.MVP.view<br />
{<br />
public interface IAddView<br />
{</p>
<p>function set Number3(value:String):void;</p>
<p>function get Number1():Number;<br />
function get Number2():Number;</p>
<p>}<br />
}</p></blockquote>
<p>The AddView custom component contains the MXML tag needed to define the  UI and it calls the addData() method in the Presenter.</p>
<blockquote><p>&lt;mx:Label text=&#8221;Addition of Two Numbers&#8221; width=&#8221;100%&#8221; fontWeight=&#8221;bold&#8221;/&gt;</p>
<p>&lt;mx:Form width=&#8221;100%&#8221; height=&#8221;50%&#8221;&gt;<br />
&lt;mx:FormItem label=&#8221;Number One&#8221; width=&#8221;100%&#8221;&gt;<br />
&lt;mx:TextInput id=&#8221;_Number1&#8243; editable=&#8221;true&#8221; width=&#8221;100%&#8221; restrict=&#8221;0-9&#8243;/&gt;<br />
&lt;/mx:FormItem&gt;<br />
&lt;mx:FormItem label=&#8221;Number Two&#8221; width=&#8221;100%&#8221;&gt;<br />
&lt;mx:TextInput id=&#8221;_Number2&#8243; editable=&#8221;true&#8221; width=&#8221;100%&#8221; restrict=&#8221;0-9&#8243;/&gt;<br />
&lt;/mx:FormItem&gt;<br />
&lt;/mx:Form&gt;<br />
&lt;mx:HBox width=&#8221;100%&#8221;&gt;<br />
&lt;mx:Label text=&#8221;Result&#8221; /&gt;<br />
&lt;mx:Label width=&#8221;100%&#8221; id=&#8221;_Number3&#8243; /&gt;<br />
&lt;mx:Button label=&#8221;Add&#8221; click=&#8221;_presenter.addData()&#8221; /&gt;<br />
&lt;/mx:HBox&gt;</p></blockquote>
<p>It also contains the methods defined in the IAddView and a private  method that is registered as a listener for the creationComplete event  that initialize the presenter.</p>
<blockquote><p>import com.vinoth.MVP.presenter.AdditonPresenter;</p>
<p>private var _presenter:AdditonPresenter;</p>
<p>private function init():void{<br />
_presenter = new AdditonPresenter(this);<br />
}</p>
<p>public function get Number1():Number {<br />
return Number(_Number1.text);<br />
}</p>
<p>public function get Number2():Number{<br />
return Number(_Number2.text);<br />
}</p>
<p>public function set Number3(value:String):void{<br />
_Number3.text = value;<br />
}</p></blockquote>
<p>The presenter is the one which handles the business logic and updates the view through the interface without accessing the View Form.The presenter stores a private member of the view and it updates accordingly.</p>
<blockquote><p>public var _view:IAddView</p></blockquote>
<p>The Patter is simple but yet very powerful because of its least dependency and the presenter relies only on the interface and not on the UI.</p>
<p><a href="http://vinothbabu.com/Flex-Samples/MVP-Addition.rar" target="_blank">Application Souce</a></p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/03/29/introduction-to-mvp-for-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Who can become a Great leader &#8211; IT Environment</title>
		<link>http://vinothbabu.com/2010/03/25/who-can-become-a-great-leader-it-environment/</link>
		<comments>http://vinothbabu.com/2010/03/25/who-can-become-a-great-leader-it-environment/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 07:37:28 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[My World]]></category>
		<category><![CDATA[Architect]]></category>
		<category><![CDATA[Bhagat Singh]]></category>
		<category><![CDATA[Great Leader]]></category>
		<category><![CDATA[Mahatama Gandhi]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=235</guid>
		<description><![CDATA[This article is a piece of information that i have learnt so far in my life also tried to achive and practice this when i was lead too in some of my previous organisation. Thought sharing this written information can help many to get into this path in future or change to this if they [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/235.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>This article is a piece of information that i have learnt so far in my life also tried to achive and practice this when i was lead too in some of my previous organisation.<span id="more-235"></span> Thought sharing this written information can help many to get into this path in future or change to this if they wish to follow or gain knowledge which can make our IT industry majuscule and also my Abdul Kalam sir&#8217;s dream 2020. I failed to achive many things in my life in IT industries, then i decided to get into a soul called <strong>rebel </strong>to bring change. <strong>I just work these days only to bring change.<img class="alignright size-medium wp-image-240" title="leaders wanted" src="http://vinothbabu.com/wp-content/uploads/2010/03/leaders-wanted-300x284.gif" alt="leaders wanted" width="300" height="284" /></strong></p>
<p>A <strong>Great </strong>leader</p>
<p>A great leader is one who is true to his <strong>heart </strong>than his mind, who can make things work through <strong>heart </strong>in all environments and angle.</p>
<p>A great leader can handle resource which are not capable of even coding a single <strong>line </strong>and who does not quit at any wee.</p>
<p>A great leader is a great <strong>physiologist</strong>, one who can turn into anything depending upon the situation. If he is interacting with a child, he will think and play the coins according to that child minds than his mind. The greatest challenge is changing a person to what we require, there might be some good , bad and attitude programmers, a <strong>great </strong>leader is one who brings all these to square one.</p>
<p>A great leader is one who does <strong>not </strong>show his <strong>attitude </strong>towards his team, instead he focus and makes other also to focus on the programming language and show their attitude in the programming language.</p>
<blockquote><p><strong>Ex</strong>: If the language like Java does not allow you to program as you like, a great leader always asks their programmer to show their attitude in it such that making java itself flexible. This requires genious level of thinking to overcome Java strubborn in their pattern itself.</p></blockquote>
<p><strong>1. How are you going to hanle a project when the resource allocation is limited or low?</strong></p>
<p>Start the project like a tortise by giving training to all and make the project end up like a rabit. Its something like when the resources are low, you need to make or bring your team members mind into Agile.</p>
<p><strong>2. How are you going to handle when your team lacks basic programming knowledge itself?</strong></p>
<p>The situation is complex, and you need to give them the confidence, encouragement at every level at the same wee handle your elite programmers to completer their task. A example is to teach him programming and appreciate them even if they have achived nothing. This can quickly turn them into elite ones.</p>
<p><strong>3. How to handle if both of the above at same instance?</strong></p>
<p>Become a singleton class. That is you should able to take up the 60 percent of project on your head along with other tasks too, and let your team create instances of your knowledge and implement them at lowest level. You should never change at any point of wee. In more simpler words a <strong>great</strong> <strong>leader</strong> can only finish out the project into success in such situation</p>
<p>A great leader should have a vision of <strong>Bagat singh</strong> following the path of <strong>Mahatma Gandhi</strong></p>
<p>A great leader is a great human being respected by all ends. Mahatama Gandhi, Abdul Kalam sir [My college day's professor] could suit my article though they were not from IT industry.<strong></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/03/25/who-can-become-a-great-leader-it-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linklist and ArrayList</title>
		<link>http://vinothbabu.com/2010/03/23/linklist-and-arraylist/</link>
		<comments>http://vinothbabu.com/2010/03/23/linklist-and-arraylist/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 13:07:17 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=227</guid>
		<description><![CDATA[Today i was turning back towards Linklist and a question dropped in my mind is when to use Linklist and When to use ArrayList. They both are different in implementations. LinkedList implements it with a doubly-linked list. ArrayList implements it with a dynamically resizing array. If you take up Linklist you can walk the lists [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/227.png&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>Today i was turning back towards Linklist and a question dropped in my mind is when to use Linklist and When to use ArrayList.<span id="more-227"></span></p>
<p>They both are different in implementations. LinkedList implements it with a doubly-linked list. ArrayList implements it with a dynamically resizing array. If you take up Linklist you can walk the lists forward or backwards, but grabbing an element in the middle takes time which depeneds upon your size of the list.</p>
<p>ArrayLists allows you random access, but adding and removing from anywhere smells your time which requires shifting all the latter elements. When you add more elements more than the capacity, a new array twice of the default size is allocated and the older array is copied to newer one.</p>
<p><strong>When should i use LinkedList?</strong></p>
<ol>
<li> When you need efficient removal in between elements or at the start.</li>
<li> When you don&#8217;t need random access to elements, but can live with iterating over them one by one</li>
</ol>
<p><strong><br />
When should i use ArrayList?</strong></p>
<ol>
<li> When you need random access to elements (&#8220;get the nth. element&#8221;)</li>
<li> When you don&#8217;t need to remove elements from between others. It&#8217;s possible but it&#8217;s slower since the internal backing-up array needs to be reallocated.</li>
<li> Adding elements is amortized constant time (meaning every once in a while, you pay some performance, but overall adding is instantly done)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/03/23/linklist-and-arraylist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My India &#8211; Top 10 Amazing Photos</title>
		<link>http://vinothbabu.com/2010/03/21/my-india-top-10-amazing-photos/</link>
		<comments>http://vinothbabu.com/2010/03/21/my-india-top-10-amazing-photos/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 14:33:16 +0000</pubDate>
		<dc:creator>Sachin</dc:creator>
				<category><![CDATA[My World]]></category>

		<guid isPermaLink="false">http://vinothbabu.com/?p=210</guid>
		<description><![CDATA[While coding here in office on sunday, i really felt bored with this power learn team working so hard for their stable release and i was sitting in my desk thinking on a pattern on how they are stating it as best. After all reading, i felt that its time for a break and the [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://vinothbabu.com/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/210.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>While coding here in office on sunday, i really felt bored with this power learn team working so hard for their stable release and i was sitting in my desk thinking on a pattern on how they are stating it as best. After all reading, i felt that its time for a break and the result is this collection of photos.<span id="more-210"></span></p>
<p><strong>We welcome this way</strong></p>
<p><img class="aligncenter size-full wp-image-211" title="india-001" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-001.jpg" alt="india-001" width="500" height="346" /></p>
<p><strong>Mate&#8230; ah recession</strong></p>
<p><img class="aligncenter size-full wp-image-212" title="india-003" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-003.jpg" alt="india-003" width="485" height="315" /></p>
<p><strong>The Cute Girl</strong></p>
<p><img class="aligncenter size-full wp-image-213" title="india-067" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-067.jpg" alt="india-067" width="500" height="348" /></p>
<p><strong>I am Tired.</strong></p>
<p><img class="aligncenter size-full wp-image-214" title="india-060" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-060.jpg" alt="india-060" width="475" height="473" /></p>
<p><strong>Move Move&#8230;. Train is coming</strong></p>
<p><img class="aligncenter size-full wp-image-215" title="india-043" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-043.jpg" alt="india-043" width="500" height="346" /></p>
<p><strong>The Real and tasty Indian food</strong></p>
<p><img class="aligncenter size-full wp-image-216" title="india-052" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-052.jpg" alt="india-052" width="500" height="373" /></p>
<p><strong>I can still code</strong></p>
<p><img class="aligncenter size-full wp-image-217" title="india-038" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-038.jpg" alt="india-038" width="500" height="333" /></p>
<p><strong>The TATA Truck which can hold more&#8230;&#8230;&#8230;&#8230;.</strong></p>
<p><img class="aligncenter size-full wp-image-218" title="india-029" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-029.jpg" alt="india-029" width="498" height="367" /></p>
<p><strong>The School boy</strong></p>
<p><img class="aligncenter size-full wp-image-219" title="india-054" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-054.jpg" alt="india-054" width="467" height="557" /></p>
<p><strong>And last but not least&#8230;&#8230;&#8230;. the Hands.</strong></p>
<p><img class="aligncenter size-full wp-image-220" title="india-068" src="http://vinothbabu.com/wp-content/uploads/2010/03/india-068.jpg" alt="india-068" width="500" height="332" /></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2884px; width: 1px; height: 1px; overflow: hidden;">http://media.smashingmagazine.com/cdn_smash/wp-content/uploads/2010/03/india-001.jpg</div>
]]></content:encoded>
			<wfw:commentRss>http://vinothbabu.com/2010/03/21/my-india-top-10-amazing-photos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
