<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SteveJ's Blog &#187; Java</title>
	<atom:link href="http://blog.stefanjaeger.ch/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stefanjaeger.ch</link>
	<description>Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.</description>
	<lastBuildDate>Tue, 16 Jun 2009 08:37:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Expressions in Eclipse Debugger</title>
		<link>http://blog.stefanjaeger.ch/2008/12/12/expressions-in-eclipse-debugger/</link>
		<comments>http://blog.stefanjaeger.ch/2008/12/12/expressions-in-eclipse-debugger/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 21:28:38 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/12/12/expressions-in-eclipse-debugger/</guid>
		<description><![CDATA[Today, I encountered a very helpful feature in Eclipse. When I am debugging code, I sometimes want to know, what’s the result of a method is. If the result it’s not assigned to a variable, it gets complicated. Take a look to this example: what is the result of add(17,19)? 

public class DemoApplication &#123;
&#160;
  [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I encountered a very helpful feature in Eclipse. When I am debugging code, I sometimes want to know, what’s the result of a method is. If the result it’s not assigned to a variable, it gets complicated. Take a look to this example: what is the result of add(17,19)? </p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DemoApplication <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
        DemoApplication calc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DemoApplication<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>calc.<span style="color: #006633;">divide</span><span style="color: #009900;">&#40;</span>calc.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">17</span>, <span style="color: #cc66cc;">19</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> add<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i, <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> i <span style="color: #339933;">+</span> j<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> divide<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i, <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> i <span style="color: #339933;">/</span> j<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In earlier times, I stepped one step further to get into the method divide. Then I got the result of add(17,19) in my parameter. </p>
<p>&#160;</p>
<p>But Eclipse is offering a better solution. In the Debugging Perspective, there is a view called Expressions. Just add a new expression add(17,19) and the Debugger is printing out the result.</p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/image35.png" rel="lightbox"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="259" alt="image" src="http://blog.stefanjaeger.ch/wp-content/image-thumb35.png" width="404" border="0" /></a> </p>
<p>The result is directly printed out:</p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/image36.png" rel="lightbox"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="214" alt="image" src="http://blog.stefanjaeger.ch/wp-content/image-thumb36.png" width="489" border="0" /></a> </p>
<p>&#160;</p>
<p>A simple, but helpful feature in Eclipse!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/12/12/expressions-in-eclipse-debugger/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OSGi &#8211; a brief introduction</title>
		<link>http://blog.stefanjaeger.ch/2008/12/05/osgi-a-brief-introduction/</link>
		<comments>http://blog.stefanjaeger.ch/2008/12/05/osgi-a-brief-introduction/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 21:54:16 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/12/05/osgi-a-brief-introduction/</guid>
		<description><![CDATA[There was a time, OSGi was for me just an “not understandable” abbreviation. Wiki told me, that OSGi is a framework for a dynamic component model. Huh? Is it just a specification or is it an implementation? Didn’t understand it all.
I started about two months with working a little bit with OSGi. I want to [...]]]></description>
			<content:encoded><![CDATA[<p>There was a time, OSGi was for me just an “not understandable” abbreviation. Wiki told me, that OSGi is a framework for a dynamic component model. Huh? Is it just a specification or is it an implementation? Didn’t understand it all.</p>
<p>I started about two months with working a little bit with OSGi. I want to write here these parts, which were unclear for me at the beginning. It should be an introduction for everyone, who has never heard about OSGi.</p>
<p>Okay, let’s start.    </p>
<p>The setup of OSGi is something like EJB. </p>
<ol>
<li>EJB has a specification from Sun. </li>
<li>OSGi has specification from the OSGi Alliance. </li>
<li>EJB need’s an application server as a platform (Weblogic, Glassfish, Websphere, JBoss, and so on) to run an “EJB” application. </li>
<li>OSGi need’s also a platform to run “OSGi” application. Like an application server, which is implementing the EJB contract, an OSGi platform implements the OSGi framework specification. Currently, there some OSGi implementation out there. The most known are Equinox, Apache Felix or Knopflerfish. </li>
</ol>
<p>Okay, now, we know, how OSGi is built. But what does it? In one sentence, it is something like a JVM with some extra features. OSGi extends the JVM and a Java program is running on that OSGi Platform instead of running directly on the JVM. OSGi offers some advantages, which I will mention shortly.</p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/image34.png" rel="lightbox"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="322" alt="image" src="http://blog.stefanjaeger.ch/wp-content/image-thumb34.png" width="401" border="0" /></a>&#160; <br />(Source: <a title="http://de.wikipedia.org/wiki/OSGi" href="http://de.wikipedia.org/wiki/OSGi">http://de.wikipedia.org/wiki/OSGi</a>)</p>
<p>&#160; <br />The difference between a usual Java program (a JAR file) and an OSGi program (let us call that a bundle) are some information in the META-INF\MANIFEST.MF file. These information looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Manifest<span style="color: #339933;">-</span>Version<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1.0</span>
Bundle<span style="color: #339933;">-</span>ManifestVersion<span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span>
Bundle<span style="color: #339933;">-</span><span style="color: #003399;">Name</span><span style="color: #339933;">:</span> Example OSGi bundle
Bundle<span style="color: #339933;">-</span>SymbolicName<span style="color: #339933;">:</span> ch.<span style="color: #006633;">stefanjaeger</span>.<span style="color: #006633;">osgi</span>.<span style="color: #006633;">example</span>
Bundle<span style="color: #339933;">-</span>Version<span style="color: #339933;">:</span> 1.0.0</pre></div></div>

<p>That’s it. An OSGi program (called a bundle) is nothing more than a JAR file with the MANIFEST.MF. Now, you can run this bundle in an OSGi environment like Equinox or Apache Felix.</p>
<p>Okay, know, we come to the advantages of OSGi. The biggest advantage is the ability to run a bundle in different versions at the same time. For example, bundle A has a dependency to bundle B in version 1.0.0 and bundle C has a dependency to bundle B in version 1.1.0. </p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/zeichnung21.png" rel="lightbox"><img title="Zeichnung2" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="107" alt="Zeichnung2" src="http://blog.stefanjaeger.ch/wp-content/zeichnung2-thumb1.png" width="235" border="0" /></a></p>
<p>&#160;</p>
<p>With the usual JVM, you get a problem when running A and C in the same VM. The JVM will take the first “B” in the classpath it found. This means, it is possible, that for C gets the files from B in version 1.0.0 (instead of 1.1.0), which could result in “MethodNotFoundException” and such stuff.<br />
  <br />With OSGi, this problem doesn’t exists anymore. In the MANIFST.MF you can define all dependencies explicitly with the version. Following example means, that our bundle has a dependency to the Apache Commons Lang Package in version between 2.0.0 and 2.1.0.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Require<span style="color: #339933;">-</span>Bundle<span style="color: #339933;">:</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">commons</span>.<span style="color: #006633;">lang</span><span style="color: #339933;">;</span>bundle<span style="color: #339933;">-</span>version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;[2.0.0,2.1.0]&quot;</span></pre></div></div>

<p>The OSGi platform checks at the beginning, that all required bundles are available and solves the classpath problem for us.</p>
<p>Okay, we’re almost finished. There is one important point I want to mention. Packages are not “open” as usual in JAR files. If we want to make some classes accessible for other bundles, we do have to export these packages:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Export<span style="color: #339933;">-</span><span style="color: #000000; font-weight: bold;">Package</span><span style="color: #339933;">:</span> ch.<span style="color: #006633;">stefanjaeger</span>.<span style="color: #006633;">communiction</span>.<span style="color: #006633;">interfaces</span></pre></div></div>

<p>Of course, OSGi can do more than that. But for this introduction, I think, it’s enough<br />
  <br /> <img src='http://blog.stefanjaeger.ch/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/12/05/osgi-a-brief-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sun Certified Business Component Developer Factsheets</title>
		<link>http://blog.stefanjaeger.ch/2008/11/14/sun-certified-business-component-developer/</link>
		<comments>http://blog.stefanjaeger.ch/2008/11/14/sun-certified-business-component-developer/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 17:24:22 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/11/14/sun-certified-business-component-developer/</guid>
		<description><![CDATA[Today, I passed the SCBCD exam! Here some information&#8217;s, which helped me to pass the exam:

Study Guide
http://java.boot.by/scbcd5-guide/
Free Training Test:
http://www.sun.com/training/certification/assessment/

I also wrote some “Factsheets”, which I used to sum up all topics. Besides Factsheet 0, they can also be used as an assistance on the daily EJB 3.0 work.

Factsheet 0 &#8211; some stuff, which is only [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I passed the SCBCD exam! Here some information&#8217;s, which helped me to pass the exam:</p>
<ul>
<li>Study Guide<br />
<a title="http://java.boot.by/scbcd5-guide/" href="http://java.boot.by/scbcd5-guide/">http://java.boot.by/scbcd5-guide/</a></li>
<li>Free Training Test:<br />
<a title="http://www.sun.com/training/certification/assessment/" href="http://www.sun.com/training/certification/assessment/">http://www.sun.com/training/certification/assessment/</a></li>
</ul>
<p>I also wrote some “Factsheets”, which I used to sum up all topics. Besides Factsheet 0, they can also be used as an assistance on the daily EJB 3.0 work.</p>
<ul>
<li><a title="http://blog.stefanjaeger.ch/wp-content/factsheet0_scbcd.pdf" href="http://blog.stefanjaeger.ch/wp-content/factsheet0_scbcd.pdf">Factsheet 0 &#8211; some stuff, which is only for the SCBCD relevant</a></li>
<li><a title="http://blog.stefanjaeger.ch/wp-content/factsheet1_statefulandstatelessbeans.pdf" href="http://blog.stefanjaeger.ch/wp-content/factsheet1_statefulandstatelessbeans.pdf">Factsheet 1 &#8211; Stateful and Stateless Session Beans</a></li>
<li><a title="http://blog.stefanjaeger.ch/wp-content/factsheet2_mdbsandjms.pdf" href="http://blog.stefanjaeger.ch/wp-content/factsheet2_mdbsandjms.pdf">Factsheet 2 &#8211; MDBs and JMS</a></li>
<li><a title="http://blog.stefanjaeger.ch/wp-content/factsheet3_transactionsandsecurity.pdf" href="http://blog.stefanjaeger.ch/wp-content/factsheet3_transactionsandsecurity.pdf">Factsheet 3 &#8211; Transactions and Security</a></li>
<li><a title="http://blog.stefanjaeger.ch/wp-content/factsheet4_jpa1.pdf" href="http://blog.stefanjaeger.ch/wp-content/factsheet4_jpa1.pdf">Factsheet 4 &#8211; JPA, part 1</a></li>
<li><a title="http://blog.stefanjaeger.ch/wp-content/factsheet5_jpa2.pdf" href="http://blog.stefanjaeger.ch/wp-content/factsheet5_jpa2.pdf">Factsheet 5 &#8211; JPA, part 2</a></li>
</ul>
<p>If you find any mistakes in the Factsheet, just let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/11/14/sun-certified-business-component-developer/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Mastering Enterprise JavaBeans 3.0</title>
		<link>http://blog.stefanjaeger.ch/2008/11/12/mastering-enterprise-javabeans-30/</link>
		<comments>http://blog.stefanjaeger.ch/2008/11/12/mastering-enterprise-javabeans-30/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 07:51:33 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/11/12/mastering-enterprise-javabeans-30/</guid>
		<description><![CDATA[If you want to have a good introduction to the topic EJB 3.0, I can recommend you the book “Mastering Enterprise JavaBeans 3.0”. This book can be freely downloaded from TheServerSide.com. 
I am currently preparing for the SCBCD 5.0 and in my opinion, it’s better than the book “Enterprise JavaBans 3.0” from O’Reilly. “Mastering EJB [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to have a good introduction to the topic EJB 3.0, I can recommend you the book “Mastering Enterprise JavaBeans 3.0”. This book can be freely downloaded from <a title="http://www.theserverside.com/tt/books/wiley/masteringEJB3/index.tss" href="http://www.theserverside.com/tt/books/wiley/masteringEJB3/index.tss">TheServerSide.com</a>. </p>
<p>I am currently preparing for the SCBCD 5.0 and in my opinion, it’s better than the book “Enterprise JavaBans 3.0” from O’Reilly. “Mastering EJB 3.0” covers many topics about Java EE much deeper. For example, it mentions poison messages or clustering as&#160; has a very useful overview of all possible annotations in the appendix.</p>
<p>Only the part JPA is not covered as deep as in the O’Reilly book. EmbededId is only mentioned, but not described in detail.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/11/12/mastering-enterprise-javabeans-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean up your Java code</title>
		<link>http://blog.stefanjaeger.ch/2008/11/09/clean-up-your-java-code/</link>
		<comments>http://blog.stefanjaeger.ch/2008/11/09/clean-up-your-java-code/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 11:26:37 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/11/09/clean-up-your-java-code/</guid>
		<description><![CDATA[In Eclipse, there is a nice feature to clean up Java code. First, you can change the Clean Up profile (Window – Preferences) and define, how you want the code should look like.

There are interesting clean ups like “Remove unnecessary casts” or to add missing Annotations like “@Override”. 
 
After creating your profile, simply right [...]]]></description>
			<content:encoded><![CDATA[<p>In Eclipse, there is a nice feature to clean up Java code. First, you can change the Clean Up profile (Window – Preferences) and define, how you want the code should look like.</p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/image32.png" rel="lightbox"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="318" alt="image" src="http://blog.stefanjaeger.ch/wp-content/image-thumb32.png" width="450" border="0" /></a></p>
<p>There are interesting clean ups like “Remove unnecessary casts” or to add missing Annotations like “@Override”. </p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/image33.png" rel="lightbox"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="365" alt="image" src="http://blog.stefanjaeger.ch/wp-content/image-thumb33.png" width="450" border="0" /></a> </p>
<p>After creating your profile, simply right click to the project and choose Source – Clean up.</p>
<p>Nice feature. If you want to know more about this feature, you will find <a href="http://www.ibm.com/developerworks/opensource/library/os-eclipse-clean/index.html">here</a> more information’s.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/11/09/clean-up-your-java-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bidirectional Mapping with JiBX</title>
		<link>http://blog.stefanjaeger.ch/2008/09/26/bidirectional-mapping-with-jibx/</link>
		<comments>http://blog.stefanjaeger.ch/2008/09/26/bidirectional-mapping-with-jibx/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 21:23:03 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/09/26/bidirectional-mapping-with-jibx/</guid>
		<description><![CDATA[In this post, I will cover again the topic JiBX. This time, I will focus on a very special case, the bidirectional mapping with JiBX. To realize that without affecting a currently used domain model (as it will happen if we use pre-set, as described in http://jibx.sourceforge.net/tutorial/binding-extend.html), we need to implement an JiBX Marshaller and [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I will cover again the topic JiBX. This time, I will focus on a very special case, the bidirectional mapping with JiBX. To realize that without affecting a currently used domain model (as it will happen if we use pre-set, as described in <a href="http://jibx.sourceforge.net/tutorial/binding-extend.html">http://jibx.sourceforge.net/tutorial/binding-extend.html</a>), we need to implement an JiBX Marshaller and an JiBX Unmarshaller.</p>
<p>But let me start with the simple problem. We do have two simple POJOs, <a href="http://blog.stefanjaeger.ch/wp-content/customerjava.txt">Customer</a> and <a href="http://blog.stefanjaeger.ch/wp-content/personjava.txt">Person</a>, which do know each other. If you are using for example Hibernate, bidirectional linking is not a rarity. With the <a href="http://blog.stefanjaeger.ch/wp-content/customer-binding-before.xml">JiBX binding XML</a> we used in our last examples, the bidirectional linking is not set. To demonstrate this, I added these two lines of code in the main application:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>customer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>customer.<span style="color: #006633;">getPerson</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCustomer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The second line will result in a NullPointerException, because JiBX is not setting this bidirectional linking. To get that working without affecting the two classes Customer and Person (!), we have to create our own Marshaller and Unmarshaller.</p>
<p>First of all, we have to <a href="http://blog.stefanjaeger.ch/wp-content/customer-binding-rewritten.xml">prepare our mapping file</a>. The best way for a bidirectional mapping is to define an own mapping section for the class Person (which was previously part of the Customer mapping part).</p>
<p>The reason for this step is simple, but important. Our customized Unmarshaller should let JiBX unmarshal the Person into an object and our Unmarshaller should only extend the object with the bidirectional mapping to the Customer. For this reason, JiBX needs an own mapping section for this class.</p>
<p>After preparing the JiBX mapping, our next step is to create a Marshaller and Unmarshaller class. For the bidirectional mapping, we will just need an Unmarshaller. But because we do have a JiBX mapping file for both directions, we do have to define a Marshaller and a Unmarshaller.&#160; <br />We create for this example a new class with the name <a href="http://blog.stefanjaeger.ch/wp-content/bidirectionalmapperjava.txt">BidirectionalMapper</a>, which implements the interfaces IMarshaller, IUnmarshaller and IAliasable. These Interfaces are delivered with the JiBX libraries. In the implementation, there are two remarkable parts in the method unmarshal. The first one just forwards the real unmarshalling action to the JiBX context and the second one creates the bidirectional linking.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Object</span> unmarshalledObject <span style="color: #339933;">=</span> ctx.<span style="color: #006633;">unmarshalElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
Person person <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Person<span style="color: #009900;">&#41;</span> unmarshalledObject<span style="color: #339933;">;</span> 
... 
<span style="color: #003399;">Object</span> parent <span style="color: #339933;">=</span> ctx.<span style="color: #006633;">getStackObject</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
person.<span style="color: #006633;">setCustomer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Customer<span style="color: #009900;">&#41;</span> parent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the marshal method, we also let JiBX marshal our person. Because the bidirectional linking has no affect to this method, this method is just simple.</p>

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

<p>After we created our Mapper, we need to define the marshallers in the <a href="http://blog.stefanjaeger.ch/wp-content/customer-binding-with-unmarshaller.xml">JiBX mapping file</a>. For this reason, we expand the element structure with the marshaller and unmarshaller class path.</p>
<p>If we run now our application again, there is no NullPointerException anymore and we can use our previously used domain model without changing anything at these classes.</p>
<p>If you are interested, you can download the whole eclipse project with all the sources from <a href="http://blog.stefanjaeger.ch/wp-content/jibx_playground.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/09/26/bidirectional-mapping-with-jibx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dependency Analyzer</title>
		<link>http://blog.stefanjaeger.ch/2008/09/25/dependency-analyzer/</link>
		<comments>http://blog.stefanjaeger.ch/2008/09/25/dependency-analyzer/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 16:38:37 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/09/25/dependency-analyzer/</guid>
		<description><![CDATA[
In a software project, Software Engineers need to ensure, that the source code meets the architectural rules. One of a usual architecture rule are the dependencies between the layer and packages. There are a lot of tools, which can be used to ensure, that no class breaks this rules.
If you know, that there are some [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>In a software project, Software Engineers need to ensure, that the source code meets the architectural rules. One of a usual architecture rule are the dependencies between the layer and packages. There are a lot of tools, which can be used to ensure, that no class breaks this rules.</p>
<p>If you know, that there are some specific classes, which do not meet these rules, a dependency code analysis is needed. Therefore, I found a free tool called CDA (<a href="http://www.dependency-analyzer.org/">http://www.dependency-analyzer.org/</a>), which is very helpful in such a situation. It can also be used for repeated check to ensure architecture compatibility, but in this blog entry, I will focus on code analysis.</p>
<p>First of all, just install this tool as described on the website (<a href="http://www.dependency-analyzer.org/#Installation">http://www.dependency-analyzer.org/#Installation</a>). CDA doesn&#8217;t need any installation (just unzip the compressed file) and can be run with Java 1.5.</p>
<p>After finishing the installation procedure, you need to create for every project a Workset. A Workset can contain different code sources, which are analysed together. First, define a Name. After that, go to the Classpath register. The easiest way to use CDA is to analyse a JAR file. Add all JAR files, which you want to analyse.</p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/clip-image003.jpg" rel="lightbox"><img title="clip_image003" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="323" alt="clip_image003" src="http://blog.stefanjaeger.ch/wp-content/clip-image003-thumb.jpg" width="442" border="0" /></a></p>
<p>If you are finished, save the Workset. CDA will load now all classes from the JAR files into a tree. With CTRL + F you can search for a specific class or you can navigate with the package name to a specific class. With right click, you can analyse all dependencies (on which classes/packages does the class depends on) or you can analyse all dependants (which classes/packages depends on the currently selected class). </p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/clip-image005.jpg" rel="lightbox"><img title="clip_image005" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="401" alt="clip_image005" src="http://blog.stefanjaeger.ch/wp-content/clip-image005-thumb.jpg" width="439" border="0" /></a></p>
<p>If you are analysing the dependencies, you can show the classes or packages, on which the specified class depends on. Furthermore, you will see all third-party libraries, on which the class depends on. If you do not want to see some specific packages, you can apply a filter (button “edit filter”), on which you can define excluded packages.</p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/clip-image006.gif" rel="lightbox"><img title="clip_image006" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="234" alt="clip_image006" src="http://blog.stefanjaeger.ch/wp-content/clip-image006-thumb.gif" width="443" border="0" /></a></p>
<p>The generated graph looks like following. It is almost the same as the textual dependency view, with the exception, that no third-party libraries are shown. </p>
<p><a href="http://blog.stefanjaeger.ch/wp-content/clip-image008.jpg" rel="lightbox"><img title="clip_image008" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="309" alt="clip_image008" src="http://blog.stefanjaeger.ch/wp-content/clip-image008-thumb.jpg" width="437" border="0" /></a></p>
<p>This tool is user friendly. If you are using this tool, you will very fast get to work with it. I use this tool to find dependants on a class and to draw simple UML diagrams of a class (very useful if you want to draw a UML diagram from just one class with all it dependencies).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/09/25/dependency-analyzer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterate backwards through a List</title>
		<link>http://blog.stefanjaeger.ch/2008/08/06/iterate-backwards-through-a-list/</link>
		<comments>http://blog.stefanjaeger.ch/2008/08/06/iterate-backwards-through-a-list/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 17:21:04 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/08/06/iterate-backwards-through-a-list/</guid>
		<description><![CDATA[Today, I had the problem to iterate backwards in a ArrayList. Didn’t know, there is a ListIterator:

List&#60;String&#62; theList = new ArrayList&#60;String&#62;&#40;&#41;; 
theList.add&#40;&#34;a&#34;&#41;; 
theList.add&#40;&#34;b&#34;&#41;; 
theList.add&#40;&#34;c&#34;&#41;; 
ListIterator&#60;String&#62; liter = theList.listIterator&#40;theList.size&#40;&#41;&#41;; 
while &#40;liter.hasPrevious&#40;&#41;&#41; &#123; 
  System.out.println&#40;liter.previous&#40;&#41;&#41;; 
&#125;

]]></description>
			<content:encoded><![CDATA[<p>Today, I had the problem to iterate backwards in a ArrayList. Didn’t know, there is a ListIterator:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> theList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
theList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
theList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
theList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
ListIterator<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> liter <span style="color: #339933;">=</span> theList.<span style="color: #006633;">listIterator</span><span style="color: #009900;">&#40;</span>theList.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>liter.<span style="color: #006633;">hasPrevious</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>liter.<span style="color: #006633;">previous</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/08/06/iterate-backwards-through-a-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Use of instanceof</title>
		<link>http://blog.stefanjaeger.ch/2008/06/27/dynamic-use-of-instanceof/</link>
		<comments>http://blog.stefanjaeger.ch/2008/06/27/dynamic-use-of-instanceof/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 20:01:26 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/06/27/dynamic-use-of-instanceof/</guid>
		<description><![CDATA[Generics are very useful. But sometimes, they don&#8217;t fullfil all required needs. Today, I had a small problem. Over the parameter of a method, a Class definition was passed. In the method, I had to cast an object of type Object into a concrete type (the concrete type was T, defined by Generics). The easiest [...]]]></description>
			<content:encoded><![CDATA[<p>Generics are very useful. But sometimes, they don&#8217;t fullfil all required needs. Today, I had a small problem. Over the parameter of a method, a Class definition was passed. In the method, I had to cast an object of type Object into a concrete type (the concrete type was T, defined by Generics). The easiest way is to put the cast between a try and catch block. This will work, no question. But in my piece of code, a try and catch block wasn&#8217;t very nice. For this reason, I tried to check, if the object o is of the type clazz. Unfortunately, instanceof doesn&#8217;t work with dynamic defined classes. But there is a simple solution: just use the method <strong>isAssignableFrom</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> test<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> clazz<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// the Object o is from somewhere...</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o <span style="color: #000000; font-weight: bold;">instanceof</span> clazz<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// does not working</span>
  <span style="color: #009900;">&#125;</span> 
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>o.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isAssignableFrom</span><span style="color: #009900;">&#40;</span>clazz<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// is working</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/06/27/dynamic-use-of-instanceof/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Collections.EMPTY_LIST with Generics</title>
		<link>http://blog.stefanjaeger.ch/2008/06/26/use-collectionsempty_list-with-generics/</link>
		<comments>http://blog.stefanjaeger.ch/2008/06/26/use-collectionsempty_list-with-generics/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 16:56:00 +0000</pubDate>
		<dc:creator>Steve J.</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/06/25/use-collectionsempty_list-with-generics/</guid>
		<description><![CDATA[Today I stumbled upon a nice solution, to use the Collections.EMPTY_LIST with Generics. Just use the method emptyList with Generics instead of the constant value.
For example:

Collections.&#60;String&#62; emtpyList&#40;&#41;;

]]></description>
			<content:encoded><![CDATA[<p>Today I stumbled upon a nice solution, to use the Collections.EMPTY_LIST with Generics. Just use the method emptyList with Generics instead of the constant value.</p>
<p>For example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Collections</span>.<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> emtpyList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.stefanjaeger.ch/2008/06/26/use-collectionsempty_list-with-generics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
