<?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/"
	>

<channel>
	<title>Satish's Blog</title>
	<atom:link href="http://satish.name/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://satish.name</link>
	<description>{:name =&#62; 'Satish Gunnu', :profession =&#62; 'Software Engineer', :interests =&#62; 'Ruby, Groovy, Java'}</description>
	<pubDate>Tue, 25 Aug 2009 20:03:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Runtime Class Reloading.</title>
		<link>http://satish.name/?p=129</link>
		<comments>http://satish.name/?p=129#comments</comments>
		<pubDate>Tue, 25 Aug 2009 20:03:40 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Grails]]></category>

		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://satish.name/?p=129</guid>
		<description><![CDATA[In this post I want to discuss how runtime class reloading can be done in java using user defined class loaders. The following is a simple example that demonstrates how classes can be reloaded at runtime in Java. This is done using a different user defined class loader than that originally loaded the class. The [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I want to discuss how runtime class reloading can be done in java using <strong>user defined class loaders</strong>. The following is a simple example that demonstrates how classes can be reloaded at runtime in Java. This is done using a different user defined class loader than that originally loaded the class. The following two java classes should be on the classpath of the java command.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.*</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestReload <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> TestClass reload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">URL</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> urls <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span>;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Convert the file object to a URL</span>
            <span style="color: #003399;">File</span> dir <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>programs<span style="color: #000099; font-weight: bold;">\\</span>projects<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> dir.<span style="color: #006633;">toURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;        <span style="color: #666666; font-style: italic;">// file:/c:/almanac1.4/examples/</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>url<span style="color: #009900;">&#41;</span>;
            <span style="color: #003399;">Runtime</span>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javac C:<span style="color: #000099; font-weight: bold;">\\</span>programs<span style="color: #000099; font-weight: bold;">\\</span>projects<span style="color: #000099; font-weight: bold;">\\</span>com<span style="color: #000099; font-weight: bold;">\\</span>*.java&quot;</span><span style="color: #009900;">&#41;</span>;
            urls <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>url<span style="color: #009900;">&#125;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">ClassLoader</span> cl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URLClassLoader</span><span style="color: #009900;">&#40;</span>urls<span style="color: #009900;">&#41;</span>;
            <span style="color: #000000; font-weight: bold;">Class</span> cls <span style="color: #339933;">=</span> cl.<span style="color: #006633;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com.TestClassImpl&quot;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>TestClass<span style="color: #009900;">&#41;</span> cls.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span>;
    <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> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> argsv<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;sys out&quot;</span><span style="color: #009900;">&#41;</span>;
        TestReload testReload <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestReload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</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>testReload.<span style="color: #006633;">reload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Test class the implementation of this class will be out side of class path</span>
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com</span>;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> TestClass <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now place the TestClass and TestClassImpl in a path other than the java class path and compile them. Now run the original TestReload and change the message, you will see the changes picked up at run-time :). Bear in mind that I chose not have the class to be reloaded specifically in class path to avoid confusion. This is perfectly acceptable and two different class loaders can load same class.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com</span>;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestClassImpl <span style="color: #000000; font-weight: bold;">implements</span> TestClass <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMessage<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;Change me&quot;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Grails development is breeze with runtime class reloading for controllers, domain and service classes etc at run time. <a href="http://www.zeroturnaround.com/javarebel/"><strong>JavaRebel</strong></a> is a promising tool that enables this functionality to java users and is a great productivity gain. This tool uses class instrumentation and java agents to achieve run-time class loading that is more efficient and faster. </p>
<p>Resources:<br />
http://mindprod.com/jgloss/reloading.html<br />
http://www.exampledepot.com/egs/java.lang/ReloadClass.html</p>
]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=129</wfw:commentRss>
		</item>
		<item>
		<title>Switching to zsh from bash</title>
		<link>http://satish.name/?p=116</link>
		<comments>http://satish.name/?p=116#comments</comments>
		<pubDate>Tue, 04 Aug 2009 04:45:20 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[bash]]></category>

		<category><![CDATA[zsh.]]></category>

		<guid isPermaLink="false">http://satish.name/?p=116</guid>
		<description><![CDATA[I have recently switched from bash to zsh. zsh has nice command completion and it also suggests command if you mistype. Mac OS-X comes with zsh installed, to switch to zsh go to system preferences -> accounts, right click on the account select advanced options and select zsh for login shell. Also along the way [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently switched from bash to zsh. zsh has nice command completion and it also suggests command if you mistype. Mac OS-X comes with zsh installed, to switch to zsh go to system preferences -> accounts, right click on the account select advanced options and select zsh for login shell. Also along the way I picked up a new command, its the bang command I would like to share, bare in mind this is not unique to zsh and is also available in bash. Have fun programming :).</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;"> !! - To run last executed command
 !$ - Last argument of previous command
 !* - All arguments
 !!:1 - First argument</pre></div></div>

<p>References<br />
<a href="http://www.zsh.org/">http://www.zsh.org/</a><br />
<a href="http://vafer.org/blog/20070103101542">http://vafer.org/blog/20070103101542</a></p>
]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=116</wfw:commentRss>
		</item>
		<item>
		<title>Switching java version in Mac OS X</title>
		<link>http://satish.name/?p=102</link>
		<comments>http://satish.name/?p=102#comments</comments>
		<pubDate>Sun, 26 Jul 2009 02:18:00 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://satish.name/?p=102</guid>
		<description><![CDATA[Recently I had to switch to newer java version on my Mac. Turns out it is not straight forward so I put together some notes that would help others. Usually java command is located in /usr/bin/java on Mac. This is a symbolic link to java command in one of the java versions installed on your [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had to switch to newer java version on my Mac. Turns out it is not straight forward so I put together some notes that would help others. Usually java command is located in /usr/bin/java on Mac. This is a symbolic link to java command in one of the java versions installed on your computer. To change your java version. use the following commands.<br />
<strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> java
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>System<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Frameworks<span style="color: #000000; font-weight: bold;">/</span>JavaVM.framework<span style="color: #000000; font-weight: bold;">/</span>Versions<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.6</span><span style="color: #000000; font-weight: bold;">/</span>Commands<span style="color: #000000; font-weight: bold;">/</span>java java</pre></div></div>

<p></strong>Now try java -version&#8230; you should see</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">java version <span style="color: #ff0000;">&quot;1.6.0_07&quot;</span>
Java<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> SE Runtime Environment <span style="color: #7a0874; font-weight: bold;">&#40;</span>build 1.6.0_07-b06-<span style="color: #000000;">153</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Java HotSpot<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">64</span>-Bit Server VM <span style="color: #7a0874; font-weight: bold;">&#40;</span>build 1.6.0_07-b06-<span style="color: #000000;">57</span>, mixed mode<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=102</wfw:commentRss>
		</item>
		<item>
		<title>JavaRebel - improves productivity</title>
		<link>http://satish.name/?p=97</link>
		<comments>http://satish.name/?p=97#comments</comments>
		<pubDate>Mon, 13 Jul 2009 05:12:19 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://satish.name/?p=97</guid>
		<description><![CDATA[I have spent some time over the weekend on javarebel from Zeroturnaround guys. I have to say I am quite impressed and it is a must tool for all the java developers. It greatly reduces development time and I bet tools like these will soon become a de facto in development environments. The tool allows [...]]]></description>
			<content:encoded><![CDATA[<p>I have spent some time over the weekend on javarebel from <a href="http://www.zeroturnaround.com">Zeroturnaround </a>guys. I have to say I am quite impressed and it is a must tool for all the java developers. It greatly reduces development time and I bet tools like these will soon become a de facto in development environments. The tool allows to load/replace classes at run-time, no need for server restarts if you are doing web-development :).  </p>
]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=97</wfw:commentRss>
		</item>
		<item>
		<title>Groovy meta-programming tutorial part-1</title>
		<link>http://satish.name/?p=64</link>
		<comments>http://satish.name/?p=64#comments</comments>
		<pubDate>Thu, 16 Apr 2009 03:11:54 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://satish.name/?p=64</guid>
		<description><![CDATA[This is part-1 in a series of tutorials about meta-programming in Groovy. Groovy provides excellent hooks for extending behavior of classes and objects at run-time. First, what is meta-programming? Meta-programming means writing programs that write programs. What this means is that programs are open for either modification or extention at any time during the process [...]]]></description>
			<content:encoded><![CDATA[<p>This is part-1 in a series of tutorials about meta-programming in Groovy. Groovy provides excellent hooks for extending behavior of classes and objects at run-time. First, what is meta-programming? Meta-programming means writing programs that write programs. What this means is that programs are open for either modification or extention at any time during the process of compilation or runtime. Meta-programming allows you to write efficient programs that change behavior dynamically based on needs or input from the environment. Groovy accomplishes this using MOP(Meta Object Protocol). Groovy provides categories, meta-classes, exapandos, mixins, annotations etc. to accomplish this. First in this part I will discuss categories.</p>
<p>1) Categories - Categories allow methods to be added dynamically on any object. Let&#8217;s see the following example. In this example I have a StringUtil class that has method capitalize which capitalizes each word in a string.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> hello <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;hello world HELLO WORLD&quot;</span>
<span style="color: #000000; font-weight: bold;">class</span> StringUtil <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #aaaadd; font-weight: bold;">String</span> capitalize<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> self<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> self.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #663399;">collect</span> <span style="color: #66cc66;">&#123;</span> it<span style="color: #66cc66;">&#91;</span>0<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> it<span style="color: #66cc66;">&#91;</span>1..<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#125;</span>.<span style="color: #663399;">join</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #993399;">use</span><span style="color: #66cc66;">&#40;</span>StringUtil<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #993399;">println</span> hello.<span style="color: #006600;">capitalize</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">// prints &quot;Hello World Hello World&quot;</span></pre></div></div>

<p>Lets see what is happening here <strong>Use</strong> is a method on class Object. <strong>Use</strong> accepts a class and closure as arguments. All the objects with in the closure will have access to the methods on the category class, in this case StringUtil. Groovy accomplishes this by providing a fresh list of properties and methods of the category class on the stack. These are the different ways <strong>Use</strong> can be used. This is taken from groovy jdk API.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">  use<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> categoryClass, Closure closure<span style="color: #009900;">&#41;</span>
    Scoped use method
  use<span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span> categoryClassList, Closure closure<span style="color: #009900;">&#41;</span>
    Scoped use method with list of categories
  use<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> array<span style="color: #009900;">&#41;</span>
    Allows you to use a list of categories, specifying the list as varargs use<span style="color: #009900;">&#40;</span>CategoryClass1, CategoryClass2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">This</span> method saves having to wrap the the category classes in a list</pre></div></div>

<p>Since groovy 1.6 is official now, groovy now provides compile time meta-programming using AST(Abstract Syntax Tree). Using this Categories can be created using @Category annotations. to be contd..</p>
]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=64</wfw:commentRss>
		</item>
		<item>
		<title>Object serialization in groovy</title>
		<link>http://satish.name/?p=66</link>
		<comments>http://satish.name/?p=66#comments</comments>
		<pubDate>Sat, 31 Jan 2009 20:25:25 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Groovy]]></category>

		<category><![CDATA[dynamic languages]]></category>

		<category><![CDATA[Serializaton]]></category>

		<guid isPermaLink="false">http://satish.name/?p=66</guid>
		<description><![CDATA[Here is a small sample code I wrote that shows object serialization in groovy.  when I ran this directly in groovy shell it did not work off the bat. I had to move the class Name to separate file Name.groovy and make sure it is in the class-path to work. Here is the link [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small sample code I wrote that shows object serialization in groovy.  when I ran this directly in groovy shell it did not work off the bat. I had to move the class <strong>Name</strong> to separate file Name.groovy and make sure it is in the class-path to work. Here is the <a href="http://www.nabble.com/Object-serialization-td21752875.html">link</a> to original discussion on groovy forum.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy groovy" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// put this in a file named Name.groovy and compile using groovyc </span>
<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #aaaadd; font-weight: bold;">Name</span> <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #aaaadd; font-weight: bold;">Serializable</span>  <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">def</span> fname, lname
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">// Now run the code below to see the Object serialization and de-serialization.</span>
<span style="color: #000000; font-weight: bold;">def</span> test1<span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Name</span><span style="color: #66cc66;">&#40;</span>fname: <span style="color: #ff0000;">&quot;fn1&quot;</span>, lname : <span style="color: #ff0000;">&quot;ln1&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">def</span> test2 <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">Name</span><span style="color: #66cc66;">&#40;</span>fname: <span style="color: #ff0000;">&quot;fn2&quot;</span>, lname: <span style="color: #ff0000;">&quot;ln2&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">//serialization</span>
<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">File</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;C:/config.txt&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">withObjectOutputStream</span> <span style="color: #66cc66;">&#123;</span> out <span style="color: #66cc66;">-&gt;</span>
    out <span style="color: #66cc66;">&lt;&lt;</span> test1
    out <span style="color: #66cc66;">&lt;&lt;</span> test2
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">//de-serialization</span>
<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">File</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;C:/config.txt&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">withObjectInputStream</span> <span style="color: #66cc66;">&#123;</span> instream <span style="color: #66cc66;">-&gt;</span>
    instream.<span style="color: #006600;">eachObject</span> <span style="color: #66cc66;">&#123;</span> 
        <span style="color: #993399;">println</span> it
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=66</wfw:commentRss>
		</item>
		<item>
		<title>Grails controller actions behind the scenes</title>
		<link>http://satish.name/?p=24</link>
		<comments>http://satish.name/?p=24#comments</comments>
		<pubDate>Sun, 04 Jan 2009 05:00:32 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Grails]]></category>

		<category><![CDATA[Groovy]]></category>

		<category><![CDATA[meta programming]]></category>

		<category><![CDATA[Metaclass]]></category>

		<guid isPermaLink="false">http://satish.name/?p=24</guid>
		<description><![CDATA[All controller actions in grails magically have access to request, params, session and bunch of other utility methods such as redirect, render etc. I digged through the grails source to find how it is done. The functionality is added to controller meta-classes utilizing groovy&#8217;s meta-programming capabilities. It is written as a plugin where in all [...]]]></description>
			<content:encoded><![CDATA[<p>All controller actions in grails magically have access to request, params, session and bunch of other utility methods such as redirect, render etc. I digged through the grails source to find how it is done. The functionality is added to controller meta-classes utilizing groovy&#8217;s meta-programming capabilities. It is written as a plugin where in all the controller meta-classes are attached the functionality we all see. Here is the portion of code that adds some functionality. Imagine writing an action/controller in conventional j2ee style, this small portion of elegant code gets rid of all the boiler plate repetitive code. This simple example shows the power of meta programming. Kudos to all the contributors for this excellent project.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy groovy" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
The method below is called for controller meta classes. and RCH is the RequestContenxtHolder from spring MVC
import org.springframework.web.context.request.RequestContextHolder as RCH
*/</span>
<span style="color: #000000; font-weight: bold;">def</span> registerCommonWebProperties<span style="color: #66cc66;">&#40;</span>MetaClass mc, GrailsApplication application<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">def</span> paramsObject <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">params</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">def</span> flashObject <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">flashScope</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">def</span> sessionObject <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">session</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">def</span> requestObject <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">currentRequest</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">def</span> responseObject <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">currentResponse</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">def</span> servletContextObject <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">servletContext</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">def</span> grailsAttrsObject <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attributes</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #808080; font-style: italic;">// the params object</span>
        mc.<span style="color: #006600;">getParams</span> <span style="color: #66cc66;">=</span> paramsObject
        <span style="color: #808080; font-style: italic;">// the flash object</span>
        mc.<span style="color: #006600;">getFlash</span> <span style="color: #66cc66;">=</span> flashObject
        <span style="color: #808080; font-style: italic;">// the session object</span>
        mc.<span style="color: #006600;">getSession</span> <span style="color: #66cc66;">=</span> sessionObject
        <span style="color: #808080; font-style: italic;">// the request object</span>
        mc.<span style="color: #006600;">getRequest</span> <span style="color: #66cc66;">=</span> requestObject
        <span style="color: #808080; font-style: italic;">// the servlet context</span>
        mc.<span style="color: #006600;">getServletContext</span> <span style="color: #66cc66;">=</span> servletContextObject
        <span style="color: #808080; font-style: italic;">// the response object</span>
        mc.<span style="color: #006600;">getResponse</span> <span style="color: #66cc66;">=</span> responseObject
        <span style="color: #808080; font-style: italic;">// The GrailsApplicationAttributes object</span>
        mc.<span style="color: #006600;">getGrailsAttributes</span> <span style="color: #66cc66;">=</span> grailsAttrsObject
        <span style="color: #808080; font-style: italic;">// The GrailsApplication object</span>
        mc.<span style="color: #006600;">getGrailsApplication</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span> RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attributes</span>.<span style="color: #006600;">grailsApplication</span> <span style="color: #66cc66;">&#125;</span>
        mc.<span style="color: #006600;">getActionName</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">actionName</span>
        <span style="color: #66cc66;">&#125;</span>
        mc.<span style="color: #006600;">getControllerName</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">-&gt;</span>
            RCH.<span style="color: #006600;">currentRequestAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">controllerName</span>
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=24</wfw:commentRss>
		</item>
		<item>
		<title>RubyConf 2008</title>
		<link>http://satish.name/?p=22</link>
		<comments>http://satish.name/?p=22#comments</comments>
		<pubDate>Sun, 14 Dec 2008 18:18:08 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[conf]]></category>

		<guid isPermaLink="false">http://satish.name/?p=22</guid>
		<description><![CDATA[Checkout the video of keynote by Dave Thomas and Matz&#8217;s at RubyConf this year at Orlando. Dave talks about forking ruby and creating new projects. Matz&#8217;s talks about reasons behind Ruby. The videos are provided by confreaks in a well formatted way.
Dave&#8217;s Keynote: One of the things I noticed after professionally working with Grails and [...]]]></description>
			<content:encoded><![CDATA[<p>Checkout the video of keynote by <a href="http://pragdave.pragprog.com/">Dave Thomas</a> and <a href="http://en.wikipedia.org/wiki/Yukihiro_Matsumoto" title="Yukihiro 'Matz' Matsumoto">Matz&#8217;s</a> at RubyConf this year at Orlando. Dave talks about forking ruby and creating new projects. Matz&#8217;s talks about reasons behind Ruby. The videos are provided by <a href="http://www.confreaks.com/">confreaks</a> in a well formatted way.</p>
<p><strong>Dave&#8217;s Keynote:</strong> One of the things I noticed after professionally working with Grails and Groovy the elegance of Groovy&#8217;s Closure syntax. Dave talks among a lot of other things about introducing such changes to ruby&#8217;s closure syntax in one of the forked project ideas.</p>
<p><embed src="http://rubyconf2008.confreaks.com/player.swf" allowscriptaccess="always" allowfullscreen="true" flashvars="image=images%2Fkeynote-preview.jpg&amp;file=http%3A%2F%2Frubyconf2008.confreaks.com%2Fvideos%2Fkeynote-small.mp4&amp;plugins=viral-1" width="640" height="260"></embed></p>
<p><strong>Matz&#8217;s Keynote:</strong></p>
<p><embed src="http://rubyconf2008.confreaks.com/player.swf" allowscriptaccess="always" allowfullscreen="true" flashvars="image=images%2Fmatzs-keynote-preview.jpg&amp;file=http%3A%2F%2Frubyconf2008.confreaks.com%2Fvideos%2Fmatzs-keynote-small.mp4&amp;plugins=viral-1" width="640" height="260"></embed></p>
]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=22</wfw:commentRss>
		</item>
		<item>
		<title>Case insensitive usernames, grails acegi plugin</title>
		<link>http://satish.name/?p=21</link>
		<comments>http://satish.name/?p=21#comments</comments>
		<pubDate>Fri, 05 Dec 2008 01:22:28 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://satish.name/?p=21</guid>
		<description><![CDATA[To make acegi grails plugin work for case insensitive user-names, I used the following code snippet to override/redefine the loadDomainUser method. I put this in bootstrap and it worked like a gem.
Note: there are other methods in GrailsDaoImpl that need to be redefined if you use them.

GrailsDaoImpl.metaClass.loadDomainUser = &#123; username, session -&#62;
    def [...]]]></description>
			<content:encoded><![CDATA[<p>To make acegi grails plugin work for case insensitive user-names, I used the following code snippet to override/redefine the loadDomainUser method. I put this in bootstrap and it worked like a gem.<br />
Note: there are other methods in GrailsDaoImpl that need to be redefined if you use them.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy groovy" style="font-family:monospace;">GrailsDaoImpl.<span style="color: #006600;">metaClass</span>.<span style="color: #006600;">loadDomainUser</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> username, session <span style="color: #66cc66;">-&gt;</span>
    <span style="color: #000000; font-weight: bold;">def</span> clazz <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006600;">forName</span><span style="color: #66cc66;">&#40;</span>loginUserDomainClass, <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #000000; font-weight: bold;">new</span> GroovyClassLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">def</span> crit <span style="color: #66cc66;">=</span> clazz.<span style="color: #006600;">createCriteria</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">def</span> users <span style="color: #66cc66;">=</span> crit.<span style="color: #006600;">list</span> <span style="color: #66cc66;">&#123;</span>
        ilike<span style="color: #66cc66;">&#40;</span>usernameFieldName, username<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>users.<span style="color: #006600;">empty</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        logger.<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;User not found: ${username}&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> UsernameNotFoundException<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;User not found.&quot;</span>, username<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> users<span style="color: #66cc66;">&#91;</span>0<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=21</wfw:commentRss>
		</item>
		<item>
		<title>jQuery datepicker issue in IE(Internet explorer)</title>
		<link>http://satish.name/?p=19</link>
		<comments>http://satish.name/?p=19#comments</comments>
		<pubDate>Tue, 11 Nov 2008 23:35:34 +0000</pubDate>
		<dc:creator>satish</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://satish.name/?p=19</guid>
		<description><![CDATA[jQuery datepicker adds a new attribute to the DOM element in IE. if you try to add a new DOM element dynamically copying from an existing element the datepicker will not work in IE as the newly added DOM element refers to the old jQuery attribute. One way to fix this is to delete the [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery datepicker adds a new attribute to the DOM element in IE. if you try to add a new DOM element dynamically copying from an existing element the datepicker will not work in IE as the newly added DOM element refers to the old jQuery attribute. One way to fix this is to delete the attribute and then instantiate the datepicker class on the element. See the following code for the fix.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//newDiv is the new added dom element with innerHTML</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#newDiv&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.datePicker&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//removing jquery added attribute as this is causing the dynamically</span>
    <span style="color: #006600; font-style: italic;">// added DOM elem referring old DOM element from it is copied.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jQuery.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> jqaddedattr;
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">attributes</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span>.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/jQuery/</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                jqaddedattr <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jqaddedattr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span>jqaddedattr.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>yearRange<span style="color: #339933;">:</span> <span style="color: #3366CC;">'-100:+10'</span><span style="color: #339933;">,</span> changeFirstDay<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'change'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://satish.name/?feed=rss2&amp;p=19</wfw:commentRss>
		</item>
	</channel>
</rss>
