<?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>tail -f log/development.log</title>
	<atom:link href="http://maciej.inszy.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://maciej.inszy.org</link>
	<description>Maciej&#039;s weblog</description>
	<lastBuildDate>Tue, 23 Feb 2010 21:52:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring 3 MVC and optional relationships</title>
		<link>http://maciej.inszy.org/2010/02/18/spring-3-mvc-and-optional-relationships/</link>
		<comments>http://maciej.inszy.org/2010/02/18/spring-3-mvc-and-optional-relationships/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 16:00:33 +0000</pubDate>
		<dc:creator>maciej</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[roo]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring mvc]]></category>

		<guid isPermaLink="false">http://maciej.inszy.org/?p=50</guid>
		<description><![CDATA[Last December Ben Alex and his team released Spring Roo 1.0.0.GA. I&#8217;ve decided to give it a try. Even though there was some initial criticism I found Roo to be a quite useful tool.
After creating some CRUD controllers I wanted to enable optional relationships in the view (i.e. comboboxes with a null/empty option). As it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Last December Ben Alex and his team released <a title="Spring Roo" href="http://www.springsource.org/roo">Spring Roo</a> 1.0.0.GA. I&#8217;ve decided to give it a try. Even though there was some <a href="http://www.gridshore.nl/2009/06/11/why-spring-roo-is-not-my-thing/">initial criticism</a> I found Roo to be a quite useful tool.</p>
<p>After creating some CRUD controllers I wanted to enable optional relationships in the view (i.e. comboboxes with a null/empty option). As it&#8217;s quite a commonly requested feature and it cannot (at least as to my best knowledge) be enabled with toggling a single switch I&#8217;ve decided to share here my recipe how to do this.</p>
<p>Let&#8217;s say we have <tt>Node</tt> entity that can reference another node (it&#8217;s parent).</p>
<p>Node.java:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
@RooJavaBean
@RooToString
@RooEntity<span style="color: #009900;">&#40;</span>identifierType <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Node <span style="color: #009900;">&#123;</span>
&nbsp;
	@ManyToOne
	@JoinColumn<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;parent_id&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Node parent<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now let&#8217;s add the <em>No parent</em> option to the fragment holding the node parents list in the edit form JSP template:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form:select</span> <span style="color: #000066;">cssStyle</span>=<span style="color: #ff0000;">&quot;width:250px&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_parent_id&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form:option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;No parent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form:options</span> <span style="color: #000066;">itemValue</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;${nodes}&quot;</span> <span style="color: #000066;">itemLabel</span>=<span style="color: #ff0000;">&quot;fullPath&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>After the form is submitted it reaches the <tt>NodeController.update()</tt> method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@RequestMapping<span style="color: #009900;">&#40;</span>method <span style="color: #339933;">=</span> RequestMethod.<span style="color: #006633;">PUT</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> NodeController.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>@Valid Node node, BindingResult result, ModelMap modelMap<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ...</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>But before this happens the values that were submitted have to be converted into proper Node properties. The <tt>id</tt> into an <tt>Integer</tt>, date time values into a <tt>java.util.Date</tt> objects, etc. Without going into further details this happens in Spring&#8217;s <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#core-convert">conversion system</a>.<br />
All entity beans by default hit the <tt>org.springframework.core.convert.support.IdToEntityConverter</tt> converter. The converter basically tries to find a <tt>find<em>EntityName</em>()</tt> static method on the class that it has to convert to and call it passing the <em>id</em> from the HTML form. It does that regardless whether the <em>id</em> is null or not. And since the default Roo finders throw an <tt>IllegalArgumentException</tt>, as shown bellow, we quickly see the &#8220;Internal Error&#8221; page and a long stack trace in the server log.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Node Node.<span style="color: #006633;">findNode</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;An identifier is required to retrieve an instance of Node&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> entityManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>Node.<span style="color: #000000; font-weight: bold;">class</span>, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here are the two first options for solving this that came to my mind:</p>
<ul>
<li>We can push in all the Roo finders from aspect files into the respective Java classes and change their behaviour. But it&#8217;s not the most elegant solution and, yes, it changes the finder behaviour, which might not be desirable.</li>
<li>Write specific converters for every entity class in our project.</li>
</ul>
<p>Neither of these seemed to me a good solution. So I looked into tweaking the Spring the default spring converter. The new IdToEntityOrNullConverter has basically only 2 lines added in the <tt>convert()</tt> method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> convert<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> source, TypeDescriptor sourceType, TypeDescriptor targetType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Method</span> finder <span style="color: #339933;">=</span> getFinder<span style="color: #009900;">&#40;</span>targetType.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">Object</span> id <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conversionService</span>.<span style="color: #006633;">convert</span><span style="color: #009900;">&#40;</span>source, sourceType, TypeDescriptor.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>finder
				.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> ReflectionUtils.<span style="color: #006633;">invokeMethod</span><span style="color: #009900;">&#40;</span>finder, source, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And it works!</p>
<p>You need to remember to register the beans in the applicationContext.xml as well:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mvc:annotation-driven</span> <span style="color: #000066;">conversion-service</span>=<span style="color: #ff0000;">&quot;conversionService&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">		There are two conversion services. The generic one is used by idToEntityOrNullConverter as it requires one. We cannot</span>
<span style="color: #808080; font-style: italic;">		use the conversionService that is being used in the MVC context, as we would run into the chicken-and-egg problem</span>
<span style="color: #808080; font-style: italic;">		trying to instantiate the converter and the conversionService.</span>
<span style="color: #808080; font-style: italic;">	--&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;genericConversionService&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.context.support.ConversionServiceFactoryBean&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;idToEntityOrNullConveter&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.inszy.spring.support.IdToEntityOrNullConveter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">index</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;genericConversionService&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;conversionService&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.format.support.FormattingConversionServiceFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;converters&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;idToEntityOrNullConveter&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>There is also a JIRA issue available for this problem <a href="http://jira.springframework.org/browse/ROO-581">#ROO-581</a>.</p>
<p>IdToEntityOrNullConverter.java listing:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.inszy.spring.support</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Method</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Modifier</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collections</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Set</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.convert.TypeDescriptor</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.convert.converter.ConditionalGenericConverter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.core.convert.support.GenericConversionService</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.util.ClassUtils</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.util.ReflectionUtils</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> IdToEntityOrNullConveter <span style="color: #000000; font-weight: bold;">implements</span> ConditionalGenericConverter <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> GenericConversionService conversionService<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> IdToEntityOrNullConveter<span style="color: #009900;">&#40;</span>GenericConversionService conversionService<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conversionService</span> <span style="color: #339933;">=</span> conversionService<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Set</span> getConvertibleTypes<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: #003399;">Collections</span>.<span style="color: #006633;">singleton</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ConvertiblePair<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span>.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #003399;">Object</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> matches<span style="color: #009900;">&#40;</span>TypeDescriptor sourceType, TypeDescriptor targetType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Method</span> finder <span style="color: #339933;">=</span> getFinder<span style="color: #009900;">&#40;</span>targetType.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>finder <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conversionService</span>.<span style="color: #006633;">canConvert</span><span style="color: #009900;">&#40;</span>sourceType, TypeDescriptor.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>finder
				.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> convert<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> source, TypeDescriptor sourceType, TypeDescriptor targetType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Method</span> finder <span style="color: #339933;">=</span> getFinder<span style="color: #009900;">&#40;</span>targetType.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">Object</span> id <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conversionService</span>.<span style="color: #006633;">convert</span><span style="color: #009900;">&#40;</span>source, sourceType, TypeDescriptor.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>finder
				.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> ReflectionUtils.<span style="color: #006633;">invokeMethod</span><span style="color: #009900;">&#40;</span>finder, source, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Method</span> getFinder<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #339933;">?&amp;</span>gt<span style="color: #339933;">;</span> entityClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> finderMethod <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;find&quot;</span> <span style="color: #339933;">+</span> getEntityName<span style="color: #009900;">&#40;</span>entityClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">Method</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> methods <span style="color: #339933;">=</span> entityClass.<span style="color: #006633;">getDeclaredMethods</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Method</span> method <span style="color: #339933;">:</span> methods<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Modifier</span>.<span style="color: #006633;">isStatic</span><span style="color: #009900;">&#40;</span>method.<span style="color: #006633;">getModifiers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> method.<span style="color: #006633;">getParameterTypes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span>
					<span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> method.<span style="color: #006633;">getReturnType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>entityClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>method.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>finderMethod<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">return</span> method<span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</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: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> getEntityName<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #339933;">?&amp;</span>gt<span style="color: #339933;">;</span> entityClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> shortName <span style="color: #339933;">=</span> ClassUtils.<span style="color: #006633;">getShortName</span><span style="color: #009900;">&#40;</span>entityClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> lastDot <span style="color: #339933;">=</span> shortName.<span style="color: #006633;">lastIndexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lastDot <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> shortName.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span>lastDot <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> shortName<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Any feedback is greatly appreciated.</p>
<p><em><strong>UPDATE 2010.02.12:</strong> This should no longer be required if you&#8217;re using Roo 1.0.2 (or newer) as Andrew Swan noted on <a href="http://forum.springsource.org/showpost.php?p=284835&#038;postcount=5">the Spring forums.</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://maciej.inszy.org/2010/02/18/spring-3-mvc-and-optional-relationships/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Internet connection checker</title>
		<link>http://maciej.inszy.org/2009/08/24/java-internet-connection-checker/</link>
		<comments>http://maciej.inszy.org/2009/08/24/java-internet-connection-checker/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 12:01:26 +0000</pubDate>
		<dc:creator>maciej</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://maciej.inszy.org/?p=33</guid>
		<description><![CDATA[Over a year ago Anand Sreenivasan published a short Java class which purpose was to check for Internet connectivity on the computer of the person running it. It was meant to be used as a CLI app. I decided to make it a little bit more reusable.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.CharBuffer;
import java.util.Date;
import java.util.logging.Level;
import [...]]]></description>
			<content:encoded><![CDATA[<p><span>Over a year ago Anand Sreenivasan <a href="http://anandsreenivasan.blogspot.com/2008/04/checking-internet-connection-on-your.html">published</a> a short Java class which purpose was to check for Internet connectivity on the computer of the person running it. It was meant to be used as a CLI app. I decided to make it a little bit more reusable.</span></p>
<p><span><span id="more-33"></span></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Reader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URLConnection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.nio.CharBuffer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Level</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> InternetChecker <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> URL_TO_CHECK <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.google.com/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> CHECK_EVERY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* 30 minutes */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> BUF_SIZE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> InternetChecker ref<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Date</span> lastCheck<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> lastState<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Logger log <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>InternetChecker.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> InternetChecker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isStateValid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lastState <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lastCheck.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> CHECK_EVERY<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isConnectionPresent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isStateValid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			checkConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> lastState<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isConnectionPresent<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> forceCheck<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>forceCheck<span style="color: #009900;">&#41;</span>
			invalidateState<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> isConnectionPresent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> invalidateState<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		lastCheck <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		lastState <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> checkConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		lastCheck <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>URL_TO_CHECK<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">URLConnection</span> urlConnection <span style="color: #339933;">=</span> url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003399;">InputStream</span> inputStream <span style="color: #339933;">=</span> urlConnection.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Reader</span> reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>inputStream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			StringBuilder contents <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			CharBuffer buf <span style="color: #339933;">=</span> CharBuffer.<span style="color: #006633;">allocate</span><span style="color: #009900;">&#40;</span>BUF_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<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>
				reader.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span>buf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>buf.<span style="color: #006633;">hasRemaining</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;">break</span><span style="color: #339933;">;</span>
&nbsp;
				contents <span style="color: #339933;">=</span> contents.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>buf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			inputStream.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			lastState <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			log.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">INFO</span>, <span style="color: #0000ff;">&quot;Internet connectivy present.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>
			log.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">WARNING</span>, <span style="color: #0000ff;">&quot;Internet connectivity not present.&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			lastState <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</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> InternetChecker getDefaultInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ref <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ref <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> InternetChecker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> ref<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>To use it you invoke:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">InternetChecker.<span style="color: #006633;">getDefaultInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isConnectionPresent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can also force checking the connection by passing <em>true</em> to the <em>isConnectionPresent()</em> method.</p>
<p>Please to report any bugs or ideas, I will update the class if necessary.</p>
]]></content:encoded>
			<wfw:commentRss>http://maciej.inszy.org/2009/08/24/java-internet-connection-checker/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>RubyGems 1.3.1 for Ubuntu 8.10</title>
		<link>http://maciej.inszy.org/2009/02/06/rubygems-131-for-ubuntu-810/</link>
		<comments>http://maciej.inszy.org/2009/02/06/rubygems-131-for-ubuntu-810/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 19:30:20 +0000</pubDate>
		<dc:creator>maciej</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ppa]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubygems]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://maciej.inszy.org/?p=10</guid>
		<description><![CDATA[Some time ago Rails 2.2 was released. Since than the framework requires rubygems 1.3.1 to run. Unfortunately Ubuntu 8.10 only has rubygems 1.2.0 in its repositories. A quick google search didn&#8217;t yield a good solution for this. Everyone is suggesting to install the vanilla rubygems-1.3.1.tgz, but I feel more comfortable having rubygems managed by Ubuntu&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago <a title="Rails 2.2 release notes" href="http://guides.rubyonrails.org/2_2_release_notes.html">Rails 2.2</a> was released. Since than the framework requires rubygems 1.3.1 to run. Unfortunately Ubuntu 8.10 only has rubygems 1.2.0 in its repositories. A quick google search didn&#8217;t yield a good solution for this. <a href="https://help.ubuntu.com/community/RubyOnRails#RubyGems%201.3.1">Everyone</a> <a href="http://www.neeraj.name/blog/articles/776-updating-rubygem-to-1-3-1-on-ubuntu">is</a> <a href="http://intertwingly.net/blog/2008/11/23/RubyGems-1-3-1-on-Ubuntu-8-10">suggesting</a> to install the vanilla rubygems-1.3.1.tgz, but I feel more comfortable having rubygems managed by Ubuntu&#8217;s package manager.  So I created the package myself.</p>
<p><script type="text/javascript">// < ![CDATA[
// < ![CDATA[
   &lt;!       function updateSeries(select) {           var deb = document.getElementById('series-deb');           deb.innerHTML = select.value;           var deb_src = document.getElementById('series-deb-src');           deb_src.innerHTML = select.value;       }   // &gt;
// ]]&gt;</script></p>
<p>It&#8217;s now available from my <abbr title="Personal package archive">PPA</abbr>. To install it you need to add the following lines to your /etc/apt/sources.list file:</p>
<pre>deb <a href="http://ppa.launchpad.net/maciejb/ppa/ubuntu">http://ppa.launchpad.net/maciejb/ppa/ubuntu</a> intrepid main
deb-src <a href="http://ppa.launchpad.net/maciejb/ppa/ubuntu">http://ppa.launchpad.net/maciejb/ppa/ubuntu</a> intrepid main</pre>
<p>For further instructions please follow this <a title="Adding a PPA to your Ubuntu repositories" href="https://help.launchpad.net/Packaging/PPA#Adding%20a%20PPA%20to%20your%20Ubuntu%20repositories">link</a>. My PPA&#8217;s address is: <a title="PPA for Maciej Biłas" href="https://launchpad.net/~maciejb/+archive/ppa">https://launchpad.net/~maciejb/+archive/ppa</a>.</p>
<p><strong>Update (2009/09/08)</strong>: Brightbox currently has the most up-to-date Rubygems repository available: <a href="http://wiki.brightbox.co.uk/docs:brightboxaptrepository">http://wiki.brightbox.co.uk/docs:brightboxaptrepository</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maciej.inszy.org/2009/02/06/rubygems-131-for-ubuntu-810/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
