<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>JavaPorn - Pornographic Java</title>
    <link>http://javaporn.cestdelamerde.com/</link>
    <description></description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <pubDate>Thu, 12 Jun 2008 20:52:29 GMT</pubDate>

    <image>
        <url>http://javaporn.cestdelamerde.com/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: JavaPorn - Pornographic Java - </title>
        <link>http://javaporn.cestdelamerde.com/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Cute format on javaporn ?</title>
    <link>http://javaporn.cestdelamerde.com/archives/11-Cute-format-on-javaporn.html</link>
    
    <comments>http://javaporn.cestdelamerde.com/archives/11-Cute-format-on-javaporn.html#comments</comments>
    <wfw:comment>http://javaporn.cestdelamerde.com/wfwcomment.php?cid=11</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://javaporn.cestdelamerde.com/rss.php?version=2.0&amp;type=comments&amp;cid=11</wfw:commentRss>
    

    <author>nospam@example.com (François Guerry)</author>
    <content:encoded>
    I wrote only 2 posts on this wonderful blog, and I&#039;m already upset by the dumb formating options.&lt;br /&gt;
I thought : and if I was able to copy/paste the nice formatted code of an eclipse editor directly in the blog post, without having any edition to do about format itself... ?&lt;br /&gt;
&lt;br /&gt;
Yeah...&lt;br /&gt;
&lt;br /&gt;
Just made it &lt;img src=&quot;http://javaporn.cestdelamerde.com/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Look at my beautiful previous posts with gorgeous syntax highlight ! What a dream !! Rendered with my own tool !&lt;br /&gt;
You want to do it all the same ?&lt;br /&gt;
Come on, just check this code in, and with slight adaptations to match your blog engine it could work nice...&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://javaporn.cestdelamerde.com/uploads/Analysis.java&quot; title=&quot;Analysis.java&quot; target=&quot;_blank&quot;&gt;Analysis.java&lt;/a&gt; (ahh, of course the code itself is a perfect piece of crap)&lt;br /&gt;
&lt;br /&gt;
Small howto :&lt;br /&gt;
&lt;br /&gt;
* be sure to use Java 6 !!!&lt;br /&gt;
* download &amp;amp; compile the code&lt;br /&gt;
* run it as a main class &lt;br /&gt;
* copy some code from an arbitrary eclipse editor (java, xml, whatever...)&lt;br /&gt;
* paste it in the big window&lt;br /&gt;
* click the export button&lt;br /&gt;
* copy all the ugly code produced&lt;br /&gt;
* paste it to your naughty blog&lt;br /&gt;
&lt;br /&gt;
It takes in account bold, italic, and colors. So feel free to configure eclipse with funny styles to use it as well ! (I&#039;m pretty proud about my pink strings, in fact...)&lt;br /&gt;
&lt;br /&gt;
Enjoy &lt;img src=&quot;http://javaporn.cestdelamerde.com/templates/default/img/emoticons/wink.png&quot; alt=&quot;;-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt; 
    </content:encoded>

    <pubDate>Thu, 12 Jun 2008 14:44:27 +0200</pubDate>
    <guid isPermaLink="false">http://javaporn.cestdelamerde.com/archives/11-guid.html</guid>
    
</item>
<item>
    <title>Closeup on object encapsulation violation</title>
    <link>http://javaporn.cestdelamerde.com/archives/10-Closeup-on-object-encapsulation-violation.html</link>
    
    <comments>http://javaporn.cestdelamerde.com/archives/10-Closeup-on-object-encapsulation-violation.html#comments</comments>
    <wfw:comment>http://javaporn.cestdelamerde.com/wfwcomment.php?cid=10</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://javaporn.cestdelamerde.com/rss.php?version=2.0&amp;type=comments&amp;cid=10</wfw:commentRss>
    

    <author>nospam@example.com (François Guerry)</author>
    <content:encoded>
    Do you like Spring and Hibernate ? Personally, I do... but today I faced a strange issue... I tried to make the two incriminated guys auto generate a diff script for my DB schema...&lt;br /&gt;
&lt;br /&gt;
To make it short, I wrote this kind of code :&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&lt;pre&gt;        ApplicationContext context = &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; ClassPathXmlApplicationContext(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;conf/data-repository-conf.xml&quot;&lt;/FONT&gt;);&lt;BR /&gt;        LocalSessionFactoryBean lsfb = (LocalSessionFactoryBean) context.getBean(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;&amp;amp;mySessionFactory&quot;&lt;/FONT&gt;);&lt;BR /&gt;        SchemaUpdate update = &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; SchemaUpdate(lsfb.getConfiguration());&lt;BR /&gt;        update.execute(&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;true&lt;/B&gt;&lt;/FONT&gt;, &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;false&lt;/B&gt;&lt;/FONT&gt;);&lt;/pre&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
And the associated conf/data-repository-conf.xml :&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&lt;pre&gt;  &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;bean&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f007f&quot;&gt;id&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;myDataSource&quot;&lt;/I&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f007f&quot;&gt;class&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;org.apache.commons.dbcp.BasicDataSource&quot;&lt;/I&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f007f&quot;&gt;destroy-method&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;close&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;BR /&gt;  	&lt;FONT COLOR=&quot;#7f007f&quot;&gt;p:validationQuery&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;SELECT COUNT(*) FROM DUAL&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#7f007f&quot;&gt;p:driverClassName&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;com.mysql.jdbc.Driver&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#7f007f&quot;&gt;p:url&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;jdbc:mysql://host/schema&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#7f007f&quot;&gt;p:username&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;***&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#7f007f&quot;&gt;p:password&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;***&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;/&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;  &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;bean&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f007f&quot;&gt;id&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;mySessionFactory&quot;&lt;/I&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f007f&quot;&gt;class&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;org.springframework.orm.hibernate3.LocalSessionFactoryBean&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#7f007f&quot;&gt;p:dataSource-ref&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;myDataSource&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;property&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f007f&quot;&gt;name&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;mappingResources&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;      &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;list&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;        &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;value&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;mappings.hbm.xml&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;value&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;      &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;list&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;property&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;property&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f007f&quot;&gt;name&lt;/FONT&gt;=&lt;FONT COLOR=&quot;#2a00ff&quot;&gt;&lt;I&gt;&quot;hibernateProperties&quot;&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;      &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;value&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;        hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect&lt;BR /&gt;      &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;value&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;    &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;property&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;  &lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;lt;/&lt;/FONT&gt;&lt;FONT COLOR=&quot;#3f7f7f&quot;&gt;bean&lt;/FONT&gt;&lt;FONT COLOR=&quot;#008080&quot;&gt;&amp;gt;&lt;/FONT&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
Little explanation here : &lt;br /&gt;
* first it creates the AppContext&lt;br /&gt;
* then it lookup for the LocalSessionFactoryBean (not the resulting &lt;a href=&quot;http://www.hibernate.org/hib_docs/v3/api/org/hibernate/SessionFactory.html&quot;&gt;SessionFactory&lt;/a&gt;, but its creator, the original Spring &lt;a href=&quot;http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/FactoryBean.html&quot;&gt;FactoryBean&lt;/a&gt;) : for that I use the special char &quot;&amp;&quot; at the beginning of the bean&#039;s name &lt;br /&gt;
* the LocalSessionFactoryBean is needed to retrieve the underlying Configuration for Hibernate, and it creates with it a SchemaUpdate object&lt;br /&gt;
* finally, it runs the update stuff..&lt;br /&gt;
&lt;br /&gt;
This is yet at a nice level of pornography, because of course an equivalent of such a code could be integrated in the bean declaration.&lt;br /&gt;
But it doesn&#039;t deserve my purpose for some reason... whatever, let&#039;s go further !&lt;br /&gt;
Here is the result at runtime: &lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&lt;pre&gt;&lt;FONT COLOR=&quot;#000080&quot;&gt;org.hibernate.HibernateException&lt;/FONT&gt;: No local DataSource found for configuration - &#039;dataSource&#039; property must be set on LocalSessionFactoryBean&lt;BR /&gt;	at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.configure(&lt;FONT COLOR=&quot;#000080&quot;&gt;LocalDataSourceConnectionProvider.java:50&lt;/FONT&gt;)&lt;BR /&gt;	at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(&lt;FONT COLOR=&quot;#000080&quot;&gt;ConnectionProviderFactory.java:124&lt;/FONT&gt;)&lt;BR /&gt;	at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(&lt;FONT COLOR=&quot;#000080&quot;&gt;ConnectionProviderFactory.java:56&lt;/FONT&gt;)&lt;BR /&gt;	at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(&lt;FONT COLOR=&quot;#000080&quot;&gt;ManagedProviderConnectionHelper.java:27&lt;/FONT&gt;)&lt;BR /&gt;	at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(&lt;FONT COLOR=&quot;#000080&quot;&gt;SchemaUpdate.java:127&lt;/FONT&gt;)&lt;/pre&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
Hmmm... I googled this insane stack and found this is an old Spring issue :&lt;br /&gt;
&lt;a href=&quot;http://jira.springframework.org/browse/SPR-1547&quot; title=&quot;http://jira.springframework.org/browse/SPR-1547&quot;&gt;http://jira.springframework.org/browse/SPR-1547&lt;/a&gt;&lt;br /&gt;
I&#039;m using Spring 2.5.1 so I shouldn&#039;t have the problem... ?? The fact is : I have the problem...&lt;br /&gt;
&lt;br /&gt;
After a small investigation, I discovered that the datasource is passed to the Update stuff via a strange ThreadLocal trick, but this trick failed here for some unobvious reasons... To waste no time, and as long as this small program is a one-shot test stuff, I decided to solve the problem with the ugly code following.&lt;br /&gt;
First we have a look inside the &lt;a href=&quot;http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/LocalSessionFactoryBean.html&quot;&gt;problematic class&lt;/a&gt; code to see how to fix that :&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&lt;pre&gt;&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;public&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;class&lt;/B&gt;&lt;/FONT&gt; LocalSessionFactoryBean &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;extends&lt;/B&gt;&lt;/FONT&gt; AbstractSessionFactoryBean &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;implements&lt;/B&gt;&lt;/FONT&gt; BeanClassLoaderAware {&lt;BR /&gt;&lt;BR /&gt;	&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;private&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;static&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;final&lt;/B&gt;&lt;/FONT&gt; ThreadLocal &lt;FONT COLOR=&quot;#0000c0&quot;&gt;&lt;I&gt;configTimeDataSourceHolder&lt;/I&gt;&lt;/FONT&gt; = &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; ThreadLocal();&lt;/pre&gt;        &lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
And now the fixed code itself - enjoy it:&lt;br /&gt;
&lt;blockquote&gt;&lt;br /&gt;
&lt;pre&gt;        ApplicationContext context = &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; ClassPathXmlApplicationContext(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;conf/data-repository-conf.xml&quot;&lt;/FONT&gt;);&lt;BR /&gt;        LocalSessionFactoryBean lsfb = (LocalSessionFactoryBean) context.getBean(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;&amp;amp;mySessionFactory&quot;&lt;/FONT&gt;);&lt;BR /&gt;        SchemaUpdate update = &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; SchemaUpdate(lsfb.getConfiguration());&lt;BR /&gt;        &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;try&lt;/B&gt;&lt;/FONT&gt; {&lt;BR /&gt;            Field declaredField = LocalSessionFactoryBean.&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;class&lt;/B&gt;&lt;/FONT&gt;.getDeclaredField(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;configTimeDataSourceHolder&quot;&lt;/FONT&gt;);&lt;BR /&gt;            declaredField.setAccessible(&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;true&lt;/B&gt;&lt;/FONT&gt;);&lt;BR /&gt;            ThreadLocal&amp;lt;DataSource&amp;gt; tl = (ThreadLocal&amp;lt;DataSource&amp;gt;)(declaredField.get(&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;null&lt;/B&gt;&lt;/FONT&gt;));&lt;BR /&gt;            tl.set((DataSource)context.getBean(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;myDataSource&quot;&lt;/FONT&gt;));&lt;BR /&gt;        } &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;catch&lt;/B&gt;&lt;/FONT&gt; (Throwable e) {&lt;BR /&gt;            e.printStackTrace();&lt;BR /&gt;        }&lt;BR /&gt;        update.execute(&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;true&lt;/B&gt;&lt;/FONT&gt;, &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;false&lt;/B&gt;&lt;/FONT&gt;);&lt;/pre&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
Huh, believe me or not, it simply works now &lt;img src=&quot;http://javaporn.cestdelamerde.com/templates/default/img/emoticons/laugh.png&quot; alt=&quot;:-D&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Small explanation:&lt;br /&gt;
* get the declared (static) field of the ThreadLocal&lt;br /&gt;
* make it accessible&lt;br /&gt;
* get its content (null arg for static access)&lt;br /&gt;
* put the DataSource in it&lt;br /&gt;
* here we go !!! 
    </content:encoded>

    <pubDate>Wed, 11 Jun 2008 18:38:33 +0200</pubDate>
    <guid isPermaLink="false">http://javaporn.cestdelamerde.com/archives/10-guid.html</guid>
    
</item>
<item>
    <title>Gorgeous File Manipulation</title>
    <link>http://javaporn.cestdelamerde.com/archives/9-Gorgeous-File-Manipulation.html</link>
    
    <comments>http://javaporn.cestdelamerde.com/archives/9-Gorgeous-File-Manipulation.html#comments</comments>
    <wfw:comment>http://javaporn.cestdelamerde.com/wfwcomment.php?cid=9</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://javaporn.cestdelamerde.com/rss.php?version=2.0&amp;type=comments&amp;cid=9</wfw:commentRss>
    

    <author>nospam@example.com (philou)</author>
    <content:encoded>
    The main purpose of the following code is to grab the directory of the package of a classpath resource and use it to create a new file. It is used in our unit tests where we assume that classpath resources are in real directories. It&#039;s of course pornographic...&lt;br /&gt;
&lt;blockquote&gt;&lt;pre&gt;File file = new File(new File(getClass().getResource(&quot;noel.jpg&quot;).getPath()).getParentFile(), info.getFileName());&lt;br /&gt;
file.createNewFile();&lt;/pre&gt;&lt;/blockquote&gt; 
    </content:encoded>

    <pubDate>Thu, 29 May 2008 15:55:36 +0200</pubDate>
    <guid isPermaLink="false">http://javaporn.cestdelamerde.com/archives/9-guid.html</guid>
    
</item>
<item>
    <title>ClassLoader : brutal JAR insertion at runtime</title>
    <link>http://javaporn.cestdelamerde.com/archives/8-ClassLoader-brutal-JAR-insertion-at-runtime.html</link>
    
    <comments>http://javaporn.cestdelamerde.com/archives/8-ClassLoader-brutal-JAR-insertion-at-runtime.html#comments</comments>
    <wfw:comment>http://javaporn.cestdelamerde.com/wfwcomment.php?cid=8</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://javaporn.cestdelamerde.com/rss.php?version=2.0&amp;type=comments&amp;cid=8</wfw:commentRss>
    

    <author>nospam@example.com (François Guerry)</author>
    <content:encoded>
    I didn&#039;t remember where I found this, but I&#039;d like to thank a lot the person who had invented it...&lt;br /&gt;
I&#039;d never had figured such a thing by myself, or maybe after long and desperate nights of headache, as a last chance...&lt;br /&gt;
But the fact is : it works ! And it works fine !&lt;br /&gt;
&lt;br /&gt;
The idea is to insert new URLs in the system classloader, to allow some JARs to be part of it after startup... for me, it&#039;s was a manner to expose a kind of pluggable component feature : you just drop a JAR in a specific directory, and without modifying a single line of startup script or whatever, your jar comes to life automaticaly in the app.&lt;br /&gt;
&lt;br /&gt;
And now the beast, using a bit of reflective API, reaaaaally messy :&lt;br /&gt;
&lt;blockquote&gt;&lt;pre&gt;    &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;private&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;static&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;final&lt;/B&gt;&lt;/FONT&gt; Class[] &lt;FONT COLOR=&quot;#0000c0&quot;&gt;&lt;I&gt;parameters&lt;/I&gt;&lt;/FONT&gt; = &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; Class[]{URL.&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;class&lt;/B&gt;&lt;/FONT&gt;};&lt;BR /&gt;    &lt;BR /&gt;    &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;public&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;static&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; addURL(URL u) &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;throws&lt;/B&gt;&lt;/FONT&gt; IOException {&lt;BR /&gt;        URLClassLoader sysloader = (URLClassLoader)ClassLoader.&lt;I&gt;getSystemClassLoader&lt;/I&gt;();&lt;BR /&gt;        Class sysclass = URLClassLoader.&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;class&lt;/B&gt;&lt;/FONT&gt;;&lt;BR /&gt;     &lt;BR /&gt;        &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;try&lt;/B&gt;&lt;/FONT&gt; {&lt;BR /&gt;            Method method = sysclass.getDeclaredMethod(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;addURL&quot;&lt;/FONT&gt;,&lt;FONT COLOR=&quot;#0000c0&quot;&gt;&lt;I&gt;parameters&lt;/I&gt;&lt;/FONT&gt;);&lt;BR /&gt;            method.setAccessible(&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;true&lt;/B&gt;&lt;/FONT&gt;);&lt;BR /&gt;            method.invoke(sysloader,&lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; Object[]{ u });&lt;BR /&gt;        } &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;catch&lt;/B&gt;&lt;/FONT&gt; (Throwable t) {&lt;BR /&gt;            t.printStackTrace();&lt;BR /&gt;            &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;throw&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=&quot;#7f0055&quot;&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; IOException(&lt;FONT COLOR=&quot;#ff7b92&quot;&gt;&quot;Error, could not add URL to system classloader&quot;&lt;/FONT&gt;);&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;/pre&gt;&lt;/blockquote&gt; 
    </content:encoded>

    <pubDate>Mon, 26 May 2008 15:22:16 +0200</pubDate>
    <guid isPermaLink="false">http://javaporn.cestdelamerde.com/archives/8-guid.html</guid>
    
</item>
<item>
    <title>Welcome</title>
    <link>http://javaporn.cestdelamerde.com/archives/7-Welcome.html</link>
    
    <comments>http://javaporn.cestdelamerde.com/archives/7-Welcome.html#comments</comments>
    <wfw:comment>http://javaporn.cestdelamerde.com/wfwcomment.php?cid=7</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://javaporn.cestdelamerde.com/rss.php?version=2.0&amp;type=comments&amp;cid=7</wfw:commentRss>
    

    <author>nospam@example.com (philou)</author>
    <content:encoded>
    Welcome to JavaPorn, a blog dedicated to horrible java code &lt;img src=&quot;http://javaporn.cestdelamerde.com/templates/default/img/emoticons/tongue.png&quot; alt=&quot;:-P&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Here is the first piece of code ; it is used in a project to circumvent a parsing issue that throws OutOfMemoryError. Yes OutOfMemoryError !! (see &lt;a href=&quot;https://issues.apache.org/jira/browse/SANSELAN-3&quot;&gt;SANSELAN-3 on ASF Jira&lt;/a&gt;)&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;pre&gt;try {&lt;br /&gt;
    IImageMetadata metadata = Sanselan.getMetadata(new File(sourcePath));&lt;br /&gt;
    // process stuff here &lt;img src=&quot;http://javaporn.cestdelamerde.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
} catch (OutOfMemoryError oome) {&lt;br /&gt;
    // do nothing here. see https://issues.apache.org/jira/browse/SANSELAN-3 for an explanation&lt;br /&gt;
    log.warn(&quot;Please resolve cleanly ASF SANSELAN-3, catching an OOME is so crappy&quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;/blockquote&gt; 
    </content:encoded>

    <pubDate>Mon, 26 May 2008 15:10:45 +0200</pubDate>
    <guid isPermaLink="false">http://javaporn.cestdelamerde.com/archives/7-guid.html</guid>
    
</item>

</channel>
</rss>