<?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>Kevin&#039;s Blog &#187; JavaBean</title>
	<atom:link href="http://blog.lckymn.com/tag/javabean/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.lckymn.com</link>
	<description>IT, Java, Ubuntu, Linux</description>
	<lastBuildDate>Thu, 12 Jan 2012 05:48:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Method Chaining, to use, or not to use</title>
		<link>http://blog.lckymn.com/2009/06/30/method-chaining-to-use-or-not-to-use/</link>
		<comments>http://blog.lckymn.com/2009/06/30/method-chaining-to-use-or-not-to-use/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:33:28 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Coding Style]]></category>
		<category><![CDATA[Command-Query Separation]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Fluent Interface]]></category>
		<category><![CDATA[Formatter]]></category>
		<category><![CDATA[Formatting]]></category>
		<category><![CDATA[JavaBean]]></category>
		<category><![CDATA[Method Chaining]]></category>
		<category><![CDATA[Readable]]></category>

		<guid isPermaLink="false">http://blog.lckymn.com/?p=347</guid>
		<description><![CDATA[<p>It was a Gavin King&#8217;s book from which I first heard about <a href="http://en.wikipedia.org/wiki/Method_chaining" target="_blank">method chaining</a> since it is not that popular style in Java.</p> <p>Bauer and King in their book entitled &#8216;Java Persistence with Hibernate&#8217; (2007), point out that method chaining is convenient in some cases and is more popular in <a href="http://en.wikipedia.org/wiki/Smalltalk" target="_blank">Smalltalk</a> than in <a href="http://en.wikipedia.org/wiki/Java_(programming_language)" target="_blank">Java</a> for Smalltalk, unlike Java, does not have <code>void</code> type. Thus when a method is invoked, it normally returns the object <p style="border: 3px solid rgb(243, 197, 52); padding: 5px; background-color: rgb(254, 254, 184); width: 600px; text-align: center;">[...Continue reading <a href="http://blog.lckymn.com/2009/06/30/method-chaining-to-use-or-not-to-use/">Method Chaining, to use, or not to use</a>...]</p>]]></description>
			<content:encoded><![CDATA[<p>It was a Gavin King&#8217;s book from which I first heard about <a href="http://en.wikipedia.org/wiki/Method_chaining" target="_blank">method chaining</a> since it is not that popular style in Java.</p>
<p>Bauer and King in their book entitled &#8216;Java Persistence with Hibernate&#8217; (2007), point out that method chaining is convenient in some cases and is more popular in <a href="http://en.wikipedia.org/wiki/Smalltalk" target="_blank">Smalltalk</a> than in <a href="http://en.wikipedia.org/wiki/Java_(programming_language)" target="_blank">Java</a> for Smalltalk, unlike Java, does not have <code>void</code> type. Thus when a method is invoked, it normally returns the object itself in which the method is placed.</p>
<p>Although it is used to improve readability and to reduce the amount of source code, I didn&#8217;t really like this style as it can be less readable and might make code difficult to debug. How can the technique to improve readability make the code less readable? By less readable, I mean the code may possibly be unpredictable or make the programmer confused in some cases.</p>
<p>Let&#8217;s look at some example.</p>
<p>This is a simple JavaBean named <code>Item</code></p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.methodchaining;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public class Item
{
	private int id;
	private String name;

	public Item(int id, String name)
	{
		this.id = id;
		this.name = name;
	}

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	@Override
	public String toString()
	{
		return &quot;ID: &quot; + id + &quot;\n&quot; + &quot;Name: &quot; + name + &quot;\n&quot;;
	}
}
</pre>
<p>This is a Storage class designed to use method chaining.</p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.methodchaining;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public class Storage
{
	private List&lt;Item&gt; items;

	public Storage()
	{
		this.items = new ArrayList&lt;Item&gt;();
	}

	public Storage put(String name)
	{
		items.clear();
		return and(name);
	}

	public Storage and(String name)
	{
		items.add(new Item(name.hashCode(), name));
		return this;
	}

	public Item get(int index)
	{
		return items.get(index);
	}

	public List&lt;Item&gt; getAll()
	{
		return items;
	}
}
</pre>
<p>Now, let&#8217;s use it.</p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.methodchaining;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public final class MethodChainingTest
{
	public static void main(String[] args)
	{
		String name = new Storage().put(&quot;A&quot;).and(&quot;B&quot;).and(null).and(&quot;D&quot;).get(0).getName();
		System.out.println(&quot;Name: &quot; + name + &quot;\n&quot;);

		System.exit(0);
	}

}
</pre>
<p>What is this? It looks like instantiating a <code>Storage</code> object yet the end it assigns <code>String</code> value to <code>String</code> variable named <code>name</code>?</p>
<p>It seems confusing. First, instantiate <code>Storage</code>. Then call several methods in it. Finally call the method which returns a <code>String</code> value. However, the <code>Storage</code> class doesn&#8217;t even have any method returning the <code>String</code> value. It is the method in the <code>Item</code> class.</p>
<p>OK, move to the other problem that is difficulty in debuging.<br />
The example code above does not have any compile time error yet when it runs the result is </p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
Exception in thread &quot;main&quot; java.lang.NullPointerException
	at com.lckymn.kevin.test.methodchaining.Storage.and(Storage.java:26)
	at com.lckymn.kevin.test.methodchaining.MethodChainingTest.main(MethodChainingTest.java:10)
</pre>
<p>The tenth line in the <code>MethodChainingTest.main</code> method is this.</p>
<pre class="brush: java; first-line: 10; highlight: [10]; title: ; notranslate">
		String name = new Storage().put(&quot;A&quot;).and(&quot;B&quot;).and(null).and(&quot;D&quot;).get(0).getName();
</pre>
<p>The twenty-sixth line in the <code>Storage.and</code> method is this.</p>
<pre class="brush: java; first-line: 26; highlight: [26]; title: ; notranslate">
		items.add(new Item(name.hashCode(), name));
</pre>
<p>So this line of the code causes <code>NullPointerException</code> but <code>and()</code> method is called three times in the tenth line of the <code>MethodChainingTest</code> class. Which one of these causes the error? In the example, it is very obvious that the <code>and()</code> method call with <code>null</code> parameter is the one. However, in real-life programme, it is usually much more difficult to find.</p>
<p>So, as already mentioned, I did not like using method chaining.  Then again there came a time when it was very convenient and useful to use method chaining. I found it very useful when I was making a XML generator programme for an Ajax application. I made it using <a href="http://en.wikipedia.org/wiki/JAXP" target="_blank">Java API for XML Processing (JAXP)</a>. It required to generate simple XML based on a given object so it might be too much to use <a href="http://en.wikipedia.org/wiki/XML_data_binding" target="_blank">XML data binding</a> frameworks and tools such as <a href="http://en.wikipedia.org/wiki/JAXB" target="_blank">Java Architecture for XML Binding (JAXB)</a> and <a href="http://en.wikipedia.org/wiki/XStream" target="_blank">XStream</a>. Although both JAXB and XStream are simple and easy to use and can be used to serialise objects, I wanted to have more control than what the framework provides. JAXP with <a href="http://en.wikipedia.org/wiki/Simple_API_for_XML" target="_blank">Simple API for XML (SAX)</a> parsing interface was just suitable for what I needed, yet it is not very pleasant to use the SAX interface. It uses ContentHandler interface when making XML contents and the following code is what it looks like when using it.</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
contentHandler.startDocument();

AttributesImpl atts = new AttributesImpl();
atts.addAttribute(null, null, &quot;type&quot;, null, &quot;User&quot;);
contentHandler.startElement(null, null, &quot;users&quot;, atts);

atts.clear();
atts.addAttribute(null, null, &quot;id&quot;, null, &quot;kevin&quot;);
atts.addAttribute(null, null, &quot;surname&quot;, null, &quot;Lee&quot;);
atts.addAttribute(null, null, &quot;givenName&quot;, null, &quot;Kevin&quot;);
contentHandler.startElement(null, null, &quot;user&quot;, atts);
contentHandler.characters(&quot;Test value&quot;.toCharArray(), 0, &quot;Test value&quot;.length());
contentHandler.endElement(null, null, &quot;user&quot;);

atts.clear();
atts.addAttribute(null, null, &quot;id&quot;, null, &quot;john&quot;);
atts.addAttribute(null, null, &quot;surname&quot;, null, &quot;Doe&quot;);
atts.addAttribute(null, null, &quot;givenName&quot;, null, &quot;John&quot;);
contentHandler.startElement(null, null, &quot;user&quot;, atts);
contentHandler.characters(&quot;Blah Blah&quot;.toCharArray(), 0, &quot;Blah Blah&quot;.length());
contentHandler.endElement(null, null, &quot;user&quot;);

atts.clear();
atts.addAttribute(null, null, &quot;id&quot;, null, &quot;tom&quot;);
atts.addAttribute(null, null, &quot;surname&quot;, null, &quot;Smith&quot;);
atts.addAttribute(null, null, &quot;givenName&quot;, null, &quot;Tom&quot;);
contentHandler.startElement(null, null, &quot;user&quot;, atts);
contentHandler.characters(&quot;12345&quot;.toCharArray(), 0, &quot;12345&quot;.length());
contentHandler.endElement(null, null, &quot;user&quot;);

contentHandler.endElement(null, null, &quot;users&quot;);

contentHandler.endDocument();
</pre>
<p>As all I want was simple XML for an Ajax application, I had to type &#8216;<code>null</code>&#8216; many times as parameter values for namespace URI and local name which were definitely unnecessary for my programme. Since the data transfered through network need to be small, XML sent to the front-end Ajax application had better not have the data such as namespace and schema location information and so on.</p>
<p>However, what I all had was, as shown above, the ugly code which repeatedly calls same methods with many &#8216;null&#8217; parameters. So I tried to find a better way and eventually came up with that it might be a good idea to use method chaining.  Even so, there were still the two problems I mentioned.</p>
<p>The method chaining code example that I showed earlier is, in fact, a misuse of method chaining. That can be much better if it is used properly. After all, it is not the technique that makes the code less maintainable but how it is used that makes the code less maintainable.</p>
<p>Think about this. If a knife is used by a murderer, the result of using it would be a dead body while if it is used by a chef, the result would be a delicious meal unless the chef is the murderer. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (I think I used this sentence when I had my presentation in the third year in my undergraduate days. The subject was about IT and ethics, and I was emphasising that technologies have nothing to do with ethics yet how we use these is important when it comes to ethics).</p>
<p>So, how can those two problems be solved? First of all, please don&#8217;t get me wrong. I am not saying that the way I am going to tell here is the best, but it is just what I do. That&#8217;s it.</p>
<p>I chose to implement <a href="http://en.wikipedia.org/wiki/Fluent_interface" target="_blank">fluent interface</a> yet with my own taste.</p>
<div class="txc-textbox" style="border: 3px solid rgb(243, 197, 52); padding: 10px; background-color: rgb(254, 254, 184);">
Cho, YoungHo (2008) in his article, &#8216;<a href="http://aeternum.egloos.com/1173825" target="_blank">Applicaiton of Domain-Driven Design 2.Aggregate and Repository #3</a>&#8216;, also says that although <a href="http://en.wikipedia.org/wiki/Fluent_interface" target="_blank">FLUENT INTERFACE</a> might violate the principle of <a href="http://en.wikipedia.org/wiki/Command-query_separation" target="_blank">COMMAND-QUERY SEPARATION</a> which enforces to separate the method to change the state of an object from the method to query the state, FLUENT INTERFACE using method chaining can enable the interface design to be more readable and easier to use.</p>
<p>If you can understand Korean and are interested in <a href="http://en.wikipedia.org/wiki/Domain-driven_design" target="_blank">Domain-Driven Design (DDD)</a>, his articles about DDD are really worth reading.<br />
<a href="http://aeternum.egloos.com/category/Domain-Driven%20Design" target="_blank">http://aeternum.egloos.com/category/Domain-Driven%20Design</a><br />
It is well written with appropriate example code and supporting theories and principles.
</div>
<p>So my tastes are<br />
1. The prefix &#8216;Fluent&#8217; shall be used to tell it is a fluent interface.<br />
e.g.)<br />
public interface FluentContentHandler<br />
public interface FluentStorage</p>
<p>2. <code>void</code> return type shall be used to stop method chaining if the method should not be used with other methods in the fluent interface or if it has some side-effect when using with other methods so that the programmer should be noticed it by void return type.<br />
e.g.)<br />
void endDoc()<br />
void finish()</p>
<p>3. Otherwise, all the methods shall return the type of interface itself, and the name of the normal methods which return the type of the interface itself shall begin with verb.<br />
e.g.)<br />
FluentContentHandler openElem(String qName)<br />
FluentContentHandler setText(String qName)<br />
FluentSaxAttributes create(String qName, String value)</p>
<p>OR<br />
The name of the method which must be used before the other methods shall begin with a verb.<br />
e.g.)<br />
FluentSaxAttributes create(String qName, String value)<br />
The name of the method which must be used after the method the name of which begins with a verb shall be an appropriate preposition or conjunction.<br />
e.g.)<br />
FluentSaxAttributes with(String qName, String value)<br />
FluentSaxAttributes and(String qName, String value)</p>
<p>4. If other types than the interface itself need to be returned, distinguishable method names shall be used. The name of the methods which return other type than the type of the interface itself shall begin with a preposition followed by a noun.<br />
e.g.)<br />
List toList()<br />
Map toMap()<br />
Collection toCollection()</p>
<p>I believe, these can help me to get over the first matter, and the code would be more readable as expected.</p>
<p>So let&#8217;s have a look at the new fluent interfaces for my XML generator programme.</p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.xml;

import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public interface FluentSaxContentHandler
{
	void startDoc() throws SAXException;

	void endDoc() throws SAXException;

	FluentSaxContentHandler openElem(String qName) throws SAXException;

	FluentSaxContentHandler openElem(String qName, FluentSaxAttributes attributes) throws SAXException;

	FluentSaxContentHandler setText(String text) throws SAXException;

	void closeElem(String qName) throws SAXException;
}
</pre>
<p>The programmer using this interface had better be aware of that <code>startDoc()</code> and <code>endDoc()</code> methods are to start and to end the XML document so use it once and therefore these return <code>void</code> type to warn. Similarly, <code>closeElem()</code> method the type of which is <code>void</code> closes the element with the name given as the parameter so the programmer had better stop method chaining here and open a new element with another method chaining.</p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.xml;

import org.xml.sax.helpers.AttributesImpl;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public interface FluentSaxAttributes
{
	FluentSaxAttributes create(String qName, String value);

	FluentSaxAttributes add(String qName, String value);

	AttributesImpl toAttributesImpl();
}
</pre>
<p>Since the <code>ContentHandler</code> requires <code>AttributesImpl</code> as attributes <code>toAttributesImpl()</code> method needs to return <code>AttributesImpl</code> and therefore its name consists of the preposition &#8216;to&#8217; and the noun &#8216;AttributesImpl&#8217;.</p>
<p>Now let&#8217;s use these.</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
	contentHandler.startDoc();

	contentHandler.openElem(&quot;users&quot;, atts.create(&quot;type&quot;, &quot;User&quot;));

	contentHandler.openElem(&quot;user&quot;, atts.create(&quot;id&quot;, &quot;kevin&quot;).add(&quot;surname&quot;, &quot;Lee&quot;).add(&quot;givenName&quot;, &quot;Kevin&quot;)).setText(&quot;Test value&quot;).closeElem(&quot;user&quot;);
	contentHandler.openElem(&quot;user&quot;, atts.create(&quot;id&quot;, &quot;john&quot;).add(&quot;surname&quot;, &quot;Doe&quot;).add(&quot;givenName&quot;, &quot;John&quot;)).setText(&quot;Blah Blah&quot;).closeElem(&quot;user&quot;);
	contentHandler.openElem(&quot;user&quot;, atts.create(&quot;id&quot;, &quot;tom&quot;).add(&quot;surname&quot;, &quot;Smith&quot;).add(&quot;givenName&quot;, &quot;Tom&quot;)).setText(&quot;12345&quot;).closeElem(&quot;user&quot;);

	contentHandler.closeElem(&quot;users&quot;);

	contentHandler.endDoc();
</pre>
<p>It looks much simpler and readable than the previous code below.</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
	contentHandler.startDocument();

	AttributesImpl atts = new AttributesImpl();
	atts.addAttribute(null, null, &quot;type&quot;, null, &quot;User&quot;);
	contentHandler.startElement(null, null, &quot;users&quot;, atts);

	atts.clear();
	atts.addAttribute(null, null, &quot;id&quot;, null, &quot;kevin&quot;);
	atts.addAttribute(null, null, &quot;surname&quot;, null, &quot;Lee&quot;);
	atts.addAttribute(null, null, &quot;givenName&quot;, null, &quot;Kevin&quot;);
	contentHandler.startElement(null, null, &quot;user&quot;, atts);
	contentHandler.characters(&quot;Test value&quot;.toCharArray(), 0, &quot;Test value&quot;.length());
	contentHandler.endElement(null, null, &quot;user&quot;);

	atts.clear();
	atts.addAttribute(null, null, &quot;id&quot;, null, &quot;john&quot;);
	atts.addAttribute(null, null, &quot;surname&quot;, null, &quot;Doe&quot;);
	atts.addAttribute(null, null, &quot;givenName&quot;, null, &quot;John&quot;);
	contentHandler.startElement(null, null, &quot;user&quot;, atts);
	contentHandler.characters(&quot;Blah Blah&quot;.toCharArray(), 0, &quot;Blah Blah&quot;.length());
	contentHandler.endElement(null, null, &quot;user&quot;);

	atts.clear();
	atts.addAttribute(null, null, &quot;id&quot;, null, &quot;tom&quot;);
	atts.addAttribute(null, null, &quot;surname&quot;, null, &quot;Smith&quot;);
	atts.addAttribute(null, null, &quot;givenName&quot;, null, &quot;Tom&quot;);
	contentHandler.startElement(null, null, &quot;user&quot;, atts);
	contentHandler.characters(&quot;12345&quot;.toCharArray(), 0, &quot;12345&quot;.length());
	contentHandler.endElement(null, null, &quot;user&quot;);

	contentHandler.endElement(null, null, &quot;users&quot;);

	contentHandler.endDocument();
</pre>
<p>Yet there is one more problem still left that is difficulty in debugging.</p>
<p>King and Bauer (2007) suggests that &#8220;it’s better to write each method invocation on a different line&#8221;.</p>
<p>So rewrite the code</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
	contentHandler.startDoc();

	contentHandler.openElem(&quot;users&quot;, atts.create(&quot;type&quot;, &quot;User&quot;));

	contentHandler.openElem(&quot;user&quot;, atts.create(&quot;id&quot;, &quot;kevin&quot;)
			.add(&quot;surname&quot;, &quot;Lee&quot;)
			.add(&quot;givenName&quot;, &quot;Kevin&quot;))
			.setText(&quot;Test value&quot;)
			.closeElem(&quot;user&quot;);
	contentHandler.openElem(&quot;user&quot;, atts.create(&quot;id&quot;, &quot;john&quot;)
			.add(&quot;surname&quot;, &quot;Doe&quot;)
			.add(&quot;givenName&quot;, &quot;John&quot;))
			.setText(&quot;Blah Blah&quot;)
			.closeElem(&quot;user&quot;);
	contentHandler.openElem(&quot;user&quot;, atts.create(&quot;id&quot;, &quot;tom&quot;)
			.add(&quot;surname&quot;, &quot;Smith&quot;)
			.add(&quot;givenName&quot;, &quot;Tom&quot;))
			.setText(&quot;12345&quot;)
			.closeElem(&quot;user&quot;);

	contentHandler.closeElem(&quot;users&quot;);

	contentHandler.endDoc();
</pre>
<p>Now not only does it solve the problem in debugging but it is also even more readable. My problem solved! <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
Well, unfortunately there is one more problem. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I am using Eclipse and it has a nice automatic formatting feature. So whenever I press SHIFT+CTRL+F, it automatically formats the code opened in the editor based on the format configuration. This means if I use that function, I lose the coding style of writing each method invocation on a different line as Eclipse formatter puts all the method on a different line together on one line. So do I have to reformat by myself after every automatic formatting? It&#8217;s really annoying. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Fortunately, a few changes in formatter configuration can solve this problem.</p>
<p>Click the &#8216;Window&#8217; menu -> &#8216;Preferences&#8217;</p>
<p>When the &#8216;Preferences&#8217; menu pops up<br />
-Expand the &#8216;Java&#8217; -> Expand the &#8216;Code Style&#8217; -> Select the &#8216;Fomatter&#8217;</p>
<p>-Click the &#8216;Edit&#8217; button on the top right-hand side.<br />
<div id="attachment_353" class="wp-caption alignnone" style="width: 693px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/06/formatter_configuration_01.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/06/formatter_configuration_01.jpg" alt="Expand the &#039;Java&#039; -&gt; Expand the &#039;Code Style&#039; -&gt; Select the &#039;Fomatter&#039; -&gt; Click the &#039;Edit&#039; button on the top right-hand side" title="Formatter Configuration for Method Chaining 01" width="683" height="740" class="size-full wp-image-353" /></a><p class="wp-caption-text">Expand the 'Java' -> Expand the 'Code Style' -> Select the 'Fomatter' -> Click the 'Edit' button on the top right-hand side</p></div></p>
<p>-The profile window appears -> Select the &#8216;Line Wrapping&#8217; -> Expand the &#8216;Function Calls&#8217; -> Select the &#8216;Qualified invocations&#8217; -> Select the &#8216;Wrap all elements, except first element if not necessary&#8217; as the &#8216;Line wrapping policy&#8217; -> Select the &#8216;Default indentation&#8217; as the &#8216;Indentation policy&#8217; -> Check the &#8216;Force split&#8217; -> Click the &#8216;OK&#8217; button.<br />
<div id="attachment_354" class="wp-caption alignnone" style="width: 757px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/06/formatter_configuration_02.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/06/formatter_configuration_02.jpg" alt="Profile window appears -&gt; Select the &#039;Line Wrapping&#039; -&gt; Expand the &#039;Function Calls&#039; -&gt; Select the &#039;Qualified invocations&#039; -&gt; Select the &#039;Wrap all elements, except first element if not necessary&#039; as the &#039;Line wrapping policy&#039; -&gt; Select the &#039;Default indentation&#039; as the &#039;Indentation policy&#039; -&gt; Check the &#039;Force split&#039; -&gt; Click the &#039;OK&#039; button" title="Formatter Configuration for Method Chaining 02" width="747" height="834" class="size-full wp-image-354" /></a><p class="wp-caption-text">Profile window appears -> Select the 'Line Wrapping' -> Expand the 'Function Calls' -> Select the 'Qualified invocations' -> Select the 'Wrap all elements, except first element if not necessary' as the 'Line wrapping policy' -> Select the 'Default indentation' as the 'Indentation policy' -> Check the 'Force split' -> Click the 'OK' button</p></div></p>
<p>-Click the &#8216;OK&#8217; button to apply the changes.</p>
<p>Now, the Eclipse Java formatter formats the code, using method chaining, as what I want.</p>
<p>Finally, how can I improve my first example of method chaining?<br />
The Item class does not need to be changed.</p>
<p>Write the fluent interface, FluentStorage.</p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.fluentinterface;

import java.util.List;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public interface FluentStorage
{
	FluentStorage add(String name);

	List&lt;Item&gt; toList();
}
</pre>
<p>Write the class implements it.</p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.fluentinterface;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public class FluentListStorage implements FluentStorage
{
	private List&lt;Item&gt; items;

	public FluentListStorage()
	{
		items = new ArrayList&lt;Item&gt;();
	}

	@Override
	public FluentStorage add(String name)
	{
		items.add(new Item(name.hashCode(), name));
		return this;
	}

	@Override
	public List&lt;Item&gt; toList()
	{
		return items;
	}

}
</pre>
<p>Now use the fluent interface.</p>
<pre class="brush: java; title: ; notranslate">
package com.lckymn.kevin.test.fluentinterface;

import java.util.List;

/**
 * @author Lee, SeongHyun (Kevin)
 */
public final class MethodChainingTest
{
	public static void main(String[] args)
	{
		FluentStorage fluentStorage = new FluentListStorage().add(&quot;A&quot;)
				.add(&quot;B&quot;)
				.add(null)
				.add(&quot;D&quot;);

		List&lt;Item&gt; items = fluentStorage.toList();
		for (Item item : items)
		{
			System.out.println(item);
		}
		int howMany = items.size();
		System.out.println(&quot;There &quot; + (1 &lt; howMany ? &quot;are &quot; + howMany + &quot; items&quot; : &quot;is &quot; + howMany + &quot; item&quot;) + &quot; in the storage.&quot;);
		System.exit(0);
	}

}
</pre>
<p>When it runs, it displays the following error messages yet now I know that the fourteenth line causes the error.</p>
<pre class="brush: bash; gutter: false; highlight: [3]; title: ; notranslate">
Exception in thread &quot;main&quot; java.lang.NullPointerException
	at com.lckymn.kevin.test.fluentinterface.FluentListStorage.add(FluentListStorage.java:21)
	at com.lckymn.kevin.test.fluentinterface.MethodChainingTest.main(MethodChainingTest.java:14)
</pre>
<p>The fourteenth line is this.</p>
<pre class="brush: java; first-line: 14; title: ; notranslate">
				.add(null)
</pre>
<p>So change it to</p>
<pre class="brush: java; first-line: 14; title: ; notranslate">
				.add(&quot;C&quot;)
</pre>
<p>I could finally have the correct result.</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
ID: 65
Name: A

ID: 66
Name: B

ID: 67
Name: C

ID: 68
Name: D

There are 4 items in the storage.
</pre>
<p>So method chaining, to use, or not to use? It&#8217;s all up to you. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>References</strong><br />
Bauer, C. and King, G. 2007, <i>Java Persistence with Hibernate</i>, Manning Publications Co., New York.</p>
<p>Cho, Y. 2008, <i>Applicaiton of Domain-Driven Design 2. Aggregate and Repository #3</i>, viewed 29 June 2009, &lt;<a href="http://aeternum.egloos.com/1173825" target="_blank">http://aeternum.egloos.com/1173825</a>&gt;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lckymn.com/2009/06/30/method-chaining-to-use-or-not-to-use/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ROO So Cool!!! -04-</title>
		<link>http://blog.lckymn.com/2009/05/17/roo-so-cool-04/</link>
		<comments>http://blog.lckymn.com/2009/05/17/roo-so-cool-04/#comments</comments>
		<pubDate>Sun, 17 May 2009 01:03:43 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[AJDT]]></category>
		<category><![CDATA[AspectJ]]></category>
		<category><![CDATA[AspectJ Development Tools]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Eclipse JEE]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Inter-type declarations]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaBean]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[M2Eclipse]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Maven Integration for Eclipse]]></category>
		<category><![CDATA[Maven2]]></category>
		<category><![CDATA[Mixin]]></category>
		<category><![CDATA[Multiple Inheritance]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring ROO]]></category>
		<category><![CDATA[SpringSource Tool Suite]]></category>
		<category><![CDATA[STS]]></category>

		<guid isPermaLink="false">http://blog.lckymn.com/?p=283</guid>
		<description><![CDATA[<p>Continued from <a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-03/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-03/</a></p> <p>There are two other aspects which are <code>Choice_Roo_Plural</code> and <code>Choice_Roo_ToString</code>.</p> <p><div id="attachment_243" class="wp-caption alignnone" style="width: 913px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-22.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-22.jpg" alt="&#34;Choice&#34; in Plural Form, &#34;Choices&#34;" title="&#34;Choice&#34; in Plural Form, &#34;Choices&#34;" width="903" height="417" class="size-full wp-image-243" /></a><p class="wp-caption-text">&#34;Choice&#34; in Plural Form, &#34;Choices&#34;</p></div> <code>Choice_Roo_Plural</code> declares that the <code>Choice</code> has a method named <code>getPluralName()</code> which returns a String type value, &#8220;Choices&#8221; which is the plural form of &#8220;Choice&#8221;. I don&#8217;t really get why it is necessary though. I first thought it <p style="border: 3px solid rgb(243, 197, 52); padding: 5px; background-color: rgb(254, 254, 184); width: 600px; text-align: center;">[...Continue reading <a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-04/">ROO So Cool!!! -04-</a>...]</p>]]></description>
			<content:encoded><![CDATA[<p>Continued from<br />
<a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-03/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-03/</a></p>
<p>There are two other aspects which are <code>Choice_Roo_Plural</code> and <code>Choice_Roo_ToString</code>.</p>
<p><div id="attachment_243" class="wp-caption alignnone" style="width: 913px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-22.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-22.jpg" alt="&quot;Choice&quot; in Plural Form, &quot;Choices&quot;" title="&quot;Choice&quot; in Plural Form, &quot;Choices&quot;" width="903" height="417" class="size-full wp-image-243" /></a><p class="wp-caption-text">&quot;Choice&quot; in Plural Form, &quot;Choices&quot;</p></div><br />
<code>Choice_Roo_Plural</code> declares that the <code>Choice</code> has a method named <code>getPluralName()</code> which returns a String type value, &#8220;Choices&#8221; which is the plural form of &#8220;Choice&#8221;. I don&#8217;t really get why it is necessary though.  I first thought it might be the name of the table with which the <code>Choice_Roo_Entity</code> matches, yet the table name is <code>choice</code>.</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
Bind entity com.springsource.vote.domain.Choice on table choice
</pre>
<p>It is probably for the future use as a name of domain object in plural form may be frequently required when displaying the list of it.</p>
<p>Now, let&#8217;s look at the last aspect.<br />
<div id="attachment_244" class="wp-caption alignnone" style="width: 919px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-23.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-23.jpg" alt="toString() method for Choice" title="toString() method for Choice" width="909" height="417" class="size-full wp-image-244" /></a><p class="wp-caption-text">toString() method for Choice</p></div><br />
The last one is <code>Choice_Roo_ToString</code> which declare that Choice has <code>toString()</code> method.</p>
<pre class="brush: java; title: ; notranslate">
privileged aspect Choice_Roo_ToString {

    public java.lang.String Choice.toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(&quot;id: &quot;).append(getId()).append(&quot;, &quot;);
        sb.append(&quot;version: &quot;).append(getVersion()).append(&quot;, &quot;);
        sb.append(&quot;namingChoice: &quot;).append(getNamingChoice()).append(&quot;, &quot;);
        sb.append(&quot;description: &quot;).append(getDescription()).append(&quot;, &quot;);
        return sb.toString();
    }    

}
</pre>
<p>It returns String containing the information about <code>Choice</code> which includes all the values of the variables from the aspects as well. This String is used to display the information about Choice object in the view, <code>WEB-INF/jsp/vote/create.jsp</code>.</p>
<p>All these mixins can be good Separation of Concerns (SoC).  Each aspect has what should be a concern in a particular mixin only. For example, id and version of Choice are not really a concern of <code>Choice</code> itself as it does not have any meaning for Choice, yet it is very important for OR mapping. Thus it is separated from <code>Choice</code> and only occurs in <code>Choice_Roo_Entity</code> which plays the role of a persistent object.</p>
<p>It is not a completely new ways to write mixin using inter-type declarations in AspectJ (<a href="http://today.java.net/pub/a/today/2005/12/15/writing-mixins-with-aop.html" target="_blank">http://today.java.net/pub/a/today/2005/12/15/writing-mixins-with-aop.html</a>). Nevertheless, Spring ROO is still so cool as I have never seen any automatically generated code by Java frameworks uses mixins written using inter-type declarations as a nice way of SoC. I may need to call ROO RSoC (Real Separation of Concerns). <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>OK, I am now running out of time so had better finish this post quickly.  </p>
<p>I would just finally like to point out some minor issues I found.</p>
<p>1. An error in dojo JS toolkit.<br />
<div id="attachment_165" class="wp-caption alignnone" style="width: 851px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-15.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-15.jpg" alt="dojo JS Toolkit Error" title="dojo JS Toolkit Error" width="841" height="588" class="size-full wp-image-165" /></a><p class="wp-caption-text">dojo JS Toolkit Error</p></div></p>
<p>2. An error in roo.css file.<br />
<div id="attachment_245" class="wp-caption alignnone" style="width: 946px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-24.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-24.jpg" alt="CSS Error" title="CSS Error" width="936" height="408" class="size-full wp-image-245" /></a><p class="wp-caption-text">CSS Error</p></div></p>
<pre class="brush: css; first-line: 38; highlight: [41]; title: ; notranslate">
#wrap {
	margin:0 auto;
  	position:relative;
  	float:center;
  	top: 0px;
  	left:0px;
  	width:800px;
  	text-align:left;  	

}
</pre>
<p><code>center</code> is not a float value.</p>
<p>3. Using a String&#8217;s equals() method to test for an empty String. This might be OK for a small application like the ROO example but it can bring about some performance issue for a big application with numerous simultaneous user requests.<br />
<div id="attachment_246" class="wp-caption alignnone" style="width: 913px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-25.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-25.jpg" alt="Performance Issue - Test for Empty String" title="Performance Issue - Test for Empty String" width="903" height="405" class="size-full wp-image-246" /></a><p class="wp-caption-text">Performance Issue - Test for Empty String</p></div><br />
So the following code from <code>ChoiceEditor_Roo_Editor</code></p>
<pre class="brush: java; title: ; notranslate">
if (text == null || &quot;&quot;.equals(text))
</pre>
<p>had better be</p>
<pre class="brush: java; title: ; notranslate">
if (text == null || 0 == text.length())
</pre>
<p>I wrote more details about it here with performance tests.<br />
<a href="http://blog.lckymn.com/2009/05/17/test-for-empty-string/" target="_blank" style="color: blue; font-weight: bolder;">http://blog.lckymn.com/2009/05/17/test-for-empty-string/</a></p>
<p>Finally, it&#8217;s my wish. I found that aspect code is not really supported by the Eclipse functions for Java such as <code>Call Hierarchy</code> and <code>Open Declaration</code>. It would be much better if aspects are fully supported by the Eclipse functions for Java. However, it may have something to do with AJDT not Spring ROO integration.</p>
<p>Phew, I have eventually written this. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Even though I tried ROO approximately two weeks ago, I did not have time to write about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lckymn.com/2009/05/17/roo-so-cool-04/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ROO So Cool!!! -03-</title>
		<link>http://blog.lckymn.com/2009/05/17/roo-so-cool-03/</link>
		<comments>http://blog.lckymn.com/2009/05/17/roo-so-cool-03/#comments</comments>
		<pubDate>Sun, 17 May 2009 01:02:34 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[AJDT]]></category>
		<category><![CDATA[AspectJ]]></category>
		<category><![CDATA[AspectJ Development Tools]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Eclipse JEE]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Inter-type declarations]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaBean]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[M2Eclipse]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Maven Integration for Eclipse]]></category>
		<category><![CDATA[Maven2]]></category>
		<category><![CDATA[Mixin]]></category>
		<category><![CDATA[Multiple Inheritance]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring ROO]]></category>
		<category><![CDATA[SpringSource Tool Suite]]></category>
		<category><![CDATA[STS]]></category>

		<guid isPermaLink="false">http://blog.lckymn.com/?p=275</guid>
		<description><![CDATA[<p>Continued from <a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-02/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-02/</a></p> <p>Now, let&#8217;s look at more interesting one that is the ROO generated source code!</p> <p>As you can see, there are many AspectJ aspects in the <code>com.springsource.vote.domain</code> package. So I&#8217;ll firstly try to look at the <code>Choice</code> class which is not an aspect.</p> <p><div id="attachment_239" class="wp-caption alignnone" style="width: 989px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-18.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-18.jpg" alt="Domain object - Choice" title="Domain object - Choice" width="979" height="744" class="size-full wp-image-239" /></a><p class="wp-caption-text">Domain object - Choice</p></div> Wow! Is that it? Without the annotations, it <p style="border: 3px solid rgb(243, 197, 52); padding: 5px; background-color: rgb(254, 254, 184); width: 600px; text-align: center;">[...Continue reading <a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-03/">ROO So Cool!!! -03-</a>...]</p>]]></description>
			<content:encoded><![CDATA[<p>Continued from<br />
<a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-02/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-02/</a></p>
<p>Now, let&#8217;s look at more interesting one that is the ROO generated source code!</p>
<p>As you can see, there are many AspectJ aspects in the <code>com.springsource.vote.domain</code> package. So I&#8217;ll firstly try to look at the <code>Choice</code> class which is not an aspect.</p>
<p><div id="attachment_239" class="wp-caption alignnone" style="width: 989px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-18.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-18.jpg" alt="Domain object - Choice" title="Domain object - Choice" width="979" height="744" class="size-full wp-image-239" /></a><p class="wp-caption-text">Domain object - Choice</p></div><br />
Wow! Is that it? Without the annotations, it consists of only two lines of code in the class.  Just two variable declarations.</p>
<p>So where are the others?</p>
<p>Check out the <code>Choice_Roo_Entity</code> aspect.<br />
<div id="attachment_240" class="wp-caption alignnone" style="width: 919px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-19.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-19.jpg" alt="Persistent Object (Aspect)" title="Persistent Object (Aspect)" width="909" height="424" class="size-full wp-image-240" /></a><p class="wp-caption-text">Persistent Object (Aspect)</p></div><br />
It appears to be a persistent object class with a persistence manager which means it includes data access logic. This sounds like normal <a href="http://www.martinfowler.com/eaaCatalog/activeRecord.html" target="_blank">Active Record</a> yet if you closer look at the code, it uses AspectJ&#8217;s inter-type declaration to add more attributes and behaviours to the domain object <code>Choice</code>.</p>
<pre class="brush: java; title: ; notranslate">
    @javax.persistence.Id
    @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
    @javax.persistence.Column(name = &quot;id&quot;)
    private java.lang.Long Choice.id;
</pre>
<p>This code above is declaring long type id variable to the type Choice to use as an identifier for OR mapping.  Because it is declared as a private variable, it is impossible to access it inside the code of Choice but possible only inside this <code>Choice_Roo_Entity</code> aspect.</p>
<p>What about the <code>Choice_Roo_JavaBean</code>.<br />
<div id="attachment_241" class="wp-caption alignnone" style="width: 922px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-20.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-20.jpg" alt="JavaBean (Aspect)" title="JavaBean (Aspect)" width="912" height="424" class="size-full wp-image-241" /></a><p class="wp-caption-text">JavaBean (Aspect)</p></div><br />
It has all the getters and setters for the <code>Choice</code> class and again inter-type declaration is used for adding these accessor methods.  So an instance of Choice type cannot only behave as a persistent object but also as a JavaBean object.  If you look into the jsp file, you can see it is used just like the methods belong to <code>Choice</code> class.<br />
In order to access the variables inside <code>Choice</code> object, the <code>Choice_Roo_JavaBean</code> is defined as <code>privileged</code> aspect.</p>
<pre class="brush: java; highlight: [1,4,8,12,16]; title: ; notranslate">
privileged aspect Choice_Roo_JavaBean {

    public java.lang.String Choice.getNamingChoice() {
        return this.namingChoice;
    }    

    public void Choice.setNamingChoice(java.lang.String namingChoice) {
        this.namingChoice = namingChoice;
    }    

    public java.lang.String Choice.getDescription() {
        return this.description;
    }    

    public void Choice.setDescription(java.lang.String description) {
        this.description = description;
    }    

}
</pre>
<p>So as shown above, <code>Choice_Roo_JavaBean</code> is a privileged aspect and therefore it can access <code>namingChoice</code> and <code>description</code> variables which are declared in <code>Choice</code>.</p>
<p>So what is it? It is a mixin.  <a href="http://en.wikipedia.org/wiki/Mixin" target="_blank">Mixin</a> is a class which provides a functionality to a subclass yet mixin itself is not supposed to stand alone.  So a class can collect its functionality by inheriting from one or more mixins through multiple inheritance.  However, as we all know, Java does not support multiple inheritance. So to use mixins in Java world, inter-type declarations in AspectJ can be used.</p>
<pre class="brush: java; highlight: [8,13]; title: ; notranslate">
privileged aspect Choice_Roo_Entity {

	(...)

    @javax.persistence.Id
    @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
    @javax.persistence.Column(name = &quot;id&quot;)
    private java.lang.Long Choice.id;    

    (...)

    public java.lang.Long Choice.getId() {
        return this.id;
    }
}
</pre>
<p>As seen in the aspect code above, a long type variable is added to the type Choice and a getId() method which returns a long type value that is the value in the variable, id, just added by the aspect. So an instance of Choice type can have getId() method even though it does not exist in the Choice class. Therefore, as mentioned, Choice type can have characteristics of both persistent object and JavaBean.  </p>
<p>AspectJ is also used to declare Choice type as a configurable type.<br />
<div id="attachment_242" class="wp-caption alignnone" style="width: 802px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-21.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-21.jpg" alt="Make Choice @Configurable" title="Make Choice @Configurable" width="792" height="172" class="size-full wp-image-242" /></a><p class="wp-caption-text">Make Choice @Configurable</p></div><br />
This code reveals that <code>Choice</code> type has <code>@org.springframework.beans.factory.annotation.Configurable</code> annotation.</p>
<pre class="brush: java; title: ; notranslate">
privileged aspect Choice_Roo_Configurable {

    declare @type: Choice: @org.springframework.beans.factory.annotation.Configurable;    

}
</pre>
<p>Next:<br />
<a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-04/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-04/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lckymn.com/2009/05/17/roo-so-cool-03/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ROO So Cool!!! -02-</title>
		<link>http://blog.lckymn.com/2009/05/17/roo-so-cool-02/</link>
		<comments>http://blog.lckymn.com/2009/05/17/roo-so-cool-02/#comments</comments>
		<pubDate>Sun, 17 May 2009 01:01:45 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[AJDT]]></category>
		<category><![CDATA[AspectJ]]></category>
		<category><![CDATA[AspectJ Development Tools]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Eclipse JEE]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Inter-type declarations]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaBean]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[M2Eclipse]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Maven Integration for Eclipse]]></category>
		<category><![CDATA[Maven2]]></category>
		<category><![CDATA[Mixin]]></category>
		<category><![CDATA[Multiple Inheritance]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring ROO]]></category>
		<category><![CDATA[SpringSource Tool Suite]]></category>
		<category><![CDATA[STS]]></category>

		<guid isPermaLink="false">http://blog.lckymn.com/?p=273</guid>
		<description><![CDATA[<p>Continued from <a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-01/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-01/</a></p> <p>Let&#8217;s run this project to see what it looks like.</p> <p><div id="attachment_159" class="wp-caption alignnone" style="width: 833px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-09.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-09.jpg" alt="Run ROO Generated Application on Server" title="Run ROO Generated Application on Server" width="823" height="570" class="size-full wp-image-159" /></a><p class="wp-caption-text">Run ROO Generated Application on Server</p></div> Right click on the project -> Select the <code>Run As</code> option on the menu -> Select the <code>Run on Server</code>.</p> <p><div id="attachment_160" class="wp-caption alignnone" style="width: 626px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-10.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-10.jpg" alt="Choose Server" title="Choose Server" width="616" height="709" <p style="border: 3px solid rgb(243, 197, 52); padding: 5px; background-color: rgb(254, 254, 184); width: 600px; text-align: center;">[...Continue reading <a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-02/">ROO So Cool!!! -02-</a>...]</p>]]></description>
			<content:encoded><![CDATA[<p>Continued from<br />
<a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-01/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-01/</a></p>
<p>Let&#8217;s run this project to see what it looks like.</p>
<p><div id="attachment_159" class="wp-caption alignnone" style="width: 833px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-09.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-09.jpg" alt="Run ROO Generated Application on Server" title="Run ROO Generated Application on Server" width="823" height="570" class="size-full wp-image-159" /></a><p class="wp-caption-text">Run ROO Generated Application on Server</p></div><br />
Right click on the project -> Select the <code>Run As</code> option on the menu -> Select the <code>Run on Server</code>.</p>
<p><div id="attachment_160" class="wp-caption alignnone" style="width: 626px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-10.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-10.jpg" alt="Choose Server" title="Choose Server" width="616" height="709" class="size-full wp-image-160" /></a><p class="wp-caption-text">Choose Server</p></div><br />
Select <code>Choose an existing server</code> -> Select any <code>Servlet Container</code> or <code>JEE Server</code> on which you would like ROO generated application to run (If you do not have any available ones, install set it up first). -> Click the <code>Next</code> button.</p>
<p><div id="attachment_161" class="wp-caption alignnone" style="width: 628px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-11.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-11.jpg" alt="Click Finish to Run" title="Click Finish to Run" width="618" height="705" class="size-full wp-image-161" /></a><p class="wp-caption-text">Click Finish to Run</p></div><br />
Make sure <code>vote</code> project appears on the right-hand side and Click the <code>Finish</code> button.</p>
<p><div id="attachment_162" class="wp-caption alignnone" style="width: 913px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-12.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-12.jpg" alt="ROO Generated Application is Running." title="ROO Generated Application is Running." width="903" height="695" class="size-full wp-image-162" /></a><p class="wp-caption-text">ROO Generated Application is Running.</p></div><br />
Now it&#8217;s running.</p>
<p>I opened Firefox 3 to test it instead of using the built-in browser of Eclipse.<br />
Let&#8217;s create a new choice.</p>
<p><div id="attachment_163" class="wp-caption alignnone" style="width: 849px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-13.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-13.jpg" alt="Create New Choice (Firefox3)" title="Create New Choice (Firefox3)" width="839" height="688" class="size-full wp-image-163" /></a><p class="wp-caption-text">Create New Choice (Firefox3)</p></div><br />
Click the <code>Create New Choice</code> menu.</p>
<p><div id="attachment_164" class="wp-caption alignnone" style="width: 849px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-14.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-14.jpg" alt="Create New Choice Form" title="Create New Choice Form" width="839" height="586" class="size-full wp-image-164" /></a><p class="wp-caption-text">Create New Choice Form</p></div><br />
It displays the <code>Create New Choice</code> form.</p>
<p>Wait a minute! Is that a JavaScript (JS) error that <a href="http://getfirebug.com/" target="_blank">Firebug</a> complains?<br />
<div id="attachment_165" class="wp-caption alignnone" style="width: 851px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-15.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-15.jpg" alt="dojo JS Toolkit Error" title="dojo JS Toolkit Error" width="841" height="588" class="size-full wp-image-165" /></a><p class="wp-caption-text">dojo JS Toolkit Error</p></div><br />
Yes, it is but it looks like an error in <a href="http://dojotoolkit.org/" target="_blank">dojo</a> JS toolkit which Spring JS uses. Anyway, despite the error, it works fine.</p>
<p><div id="attachment_166" class="wp-caption alignnone" style="width: 849px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-16.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-16.jpg" alt="Fill in the Form -&gt; Save" title="Fill in the Form -&gt; Save" width="839" height="582" class="size-full wp-image-166" /></a><p class="wp-caption-text">Fill in the Form -> Save</p></div><br />
Quickly fill in the form. -> Click the <code>Save</code> button.</p>
<p><div id="attachment_167" class="wp-caption alignnone" style="width: 850px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-17.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-17.jpg" alt="New Choice Created" title="New Choice Created" width="840" height="588" class="size-full wp-image-167" /></a><p class="wp-caption-text">New Choice Created</p></div><br />
The entered data are added and a new Choice is created.</p>
<p>Next:<br />
<a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-03/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-03/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lckymn.com/2009/05/17/roo-so-cool-02/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ROO So Cool!!! -01-</title>
		<link>http://blog.lckymn.com/2009/05/17/roo-so-cool-01/</link>
		<comments>http://blog.lckymn.com/2009/05/17/roo-so-cool-01/#comments</comments>
		<pubDate>Sun, 17 May 2009 01:00:26 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[AJDT]]></category>
		<category><![CDATA[AspectJ]]></category>
		<category><![CDATA[AspectJ Development Tools]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Eclipse JEE]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Inter-type declarations]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JavaBean]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[M2Eclipse]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Maven Integration for Eclipse]]></category>
		<category><![CDATA[Maven2]]></category>
		<category><![CDATA[Mixin]]></category>
		<category><![CDATA[Multiple Inheritance]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring ROO]]></category>
		<category><![CDATA[SpringSource Tool Suite]]></category>
		<category><![CDATA[STS]]></category>

		<guid isPermaLink="false">http://blog.lckymn.com/?p=146</guid>
		<description><![CDATA[<p>The end of the last month Spring Source released Spring ROO in alpha stage. My friend, <a href="http://stsmedia.net/" target="_blank">Dr. Stefan Schmidt</a>, who in fact used to teach me J2EE technology at UTS when I was a UTS student, has been working for Spring Source and is now involved in ROO development. Although ROO sounds really like Australian, it signifies Real Object-Oriented (ROO). After the release of the alpha version, Dr. Schmidt posted <a href="http://stsmedia.net/introducing-spring-roo/" target="_blank">an introductory tutorial of ROO</a> on <p style="border: 3px solid rgb(243, 197, 52); padding: 5px; background-color: rgb(254, 254, 184); width: 600px; text-align: center;">[...Continue reading <a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-01/">ROO So Cool!!! -01-</a>...]</p>]]></description>
			<content:encoded><![CDATA[<p>The end of the last month Spring Source released Spring ROO in alpha stage.  My friend, <a href="http://stsmedia.net/" target="_blank">Dr. Stefan Schmidt</a>, who in fact used to teach me J2EE technology at UTS when I was a UTS student, has been working for Spring Source and is now involved in ROO development. Although ROO sounds really like Australian, it signifies Real Object-Oriented (ROO).  After the release of the alpha version, Dr. Schmidt posted <a href="http://stsmedia.net/introducing-spring-roo/" target="_blank">an introductory tutorial of ROO</a> on his blog.  He explained well so I could easily try this new mind-blowing technology. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Let&#8217;s start a journey!</p>
<p>-Check your maven and JVM versions.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
$ mvn --version
Maven version: 2.0.9
Java version: 1.6.0_13
OS name: &quot;linux&quot; version: &quot;2.6.28-11-generic&quot; arch: &quot;amd64&quot; Family: &quot;unix&quot;
</pre>
<p>- I&#8217;m using Ubuntu Linux 9.04 Jaunty Jackalope desktop edition 64bit and installed Sun JDK &amp; Maven2 from its repository.</p>
<p>-Extract <code>spring-roo-1.0.0.A2.zip</code> file to <code>/somepath/roo-1.0.0.A2</code><br />
-Add the environment variable ROO_HOME with the path of Roo home in the <code>.bashrc</code> file.<br />
-Add $ROO_HOME/bin to PATH in the <code>.bashrc</code> file.<br />
e.g.)</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
export ROO_HOME=/opt/lib/spring/roo-1.0.0.A2
PATH=${PATH}:$ROO_HOME/bin

export PATH
</pre>
<p>For Eclipse,<br />
-Extract <code>sts-roo-integration-1.0.0.A2.zip</code> file to the <code>eclipse/dropins</code> folder to use Spring ROO integration.<br />
This copying to the dropins directory only works for Eclipse Ganymede.</p>
<p>-Install ROO packages in the maven repository.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn install:install-file -DgroupId=org.springframework.roo \
  -DartifactId=roo-annotations -Dversion=1.0.0.A2 -Dpackaging=jar \
  -Dfile=$ROO_HOME/dist/roo-annotations-1.0.0.A2.jar
</pre>
<p>-Result</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
$ mvn install:install-file -DgroupId=org.springframework.roo \
       -DartifactId=roo-annotations -Dversion=1.0.0.A2 -Dpackaging=jar \
       -Dfile=$ROO_HOME/dist/roo-annotations-1.0.0.A2.jar
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'install'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file]
[INFO] Installing /opt/lib/spring/roo-1.0.0.A2/dist/roo-annotations-1.0.0.A2.jar to /home/blade2/.m2/repository/org/springframework/roo/roo-annotations/1.0.0.A2/roo-annotations-1.0.0.A2.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue May 05 22:09:23 EST 2009
[INFO] Final Memory: 7M/165M
[INFO] ------------------------------------------------------------------------
</pre>
<p>-Now starts ROO console!</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
$ mkdir roo_test
$ cd roo_test/
$ roo.sh
</pre>
<div id="attachment_149" class="wp-caption alignnone" style="width: 801px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-00.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-00.jpg" alt="ROO Console" title="ROO Console" width="791" height="583" class="size-full wp-image-149" /></a><p class="wp-caption-text">ROO Console</p></div>
<p>-Create a project directory for a ROO project.</p>
<pre>
roo&gt; script vote.roo
(... wait until ROO console does it's job...)
roo&gt; exit
</pre>
<p>Instead of following the script that Dr. Schmidt provided, I just used <code>vote.roo</code> which can be found in the <code>samples</code> directory. Well no special reasons, it just looks simpler. That&#8217;s it. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   If you are seeking more interesting one, you&#8217;d better try the one on the blog of Dr. Schmidt and then try your own one. ^O^</p>
<p>-In order to import the ROO project, just created, to Eclipse (STS), run maven2&#8242;s eclipse plug-in.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
$ mvn eclipse:eclipse
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ------------------------------------------------------------------------
[INFO] Building vote
[INFO]    task-segment: [eclipse:eclipse]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing eclipse:eclipse
Downloading:
... lots of dependencies including spring framework 3.0.0.M2 ...

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 minutes 26 seconds
[INFO] Finished at: Tue May 05 22:32:18 EST 2009
[INFO] Final Memory: 31M/353M
[INFO] ------------------------------------------------------------------------
</pre>
<p>Well, although it says</p>
<blockquote><p>
Sources for some artifacts are not available.<br />
Javadoc for some artifacts is not available.
</p></blockquote>
<p>it is not that important unless I really want to see the missing source code and Javadoc of the artifacts listed with the message.</p>
<p>If you want to get it, add <code>-DdownloadSources=true  -DdownloadJavadocs=true</code> options and run maven again.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
$ mvn eclipse:eclipse -DdownloadSources=true  -DdownloadJavadocs=true
</pre>
<p><del datetime="2009-05-17T17:36:05+00:00">I&#8217;m not sure if the source is available though.</del> <del datetime="2009-05-21T13:38:58+00:00">The source code is not available at the moment though.</del> I was wrong. The source code is available. Check this out. <a href="http://forum.springsource.org/showthread.php?t=71985" target="_blank">http://forum.springsource.org/showthread.php?t=71985</a></p>
<p>-Now run Eclipse. Since ROO is a part of Spring Framework, I&#8217;m using SpringSource Tool Suite (STS) for this practice.</p>
<div id="attachment_150" class="wp-caption alignnone" style="width: 511px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-01.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-01.jpg" alt="SpringSource Tool Suite" title="SpringSource Tool Suite" width="501" height="341" class="size-full wp-image-150" /></a><p class="wp-caption-text">SpringSource Tool Suite</p></div>
<p>Well, before I go further, here are what I am using.<br />
*SpringSource Tool Suite (STS) 2.0.0</p>
<ul>
<li>Apart from all the Spring related plug-ins that STS comes with, it also comes with several good plug-ins such as AspectJ Development Tools (AJDT), <a href="http://pmd.sourceforge.net/integrations.html#eclipse" target="_blank">PMD for Eclipse</a> (Java source code analyser) and EclEmma (Code Coverage Tool) which are what I usually install when I use pure Eclipse JEE.</li>
</ul>
<p>*Eclipse Plug-ins</p>
<ul>
<li>Subclipse</li>
<li>Maven Integration for Eclipse (M2Eclipse)</li>
<li>Aptana</li>
<li>JDepend (Java source code analyser)</li>
<li>Copy Fully Qualified Class Name Plugin</li>
<li>Resource Bundle Editor</li>
<li>and of course Spring ROO Integration for Eclipse (I heard a new STS will include it).</li>
</ul>
<p>However, what are really required for this ROO practice are Eclipse JEE, Spring IDE, AJDT, M2Eclipse and Spring ROO Integration. Or you can simply use STS and install M2Eclipse and Spring ROO Integration.  If you use Eclipse JEE Ganymede and install Spring IDE, it will automatically install AJDT as a dependency of Spring IDE since Ganymede has a smart software &amp; add-ons update manager. <img src='http://blog.lckymn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>(Good News: A free version of STS is released. Check this out<br />
<a href="http://blog.springsource.com/2009/05/07/springsource-tool-suite-now-free/" target="_blank">SpringSource Tool Suite now free</a>).</p>
<p><div id="attachment_151" class="wp-caption alignnone" style="width: 916px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-02.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-02.jpg" alt="Import ROO project" title="Import ROO project" width="906" height="693" class="size-full wp-image-151" /></a><p class="wp-caption-text">Import ROO project</p></div><br />
Right click on the project explorer -> Select <code>Import</code></p>
<p><div id="attachment_152" class="wp-caption alignnone" style="width: 920px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-03.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-03.jpg" alt="Existing Projects into Workspace" title="Existing Projects into Workspace" width="910" height="699" class="size-full wp-image-152" /></a><p class="wp-caption-text">Existing Projects into Workspace</p></div><br />
Expand the <code>General</code> entry -> Select <code>Existing Projects into Workspace</code> -> Click the <code>Next</code> button.</p>
<p><div id="attachment_153" class="wp-caption alignnone" style="width: 919px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-04.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-04.jpg" alt="Select Project to Import" title="Select Project to Import" width="909" height="696" class="size-full wp-image-153" /></a><p class="wp-caption-text">Select Project to Import</p></div><br />
Browse the roo project directory created by roo. In my case it&#8217;s <code>roo_test</code> -> Click the <code>Finish</code> button.<br />
(NOTE: Because I created the roo project directory inside the workspace of Eclipse (STS), I don&#8217;t need to check <code>Copy projects into workspace</code> option.)</p>
<p><div id="attachment_154" class="wp-caption alignnone" style="width: 919px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-05.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-05.jpg" alt="Turn AJDT&#039;s Weaving Service on" title="Turn AJDT&#039;s Weaving Service on" width="909" height="696" class="size-full wp-image-154" /></a><p class="wp-caption-text">Turn AJDT's Weaving Service on</p></div><br />
If Eclipse asks to turn on weaving service function of AJDT, Click the <code>Yes</code> button.</p>
<p><div id="attachment_155" class="wp-caption alignnone" style="width: 919px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-06.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-06.jpg" alt="Restart STS (Eclipse)" title="Restart STS (Eclipse)" width="909" height="696" class="size-full wp-image-155" /></a><p class="wp-caption-text">Restart STS (Eclipse)</p></div><br />
Restart Eclipse.</p>
<p><div id="attachment_156" class="wp-caption alignnone" style="width: 477px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-07_01.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-07_01.jpg" alt="Dependency Problems" title="Dependency Problems" width="467" height="698" class="size-full wp-image-156" /></a><p class="wp-caption-text">Dependency Problems</p></div><br />
Eclipse is restarted and there are errors in the project as the require dependencies are not in the project directory.</p>
<p>So now, let M2Eclipse resolves this dependency problem. That&#8217;s why I&#8217;m using this plug-in. I want to focus on real problems in software development rather than focusing on providing dependency libraries for development.</p>
<p><div id="attachment_157" class="wp-caption alignnone" style="width: 804px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-07_02.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-07_02.jpg" alt="Let M2Eclipse Resolves Dependencies" title="Let M2Eclipse Resolves Dependencies" width="794" height="708" class="size-full wp-image-157" /></a><p class="wp-caption-text">Let M2Eclipse Resolves Dependencies</p></div><br />
Right click on the project -> Select the <code>Maven</code> option on the menu -> Select the <code>Enable Dependency Management</code>.<br />
Wait until it does its job.</p>
<p><div id="attachment_158" class="wp-caption alignnone" style="width: 475px"><a href="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-08.jpg"><img src="http://blog.lckymn.com/wp-content/uploads/2009/05/roo-08.jpg" alt="Dependency Problems Solved" title="Dependency Problems Solved" width="465" height="699" class="size-full wp-image-158" /></a><p class="wp-caption-text">Dependency Problems Solved</p></div><br />
As shown here, Maven resolved it so all the required dependencies are there.</p>
<p>Next:<br />
<a href="http://blog.lckymn.com/2009/05/17/roo-so-cool-02/" target="_blank">http://blog.lckymn.com/2009/05/17/roo-so-cool-02/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lckymn.com/2009/05/17/roo-so-cool-01/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

