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

<channel>
	<title>spiros.blog()</title>
	<atom:link href="http://www.tzavellas.com/techblog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tzavellas.com/techblog</link>
	<description>Spiros Tzavellas's blog, mostly on software development and Java.</description>
	<pubDate>Sun, 09 Mar 2008 09:08:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Seattle Conference on Scalability</title>
		<link>http://www.tzavellas.com/techblog/2007/07/07/seattle-conference-on-scalability/</link>
		<comments>http://www.tzavellas.com/techblog/2007/07/07/seattle-conference-on-scalability/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 12:39:03 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

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

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/07/07/seattle-conference-on-scalability/</guid>
		<description><![CDATA[Finally, the talks from the Google&#8217;s scalability conference are available online.
]]></description>
			<content:encoded><![CDATA[<p>Finally, the talks from the Google&#8217;s <a href="http://www.google.com/events/scalability_seattle/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.google.com');">scalability conference</a> are available <a href="http://video.google.com/videosearch?q=user%3A%22Google+engEDU%22+Seattle+Conference+on+Scalability&#038;hl=en" onclick="javascript:pageTracker._trackPageview ('/outbound/video.google.com');">online</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/07/07/seattle-conference-on-scalability/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Dependency Injection in Struts2 for stateless EJBs part 2</title>
		<link>http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-2/</link>
		<comments>http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-2/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 12:10:12 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[EJB]]></category>

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-2/</guid>
		<description><![CDATA[This is the second, and last part of the Using Dependency Injection in Struts2 for stateless EJBs series of posts. In this post I will present a utility class that can be used to make the creation of Guice bindings for EJB3s easier.
Introducing EjbBinder
Our goal is to make an easier API, specifically for creating bindings [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second, and last part of the <strong>Using Dependency Injection in Struts2 for stateless EJBs</strong> series of posts. In this post I will present a utility class that can be used to make the creation of Guice bindings for EJB3s easier.</p>
<h3>Introducing <code>EjbBinder</code></h3>
<p>Our goal is to make an easier API, specifically for creating bindings of EJB3s, and make the specification of the JNDI name optional, when possible. The below code is a new version of the <code>EjbModule</code> class that uses a new class, called <code>EjbBinder</code>, that we are going to present in this post.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EjbModule <span style="color: #000000; font-weight: bold;">implements</span> Module <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> configure<span style="color: #009900;">&#40;</span>Binder binder<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">// Bind Context to the default InitialContext.</span>
        binder.<span style="color: #006633;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">to</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">InitialContext</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        EjbBinder ejbs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> EjbBinder<span style="color: #009900;">&#40;</span>binder, <span style="color: #000000; font-weight: bold;">new</span> GlassfishEjbJndiNameStrategy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	ejbs.<span style="color: #006633;">bindRemote</span><span style="color: #009900;">&#40;</span>CurrencyManagerRemote.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>;
	ejbs.<span style="color: #006633;">bind</span><span style="color: #009900;">&#40;</span>DatesManagerRemote.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;com.tzavellas.dates.ejb.DatesManagerBean&quot;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><code>EjbBinder</code> contains two methods named <code>bind</code> and <code>bindRemote</code>. The <code>bind</code> method receives as arguments the expected class and JNDI name and simply uses <code>Binder</code> and <code>JndiItegration</code> to create a binding. The <code>bindRemote</code> method takes as an argument the remote interface of a sesion EJB3 and creates a binding using a JNDI name retrieved from the <code>EjbJndiNameStrategy</code>, that is specified in the <code>EjbBinder</code> constructor (BTW the <code>CurrencyManagerRemote</code> EJB interface in the above code does not relate with the application that we developed in the previous post and it is here to illustrate the <code>bindRemote</code> method).</p>
<p>The definition of the <code>EjbJndiNameStrategy </code>interface:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> EjbJndiNameStrategy <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003399;">String</span> interfaceToJndiName<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> beanInterface<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The implementation of <code>EjbBinder</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.Binder</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.binder.ScopedBindingBuilder</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> com.<span style="color: #006633;">google</span>.<span style="color: #006633;">inject</span>.<span style="color: #006633;">jndi</span>.<span style="color: #006633;">JndiIntegration</span>.<span style="color: #006633;">fromJndi</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EjbBinder <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Binder binder;
    <span style="color: #000000; font-weight: bold;">private</span> EjbJndiNameStrategy jndiNameStrategy;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> EjbBinder<span style="color: #009900;">&#40;</span>Binder binder, EjbJndiNameStrategy nameStrategy<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;">binder</span> <span style="color: #339933;">=</span> binder;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">jndiNameStrategy</span> <span style="color: #339933;">=</span> nameStrategy;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> ScopedBindingBuilder bindRemote<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> beanInterface<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> bind<span style="color: #009900;">&#40;</span>beanInterface,
                jndiNameStrategy.<span style="color: #006633;">interfaceToJndiName</span><span style="color: #009900;">&#40;</span>beanInterface<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> ScopedBindingBuilder bind<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> beanInterface, <span style="color: #003399;">String</span> jndiName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> binder.<span style="color: #006633;">bind</span><span style="color: #009900;">&#40;</span>beanInterface<span style="color: #009900;">&#41;</span>
                .<span style="color: #006633;">toProvider</span><span style="color: #009900;">&#40;</span>fromJndi<span style="color: #009900;">&#40;</span>beanInterface, jndiName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Application Server Specific Naming Strategies</h3>
<p>When you create a new EJB and you do not specify a JNDI name, the application server assigns a default name for you. So, if you have an implementation of <code>EjbJndiNameStrategy</code> that uses the naming rules of your application server you could avoid the need to specify a JNDI name when creating the EJB and when creating the binding of the EJB to Guice.</p>
<p>Below we have two implementations of the <code>EjbJndiNameStrategy</code> that can infer the JNDI name of an EJB&#8217;s remote client interface using the remote interface&#8217;s class for the Glassfish and JBoss application servers.</p>
<p>For the Glassfish application server the default global JNDI name of an EJB with a remote interface is the <a href="https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment" onclick="javascript:pageTracker._trackPageview ('/outbound/glassfish.dev.java.net');">fully qualified name of the remote interface</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GlassfishEjbJndiNameStrategy <span style="color: #000000; font-weight: bold;">implements</span> EjbJndiNameStrategy <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> interfaceToJndiName<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> beanInterface<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> beanInterface.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For the JBoss application server the default JNDI name for the remote interface of an EJB is <em>earName/beanName/remote</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//WARNING: Not tested!</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JbossEjbJndiNameStrategy <span style="color: #000000; font-weight: bold;">implements</span> EjbJndiNameStrategy <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> earName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> JbossEjbJndiNameStrategy<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;">public</span> JbossEjbJndiNameStrategy<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> earName<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>earName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">&quot;&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>earName.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">earName</span> <span style="color: #339933;">=</span> earName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/&quot;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> interfaceToJndiName<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> beanInterface<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> earName <span style="color: #339933;">+</span> interfaceToBeanName<span style="color: #009900;">&#40;</span>beanInterface<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/remote&quot;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> interfaceToBeanName<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> beanInterface<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> name <span style="color: #339933;">=</span> beanInterface.<span style="color: #006633;">getSimpleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>name.<span style="color: #006633;">endsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Remote&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            name <span style="color: #339933;">=</span> name.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Remote&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>;    
        <span style="color: #000000; font-weight: bold;">return</span> name <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;Bean&quot;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Dependency Injection in Struts2 for stateless EJBs part 1</title>
		<link>http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-1/</link>
		<comments>http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-1/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 11:38:10 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[EJB]]></category>

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-1/</guid>
		<description><![CDATA[In this post I will present a way to use dependency injection of stateless session beans in Struts 2 actions using Guice. I will only write about EJB3, because they have simpler client lookup code, but you might be able to change the presented code to cover older versions of EJB.
We will use off the [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will present a way to use dependency injection of stateless session beans in Struts 2 actions using Guice. I will only write about EJB3, because they have simpler client lookup code, but you might be able to change the presented code to cover older versions of EJB.</p>
<p>We will use off the shelf Struts 2 and off the shelf Guice (with the Guice Struts 2 plug-in). No extra &#8220;glue&#8221; code is required to inject stateless EJBs into a Struts actions with Guice. In the next post I will tweak the presented code and make the binding of EJBs in Guice modules simpler.</p>
<p>This post is divided in two sections. In the first section we will create a simple, complete, hello-world type application using Struts 2. The application will consist of only one action that when called will print the current date in a JSP page. Then we will write a stateless session EJB and use Guice to inject the EJB into the action. If you are already familiar with Struts 2 you might want to skip the first section and go directly to the second.</p>
<h2>A basic Struts 2.x application</h2>
<p>Below you will find a series of steps with all code for our mini application.</p>
<h3>1. Project setup</h3>
<p>With your favorite IDE create an enterprise project. You need to create an enterprise project (ear based deployment) and not a web project (war based deployment) because we will create an EJB in the next section.</p>
<p>Now add a web module into your enterprise project and add the following jars to <em>WEB-INF/lib</em>: commons-logging-1.1.jar, freemarker-2.3.8.jar, ognl-2.6.11.jar, struts2-core-2.0.8.jar and xwork-2.0.3.jar.</p>
<p>Although I am a happy Eclipse user I have to admit that Eclipse has very basic support for Java EE 5, so for the code of this post I used Netbeans 6.0 M9 with Glassfish 2 Beta as the application server. Netbeans IMHO is not so good for Java editing but has decent support for the latest Java EE standards. Please keep in mind that the code is only tested with Glassfish 2 Beta.</p>
<h3>2. Edit web.xml</h3>
<p>The below code is the minimum web.xml needed for a Struts 2 application. It contains the Struts 2 filter definition (<code>FilterDispatcher</code>) and a welcome file (<em>index.html</em>) that it is used to redirect the user to the default Struts 2 action.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>struts2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.struts2.dispatcher.FilterDispatcher<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>struts2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>3. Create struts.xml</h3>
<p>Now we need to create the struts.xml file. This file is located at the root of your classpath. The below code has some basic configuration parameters and includes the <em>dates</em> Struts package that will contain our action.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE struts PUBLIC</span>
<span style="color: #00bbdd;">    &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;</span>
<span style="color: #00bbdd;">    &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;struts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constant</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;struts.enable.DynamicMethodInvocation&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constant</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;struts.devMode&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Include the package with our actions --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;dates.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/struts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>4. Create the dates Struts package</h3>
<p>Create the dates.xml file at the root of your classpath as we specified in the above struts.xml. In this file we define a package named <em>dates</em> and mapped under <em>&lt;context-root&gt;/dates/*</em> URL.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE struts PUBLIC</span>
<span style="color: #00bbdd;">        &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;</span>
<span style="color: #00bbdd;">        &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;struts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;package</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dates&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;/dates&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;struts-default&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CurrentDate&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.tzavellas.dates.web.CurrentDateAction&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/jsp/date.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Add more actions here --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/package<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/struts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The package contains our only action, named <code>CurrentDate</code> and mapped to the URL <em>&lt;context-root&gt;/dates/CurrentDate.action</em>. </p>
<h3>5. Create the welcome file</h3>
<p>Now we will create our welcome file that redirects the user to the Struts action. This is a simple HTML page named index.html (as defined in web.xml) and located under the context root. The page uses a meta tag to redirect to the URL of the action .</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Refresh&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;0;URL=dates/CurrentDate.action&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Loading ...<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>6. Code the action</h3>
<p>Finally it&#8217;s time for some Java code. The below code is a simple Struts 2 action that when called will set the value of the <code>currentDate</code> property to the current date.</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.dates.web</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.opensymphony.xwork2.ActionSupport</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CurrentDateAction <span style="color: #000000; font-weight: bold;">extends</span> ActionSupport <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399; font-weight: bold;">Date</span> currentDate;
&nbsp;
    @<span style="color: #003399; font-weight: bold;">Override</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">String</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span>
        currentDate = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">return</span> SUCCESS;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Date</span> getCurrentDate<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> currentDate;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;</span>/code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Note that unlike Servlets or Struts 1 actions, in Struts 2 for every HTTP request a new action instance is created so it is safe to mutate an action property (like the <code>currentDate</code> above) with request specific data.</p>
<h3>7. Create the view</h3>
<p>As we defined in the dates package (<em>dates.xml</em>) the view for the <code>CurrentDateAction</code> is a JSP file localed in <em>WEB-INF/jsp/date.jsp</em>. The below code, for the <em>date.jsp</em> page, uses the Struts 2 tag library to display the value of the <code>currentDate</code> property of the action.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span>%@ page <span style="color: #000066;">contentType</span>=<span style="color: #ff0000;">&quot;text/html&quot;</span> <span style="color: #000066;">pageEncoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span>%@ taglib <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;s&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;/struts-tags&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">   &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The current date<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The current date is: <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:property</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;currentDate&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>We&#8217;ve just created a simple application with Struts 2. In the next section we are going to define a stateless session EJB3 and wire it with the above action using Guice.</p>
<p>For more information about the Struts 2 web framework visit the <a href="http://cwiki.apache.org/WW/home.html" onclick="javascript:pageTracker._trackPageview ('/outbound/cwiki.apache.org');">Struts 2 wiki</a> pages.</p>
<h2>The EJB and the integration with Guice</h2>
<h3>8. Create the stateless session EJB3</h3>
<p>With your favorite IDE add an EJB module to the enterprise project we created in <em>step 1</em>.</p>
<p>Below we define the SLSB with a remote interface and one method that returns the current date. The bean is mapped to the global JNDI name <em>com.tzavellas.dates.ejb.DatesManagerBean</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.dates.ejb</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.Stateless</span>;
&nbsp;
@Stateless<span style="color: #009900;">&#40;</span>mappedName=<span style="color: #0000ff;">&quot;com.tzavellas.dates.ejb.DatesManagerBean&quot;</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> DatesManagerBean <span style="color: #000000; font-weight: bold;">implements</span> DatesManagerRemote <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Date</span> currentDate<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: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.dates.ejb</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ejb.Remote</span>;
&nbsp;
@<span style="color: #003399; font-weight: bold;">Remote</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> DatesManagerRemote <span style="color: #009900;">&#123;</span>
    <span style="color: #003399; font-weight: bold;">Date</span> currentDate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>9. Add the Guice jars in the classpath</h3>
<p>Add guice-1.0.jar and guice-struts2-plugin-1.0.1.jar in <em>WEB-INF/lib</em> directory of your web module. The jar file guice-1.0.jar contains the core Guice implementation and  the guice-struts2-plugin-1.0.1.jar file contains the Guice&#8217;s Struts 2 integration code.</p>
<h3>10. Edit struts.xml to include the Guice plug-in</h3>
<p>Struts 2 is a very flexible framework. One of Struts&#8217; many extensions is the <code>ObjectFactory</code> plug-in interface. The responsibility of an  <code>ObjectFactory</code> is to create the objects managed by Struts. An <code>ObjectFactory</code> is usually a dependency injection container like Spring, Pico and Guice.</p>
<p>To define Guice as the <code>ObjectFactory</code> of our Struts 2 application we have to set the <em>struts.objectFactory</em> property to <em>guice</em> in the struts.xml file and Guice will then be responsible for instantiating all the Struts managed objects (actions, interceptors, etc) .</p>
<p>To continue add the following lines in struts.xml.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- Use Guice as the ObjectFactory for this application --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constant</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;struts.objectFactory&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;guice&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- When wiring actions use Guice bindings defined in the below module --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constant</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;guice.module&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.tzavellas.dates.web.EjbModule&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<h3>11. Code the EjbModule</h3>
<p>In the above struts.xml we defined two properties, <code>struts.objectFactory</code> and <code>guice.module</code>. To explain the <code>guice.module</code> property and the concept of Guice modules we have to explain the basics of Guice.</p>
<p>Guice is a, Java 5 based, dependency injection container that does constructor, field and setter injection (Guice also has features like support for AOP Alliance interceptors that we are not going to talk about in this post). To configure Guice you create a set of modules. A module implements the <code>com.google.inject.Module</code> interface and contains bindings. Bindings are created with the <code>com.google.inject.Binder</code> that is passed to the <code>configure(Binder)</code> method of a module. A binding is a pair composed of a type (key) and an implementation. An implementation can be an object, a class or a provider (factory). The bindings are consulted by the Guice <code>Injector</code> when doing dependency injection.</p>
<p>In the Guice Struts 2 plug-in the Guice <code>ObjectFactory</code> creates an <code>Injector</code> that then reads the module from the <code>guice.module</code> property in the <em>struts.xml</em> file and uses the bindings that are specified in that module to do dependency injection in Struts 2 actions and interceptors.</p>
<p>All we have to do to enable our EJB to be injected into an action is to create a binding for the client interface of the bean. We can&#8217;t create a binding to a class or instance, because the EJB&#8217;s instances must be instantiated by the EJB container and not by Guice, so we will use a provider that will lookup the EJB from JNDI. The Guice library includes a JNDI provider that we are going to use that it is located in the <code>com.google.inject.jndi.JndiIntegration</code> class.</p>
<p>The below code is the implementation of the <code>EJBModule</code>, which has  only two bindings. The first binds the <code>javax.naming.Context</code> type to the <code>javax.naming.InitialContext</code> implementation. This means that when the Guice <code>Injector</code> finds a field or parameter of type <code>javax.naming.Context</code>, that needs to be injected (marked with the <code>@Inject</code> annotation), it will create a new object of type <code>javax.naming.InitialContext</code> and inject it. This binding is needed by the JNDI provider that we are going to use in the next binding.</p>
<p>The second binding binds our EJB&#8217;s remote interface to the JNDI provider. The JNDI provider is returned from the call to the static <code>JndiIntegration.fromJndi(Class, String)</code> method. To get a JNDI provider we have to specify the expected class and JNDI name. This binding tells the Guice <code>Injector</code> that when it finds a field or parameter of type <code>com.tzavellas.dates.ejb.DatesManagerRemote</code>, that needs to be injected (marked with the <code>@Inject</code> annotation), it should call the provider&#8217;s <code>get()</code> method to retrieve an instance to inject.</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.dates.web</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.Binder</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.Module</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> com.<span style="color: #006633;">google</span>.<span style="color: #006633;">inject</span>.<span style="color: #006633;">jndi</span>.<span style="color: #006633;">JndiIntegration</span>.<span style="color: #006633;">fromJndi</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.tzavellas.dates.ejb.DatesManagerRemote</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.naming.Context</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.naming.InitialContext</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EjbModule <span style="color: #000000; font-weight: bold;">implements</span> Module <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> configure<span style="color: #009900;">&#40;</span>Binder binder<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>        
         <span style="color: #666666; font-style: italic;">// Bind Context to the default InitialContext.</span>
        binder.<span style="color: #006633;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Context</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">to</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">InitialContext</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #666666; font-style: italic;">// Bind the remote interface to the JNDI name using the JNDI Provider</span>
        binder.<span style="color: #006633;">bind</span><span style="color: #009900;">&#40;</span>DatesManagerRemote.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #006633;">toProvider</span><span style="color: #009900;">&#40;</span>fromJndi<span style="color: #009900;">&#40;</span>DatesManagerRemote.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;com.tzavellas.dates.ejb.DatesManagerBean&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For more information on how to do dependency injection with Guice see the <a href="http://docs.google.com/View?docid=dd2fhx4z_5df5hw8" onclick="javascript:pageTracker._trackPageview ('/outbound/docs.google.com');">Guice User&#8217;s Guide</a>.</p>
<h3>12. Change the action to use the EJB</h3>
<p>Now that Guice instantiates our actions we can use the normal Guice <code>@Inject</code> annotation to mark an injection point in the action class. We can use any of the constructor, setter and field injection mechanisms. The below code uses field injection because it might be more familiar to EJB3 developers.</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.dates.web</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.Inject</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.opensymphony.xwork2.ActionSupport</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.tzavellas.dates.ejb.DatesManagerRemote</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CurrentDateAction <span style="color: #000000; font-weight: bold;">extends</span> ActionSupport <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Guice field injection of the SLSB</span>
    @Inject DatesManagerRemote bean;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399; font-weight: bold;">Date</span> currentDate;
&nbsp;
    @<span style="color: #003399; font-weight: bold;">Override</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">String</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span> <span style="color: #009900;">&#123;</span>
        currentDate = bean.<span style="color: #006633;">currentDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">return</span> SUCCESS;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Date</span> getCurrentDate<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> currentDate;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Conclusion</h3>
<p>We are done. We&#8217;ve just coded a simple Struts 2 application that uses Guice to inject stateless session EJB3s to Struts actions. You can follow the instructions outlined above to do the same into your applications.</p>
<h3>Appendix: Quick summary of all the steps</h3>
<p>Assuming that you have a working Struts 2 application, below you will find a series of steps you could follow to do dependency injection of your stateless EJB3s into your Struts 2 actions.</p>
<p>For your project:</p>
<ol>
<li>Include the Guice jars in the <em>WEB-INF/lib</em> directory.</li>
<li>Define a Guice module that will contain the bindings for your EJBs.</li>
<li>Edit the struts.xml to define Guice as your <code>ObjectFactory</code> and include the above module.</li>
</ol>
<p>For every EJB that you want to inject into your Struts actions:</p>
<ol>
<li>Inside the module, define a binding for the EJB using the Guice <code>Provider</code> from <code>com.google.inject.jndi.JndiIntegration</code> class, by specifying the bean&#8217;s client interface and the global JNDI name of the bean (or an ejb-ref if you have one defined in web.xml).</li>
<li>Use the <code>@Inject</code> annotation in the Struts actions where you want the EJBs injected.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/07/03/using-dependency-injection-in-struts2-for-stateless-ejbs-part-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C# Extension methods</title>
		<link>http://www.tzavellas.com/techblog/2007/06/02/c-extension-methods/</link>
		<comments>http://www.tzavellas.com/techblog/2007/06/02/c-extension-methods/#comments</comments>
		<pubDate>Sat, 02 Jun 2007 07:45:33 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[.Net]]></category>

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

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/06/02/c-extension-methods/</guid>
		<description><![CDATA[Scott Hanselman has a post about a user who doesn&#8217;t get what is cool about Ruby.
In the post you can find the below example that compares Java and Ruby in terms of code readability.
The Java code:

new Date&#40;new Date&#40;&#41;.getTime&#40;&#41; - 20 * 60 * 1000&#41;

The Ruby code:

20.minutes.ago

The article was interesting but what really caught my attention [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.hanselman.com/blog/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.hanselman.com');">Scott Hanselman</a> has a <a href="http://www.hanselman.com/blog/ProgrammerIntentOrWhatYoureNotGettingAboutRubyAndWhyItsTheTits.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/www.hanselman.com');">post</a> about a user who doesn&#8217;t get what is cool about <a href="http://www.ruby-lang.org/en/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.ruby-lang.org');">Ruby</a>.</p>
<p>In the post you can find the below example that compares <a href="http://java.sun.com" onclick="javascript:pageTracker._trackPageview ('/outbound/java.sun.com');">Java</a> and <a href="http://www.ruby-lang.org/en/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.ruby-lang.org');">Ruby</a> in terms of code readability.</p>
<p>The Java code:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</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: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">20</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: #009900;">&#41;</span></pre></div></div>

<p>The Ruby code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">20.<span style="color:#9900CC;">minutes</span>.<span style="color:#9900CC;">ago</span></pre></div></div>

<p>The article was interesting but what really caught my attention was some comments from C# programmers who showed how, in a few lines of code, you can mimic the Ruby syntax in C# using extension methods.</p>
<p>The new version of C#, shipped with the <a href="http://msdn2.microsoft.com/en-us/vstudio/aa700830.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/msdn2.microsoft.com');">Orcas</a> release of Visual Studio, has a new feature called extension methods. Extension methods were added to the .Net languages to support <a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/msdn2.microsoft.com');">LINQ</a> and they provide a way to attach methods to classes without changing their code.</p>
<p>The below code is copied and modified from the comments of Ian Cooper in the  aforementioned <a href="http://www.hanselman.com/blog/ProgrammerIntentOrWhatYoureNotGettingAboutRubyAndWhyItsTheTits.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/www.hanselman.com');">blog post</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> TimeExtensions <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> TimeSpan Minutes<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> <span style="color: #FF0000;">int</span> numberOfMinutes<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> TimeSpan<span style="color: #000000;">&#40;</span>0, numberOfMinutes, 0<span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> DateTime Ago<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> TimeSpan numberOfMinutes<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">return</span> DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">Subtract</span><span style="color: #000000;">&#40;</span>numberOfMinutes<span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In the above code we defined a class, called <code>TimeExtensions</code>, which contains two extension methods. Notice the <code>this</code> keyword on the left of the fist parameter (both methods take one parameter in the example code) of the methods. The <code>this</code> keyword tells the C# compiler that a method is an extension method. The parameter annotated with the <code>this</code> keyword is the object on which the extension method is called. If I am correct, the methods are not really added to the classes (you can&#8217;t find them via reflection), the compiler at-compile-time translates them into static method calls.</p>
<p>In our example the first method, called <code>Minutes</code>, will be added to the <code>int</code> class (probably via auto-boxing) and the second method, called <code>Ago</code>, will be added to the <code>TimeSpan</code> class.</p>
<p>Now, to use the extension methods that we defined above we have to import them using the <code>using TimeExtensions</code> statement. This is a really good thing since the usage of extension methods is always explicit. You have to import them to use them and if you don&#8217;t want to use them you don&#8217;t import them.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span>;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">TimeExtensions</span>;
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> HelloWorld <span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> 20.<span style="color: #0000FF;">Minutes</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Ago</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><code>20.Minutes().Ago()</code> is pretty close to <code>20.minutes.ago</code> <img src='http://www.tzavellas.com/techblog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>For a nice tutorial about C# 3.0 extension methods see: <a href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/weblogs.asp.net');">New &#8220;Orcas&#8221; Language Feature: Extension Methods</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/06/02/c-extension-methods/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Making Maven 2 work with JUnit 4</title>
		<link>http://www.tzavellas.com/techblog/2007/05/16/making-maven-2-work-with-junit-4/</link>
		<comments>http://www.tzavellas.com/techblog/2007/05/16/making-maven-2-work-with-junit-4/#comments</comments>
		<pubDate>Wed, 16 May 2007 04:38:51 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[JUnit]]></category>

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

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/05/16/making-maven-2-work-with-junit-4/</guid>
		<description><![CDATA[The current stable version (2.2) of the maven-surefire-plugin does not support JUnit 4. So Maven, out of the box, does not work with JUnit 4. Luckily if we want to use JUnit 4 in our Maven based projects we have two choices. The first is to use JUnit4TestAdapter as illustrated in this post. The second [...]]]></description>
			<content:encoded><![CDATA[<p>The current stable version (2.2) of the <a href="http://maven.apache.org/plugins/maven-surefire-plugin/" onclick="javascript:pageTracker._trackPageview ('/outbound/maven.apache.org');">maven-surefire-plugin</a> <a href="http://jira.codehaus.org/browse/SUREFIRE-31" onclick="javascript:pageTracker._trackPageview ('/outbound/jira.codehaus.org');">does not support JUnit 4</a>. So Maven, out of the box, does not work with JUnit 4. Luckily if we want to use JUnit 4 in our Maven based projects we have two choices. The first is to use <code>JUnit4TestAdapter</code> as illustrated in <a href="http://www.jroller.com/page/eu?entry=running_junit_4_test_cases" onclick="javascript:pageTracker._trackPageview ('/outbound/www.jroller.com');">this</a> post. The second is to use the snapshot version (2.3-SNAPSHOT) of the maven-surefire-plugin that has support for JUnit 4. In a small pet-project I am currently implementing I chose the second option and so far my experience was without any problems.</p>
<p>To use the 2.3-SNAPSHOT you first have to add the Maven snapshot plugin repository into your list of plugin repositories. In your <em>pom.xml</em> add the below XML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pluginRepositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pluginRepository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>apache.org<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Maven Plugin Snapshots<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://people.apache.org/repo/m2-snapshot-repository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;releases<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/enabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/releases<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;snapshots<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/enabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/snapshots<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pluginRepository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pluginRepositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You can also put this configuration into your <em>~/.m2/settings.xml</em> file to enable this repository for all your projects.</p>
<p>Then go to the maven-surefire-plugin configuration section and change the version from <em>2.2</em> to <em>2.3-SNAPSHOT</em>. For example below I have the maven-surefire-plugin configuration that I use in my pet-project:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-surefire-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.3-SNAPSHOT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>**/*Test.java<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forkMode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>once<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/forkMode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>        
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>          
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>That&#8217;s it, you are done. When you run Maven again the new (2.3-SNAPSHOT) version will be downloaded and you can start using JUnit 4 in you project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/05/16/making-maven-2-work-with-junit-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Greek Java Champions</title>
		<link>http://www.tzavellas.com/techblog/2007/04/03/greek-java-champions/</link>
		<comments>http://www.tzavellas.com/techblog/2007/04/03/greek-java-champions/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 14:33:01 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[JHUG]]></category>

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/04/03/greek-java-champions/</guid>
		<description><![CDATA[Panos and Paris, the JHUG&#8217;s JUG leaders, are now Java Champions.
Congrats guys, keep it up!
]]></description>
			<content:encoded><![CDATA[<p><a href="http://panoskonstantinidis.blogspot.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/panoskonstantinidis.blogspot.com');">Panos</a> and <a href="http://javapapo.blogspot.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/javapapo.blogspot.com');">Paris</a>, the <a href="http://www.jhug.gr" onclick="javascript:pageTracker._trackPageview ('/outbound/www.jhug.gr');">JHUG</a>&#8217;s <a href="http://java.sun.com/jugs/" onclick="javascript:pageTracker._trackPageview ('/outbound/java.sun.com');">JUG</a> leaders, are now <a href="https://java-champions.dev.java.net/" onclick="javascript:pageTracker._trackPageview ('/outbound/java-champions.dev.java.net');">Java Champions</a>.</p>
<p>Congrats guys, keep it up!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/04/03/greek-java-champions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>commons.testing</title>
		<link>http://www.tzavellas.com/techblog/2007/04/01/commonstesting/</link>
		<comments>http://www.tzavellas.com/techblog/2007/04/01/commonstesting/#comments</comments>
		<pubDate>Sun, 01 Apr 2007 20:33:20 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[Java]]></category>

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/04/01/commonstesting/</guid>
		<description><![CDATA[For me, this is the best April fool&#8217;s joke for this year.
]]></description>
			<content:encoded><![CDATA[<p>For me, <a href="http://www.mockobjects.com/2007/03/announcing-commonstesting-and.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.mockobjects.com');">this</a> is the best April fool&#8217;s joke for this year.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/04/01/commonstesting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Implementing Seam style @Logger injection with Spring</title>
		<link>http://www.tzavellas.com/techblog/2007/03/31/implementing-seam-style-logger-injection-with-spring/</link>
		<comments>http://www.tzavellas.com/techblog/2007/03/31/implementing-seam-style-logger-injection-with-spring/#comments</comments>
		<pubDate>Sat, 31 Mar 2007 15:23:44 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Spring Framework]]></category>

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/03/31/implementing-seam-style-logger-injection-with-spring/</guid>
		<description><![CDATA[Seam provides a number of features to help programmers with the tedious but necessary logging. One of them is the @Logger annotation that is used to inject a Seam Log instance into a Seam component. For example instead of writing:

private Log log = LogFactory.getLog&#40;MyClass.class&#41;;

you can write:

@Logger private Log log;

and Seam will inject an appropriate logger. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jboss.com/products/seam" onclick="javascript:pageTracker._trackPageview ('/outbound/www.jboss.com');">Seam</a> provides a number of <a href="http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/concepts.html#d0e3162" onclick="javascript:pageTracker._trackPageview ('/outbound/docs.jboss.com');">features</a> to help programmers with the tedious but necessary logging. One of them is the <code>@Logger</code> annotation that is used to inject a <a href="http://www.jboss.com/products/seam" onclick="javascript:pageTracker._trackPageview ('/outbound/www.jboss.com');">Seam</a> Log instance into a <a href="http://www.jboss.com/products/seam" onclick="javascript:pageTracker._trackPageview ('/outbound/www.jboss.com');">Seam</a> component. For example instead of writing:</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> Log log = LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>MyClass.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>you can write:</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;">@<span style="color: #003399; font-weight: bold;">Logger</span> <span style="color: #000000; font-weight: bold;">private</span> Log log;</pre></div></div>

<p>and <a href="http://www.jboss.com/products/seam" onclick="javascript:pageTracker._trackPageview ('/outbound/www.jboss.com');">Seam</a> will inject an appropriate logger. Below we will try to to implement this feature using the <a href="http://springframework.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/springframework.org');">Spring Framework</a> for objects managed by the Spring DI container (actually a  <a href="http://www.springframework.org/docs/api/org/springframework/beans/factory/BeanFactory.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');"><code>BeanFactory</code></a>).</p>
<p>The Spring DI container provides a number of extension interfaces that beans can implement to get callbacks from the container in various stages of the container operation. One callback interface is the <a href="http://www.springframework.org/docs/api/org/springframework/beans/factory/config/BeanPostProcessor.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');"><code>BeanPostProcessor</code></a>. <a href="http://www.springframework.org/docs/api/org/springframework/beans/factory/config/BeanPostProcessor.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');"><code>BeanPostProcessor</code></a>s are called before and after the initialization of each bean and allow the custom modification of bean instances (for example wrapping an instance with a <a href="http://java.sun.com/j2se/1.3/docs/guide/reflection/proxy.html" onclick="javascript:pageTracker._trackPageview ('/outbound/java.sun.com');">dynamic proxy</a>).</p>
<p>The only thing we have to do to implement the <code>@Logger</code> injection (besides defining a <code>@Logger</code> annotation) is to write a <a href="http://www.springframework.org/docs/api/org/springframework/beans/factory/config/BeanPostProcessor.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');"><code>BeanPostProcessor</code></a> that, before each bean gets initialized (right after it gets constructed), will iterate over the fields of the bean to detect any <code>@Logger</code> annotations and construct and inject a new logger instance.</p>
<p>Let&#8217;s define the annotation:</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.spring.logger</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">annotation</span>.<span style="color: #003399; font-weight: bold;">ElementType</span>.<span style="color: #006633;">FIELD</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> java.<span style="color: #006633;">lang</span>.<span style="color: #006633;">annotation</span>.<span style="color: #003399; font-weight: bold;">RetentionPolicy</span>.<span style="color: #006633;">RUNTIME</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Documented</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Retention</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Target</span>;
&nbsp;
@<span style="color: #003399; font-weight: bold;">Retention</span><span style="color: #009900;">&#40;</span>RUNTIME<span style="color: #009900;">&#41;</span>
@<span style="color: #003399; font-weight: bold;">Target</span><span style="color: #009900;">&#40;</span>FIELD<span style="color: #009900;">&#41;</span>
@<span style="color: #003399; font-weight: bold;">Documented</span>
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> <span style="color: #003399; font-weight: bold;">Logger</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>and now the <code>BeanPostProcessor</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.spring.logger</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Field</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.logging.Log</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.logging.LogFactory</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.BeansException</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.config.BeanPostProcessor</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.util.ReflectionUtils</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">springframework</span>.<span style="color: #006633;">util</span>.<span style="color: #006633;">ReflectionUtils</span>.<span style="color: #006633;">FieldCallback</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoggerPostProcessor <span style="color: #000000; font-weight: bold;">implements</span> BeanPostProcessor <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Object</span> postProcessAfterInitialization<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Object</span> bean, <span style="color: #003399; font-weight: bold;">String</span> beanName<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> BeansException <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> bean;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399; font-weight: bold;">Object</span> postProcessBeforeInitialization<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399; font-weight: bold;">Object</span> bean, <span style="color: #003399; font-weight: bold;">String</span> beanName<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> BeansException <span style="color: #009900;">&#123;</span>
    ReflectionUtils.<span style="color: #006633;">doWithFields</span><span style="color: #009900;">&#40;</span>bean.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> FieldCallback<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;">public</span> <span style="color: #006600; font-weight: bold;">void</span> doWith<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Field</span> field<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">IllegalArgumentException</span>, <span style="color: #003399; font-weight: bold;">IllegalAccessException</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>field.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Logger</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!</span>= <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          Log log = LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>bean.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
          field.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span>bean, log<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">return</span> bean;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Below I have a small <a href="http://www.junit.org" onclick="javascript:pageTracker._trackPageview ('/outbound/www.junit.org');">JUnit</a> test to verify that it works:</p>

<div class="wp_syntax"><div class="code"><pre class="java5 java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.tzavellas.spring.logger</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">junit</span>.<span style="color: #006633;">Assert</span>.*;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.logging.Log</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Before</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.support.DefaultListableBeanFactory</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.factory.support.RootBeanDefinition</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoggerPostProcessorTest <span style="color: #009900;">&#123;</span>
&nbsp;
  DefaultListableBeanFactory factory = <span style="color: #000000; font-weight: bold;">new</span> DefaultListableBeanFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
  @Before
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> setupFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    RootBeanDefinition bean = <span style="color: #000000; font-weight: bold;">new</span> RootBeanDefinition<span style="color: #009900;">&#40;</span>Bean.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
    factory.<span style="color: #006633;">addBeanPostProcessor</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LoggerPostProcessor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    factory.<span style="color: #006633;">registerBeanDefinition</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bean&quot;</span>, bean<span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @Test
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> injectLogger<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Bean b = <span style="color: #009900;">&#40;</span>Bean<span style="color: #009900;">&#41;</span> factory.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bean&quot;</span><span style="color: #009900;">&#41;</span>;
    assertNotNull<span style="color: #009900;">&#40;</span>b.<span style="color: #006633;">log</span><span style="color: #009900;">&#41;</span>;
    b.<span style="color: #006633;">doSomething</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Bean <span style="color: #009900;">&#123;</span>
&nbsp;
  @<span style="color: #003399; font-weight: bold;">Logger</span> Log log;
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> doSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is a very simple implementation since the goal of this article is to demonstrate the extensibility of the Spring DI container and not to implement a complete solution. One limitation is that this implementation only injects loggers (actually commons-logging Logs) to public fields (Seam can inject Seam Logger to private fields).</p>
<p>To use the above in a Spring XML file you simply define a bean with class <code>com.tzavellas.spring.logging.LoggerPostProcessor</code> (the id/name is not needed). The <code>BeanFactory</code>/<code>ApplicationContext</code> will automatically detect all beans that implement the <code>BeanPostProcessor</code> interface at startup time and will initialize them and then call them every time a bean gets initialized.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/03/31/implementing-seam-style-logger-injection-with-spring/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New features in Spring IDE 2.0M3</title>
		<link>http://www.tzavellas.com/techblog/2007/03/15/new-features-in-spring-ide-20m3/</link>
		<comments>http://www.tzavellas.com/techblog/2007/03/15/new-features-in-spring-ide-20m3/#comments</comments>
		<pubDate>Thu, 15 Mar 2007 14:12:21 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Spring Framework]]></category>

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/03/15/new-features-in-spring-ide-20m3/</guid>
		<description><![CDATA[Spring IDE 2.0M3 was released and the springframework.org site writes about the long-awaited Spring Webflow support. Spring IDE now includes graphical and XML editors for Spring WebFlow.
I believe that this major new feature hides 3 very important new features that IMHO programmers will find more useful, since people working with Spring spend more time editing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.springide.org/project/wiki/SpringIde2Milestone3" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springide.org');">Spring IDE 2.0M3</a> was released and the <a href="http://www.springframework.org" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');">springframework.org</a> site writes about the long-awaited <a href="http://www.springframework.org/node/429" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');">Spring Webflow support</a>. <a href="http://www.springide.org" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springide.org');">Spring IDE</a> now includes graphical and XML editors for <a href="http://www.springframework.org/webflow" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');">Spring WebFlow</a>.</p>
<p>I believe that this major new feature hides 3 very important new features that IMHO programmers will find more useful, since people working with <a href="http://www.springframework.org" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springframework.org');">Spring</a> spend more time editing Spring XML files than WebFlow XML files.  </p>
<h3>New Spring 2.0M3 features for Spring XML</h3>
<ul>
<li>Spring IDE now integrates with class reference search (Shift+Ctrl+G). This means that the results of class reference search now also include Spring beans.</li>
<li>The XML bean editor now supports renaming of bean ids (Refactor -> Rename bean element, or Alt+Shift+R)</li>
<li>Spring IDE now participates in class refactorings (class rename, class move and property rename).</li>
</ul>
<p>See the <a href="http://www.springide.org/project/wiki/SpringIde2Milestone3" onclick="javascript:pageTracker._trackPageview ('/outbound/www.springide.org');">changelog</a> of the 2.0M3 release for more information about changes and new features.</p>
<p>I am using the Spring IDE 2.0 milestones from the development update site and I am very satisfied with all the new features. The <a href="http://springide.org/project/wiki/SpringideTeam" onclick="javascript:pageTracker._trackPageview ('/outbound/springide.org');">Spring IDE team</a> is doing a great job (thanks guys) and I believe that the 2.0 release is going to be a huge step forward.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/03/15/new-features-in-spring-ide-20m3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Oracle Toplink is now open source</title>
		<link>http://www.tzavellas.com/techblog/2007/03/13/oracle-toplink-is-now-open-source/</link>
		<comments>http://www.tzavellas.com/techblog/2007/03/13/oracle-toplink-is-now-open-source/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 05:50:12 +0000</pubDate>
		<dc:creator>spiros</dc:creator>
		
		<category><![CDATA[Databases]]></category>

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

		<guid isPermaLink="false">http://www.tzavellas.com/techblog/2007/03/13/oracle-toplink-is-now-open-source/</guid>
		<description><![CDATA[Oracle has released the Toplink O/R mapping framework as open source. They proposed a new persistence project, named Eclipse Persistence Platform (or EclipseLink for short), at the Eclipse Foundation and they are donating the Toplink source code to start the project.
The EclipseLink will be a runtime project offering only libraries and no IDE tooling. Other [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.oracle.com" onclick="javascript:pageTracker._trackPageview ('/outbound/www.oracle.com');">Oracle</a> has released the <a href="http://www.oracle.com/technology/products/ias/toplink/index.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.oracle.com');">Toplink</a> <acronym title="Object / Relational">O/R</acronym> mapping framework as open source. They proposed a new persistence project, named Eclipse Persistence Platform (or EclipseLink for short), at the <a href="http://www.eclipse.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.eclipse.org');">Eclipse Foundation</a> and they are donating the <a href="http://www.oracle.com/technology/products/ias/toplink/index.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.oracle.com');">Toplink</a> source code to start the project.</p>
<p>The EclipseLink will be a runtime project offering only libraries and no IDE tooling. Other Eclipse projects, like <a href="http://www.eclipse.org/dali/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.eclipse.org');">Dali</a>, offer tooling for <acronym title="Java Persistence API">JPA</acronym> and <acronym title="Object / Relational">O/R</acronym> mapping. The project will include the <a href="http://http://www.oracle.com/technology/products/ias/toplink/index.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.oracle.com');">Toplink</a> <acronym title="Object / Relational">O/R</acronym> mapping tools and APIs, a <acronym title="Java Persistence API">JPA</acronym> implementation, an <acronym title="Object XML Mapping">OXM</acronym> framework, a <acronym title="Service Data Objects">SDO</acronym> implementation and other persistence related technologies.</p>
<p><a href="http://www.oracle.com/technology/products/ias/toplink/index.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.oracle.com');">Toplink</a> is a very mature and successful product. It is maybe the fist successful <acronym title="Object / Relational">O/R</acronym> mapping product for <a href="http://java.sun.com" onclick="javascript:pageTracker._trackPageview ('/outbound/java.sun.com');">Java</a> and it is great to see <a href="http://www.oracle.com" onclick="javascript:pageTracker._trackPageview ('/outbound/www.oracle.com');">Oracle</a> donating it to the open source community.</p>
<p>For more information see:</p>
<ul>
<li><a href="http://www.oracle.com/technology/products/ias/toplink/index.html" onclick="javascript:pageTracker._trackPageview ('/outbound/www.oracle.com');">The Oracle Toplink website</a></li>
<li><a href="http://www.theserverside.com/news/thread.tss?thread_id=44564" title="TheServerSide" onclick="javascript:pageTracker._trackPageview ('/outbound/www.theserverside.com');">Oracle Proposes Open Source Persistence Project at Eclipse</a></li>
<li><a href="http://www.infoq.com/news/2007/03/toplink-open-source" title="InfoQ" onclick="javascript:pageTracker._trackPageview ('/outbound/www.infoq.com');">Oracle Contributes TopLink ORM Open Source to Eclipse</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tzavellas.com/techblog/2007/03/13/oracle-toplink-is-now-open-source/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
