<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;DkUERXgyeSp7ImA9WhdTEEU.&quot;'><id>tag:blogger.com,1999:blog-7038817</id><updated>2011-07-08T00:16:44.691Z</updated><category term='jquery'/><category term='dependency transformation'/><category term='Mule'/><category term='portlets'/><category term='javascript'/><category term='java'/><category term='python'/><category term='web'/><category term='spring'/><category term='generics'/><category term='ESB'/><category term='html'/><category term='aop'/><category term='test driven development'/><category term='jadapter'/><category term='project management'/><category term='convention over configuration'/><category term='jython'/><category term='SOA'/><title>wtfhax</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://wtf.hax.is/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default?redirect=false&amp;v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry gd:etag='W/&quot;CEIMQHc8eyp7ImA9WxBWEUg.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-5725538996202557593</id><published>2008-12-17T18:26:00.048Z</published><updated>2010-02-02T23:16:21.973Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2010-02-02T23:16:21.973Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><category scheme='http://www.blogger.com/atom/ns#' term='html'/><title>Fancy form input hints with legal markup</title><content type='html'>&lt;div class="highlight"&gt;
&lt;h3&gt;Update&lt;/h3&gt;
&lt;p&gt;Jason has updated his excellent &lt;a href="http://github.com/jaz303/jquery-grab-bag/tree/master"&gt;hint script&lt;/a&gt;. I seriously recommended it. I modified the example to use his one.&lt;/p&gt;
&lt;/div&gt;

&lt;script type="text/javascript" src="http://github.com/pjesi/jquery/raw/master/plugins/jquery.hint.js"&gt;
&lt;/script&gt;

&lt;style type="text/css" media="screen"&gt;
#demo kbd, input.hint { font-style : italic; color:grey; }
&lt;/style&gt;

&lt;p&gt;
It is quite common these days to use JavaScript to enhance text input fields in HTML forms. One popular technique is to display a helpful text inside the input box before it gains focus and back on blur if nothing has been typed. Something like the &lt;q&gt;What are you doing at the moment?&lt;/q&gt; box on Facebook. As I was searching for examples on how this is commonly implemented, I was surprised to find only solutions that relied on illegal element attributes such as &lt;var&gt;hint&lt;/var&gt; or &lt;var&gt;placeholder&lt;/var&gt; to store the hint text.
&lt;/p&gt;

&lt;p&gt;Below is an example of invalid markup from a typical solution. Note that I am omitting the usual attributes such as &lt;var&gt;id&lt;/var&gt; and &lt;var&gt;name&lt;/var&gt; since they are not relevant here. Also note that there is no scripting applied to the example so there is no way to actually see the hint text (with the exception of using &lt;em&gt;view source&lt;/em&gt; or &lt;a href="http://getfirebug.com/"&gt;Firebug&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Source&lt;/h4&gt;
&lt;pre&gt;
&amp;lt;label&gt;Departure&amp;lt;/label&gt;
&amp;lt;input hint="dd.mm.yyyy" /&gt;
&lt;/pre&gt;

&lt;h4&gt;Output&lt;/h4&gt;

&lt;label&gt;Departure&lt;/label&gt;
&lt;input hint="dd.mm.yyyy" /&gt;

&lt;p&gt;
This certainly makes the field more accessible for those who have Javascript turned on. But it otherwise useless and I am not sure how a screen reader will interpreted this. But it is nothing new to display an example hint next to an input field to aid the user. Here is how I used to do this: 
&lt;/p&gt;

&lt;h4&gt;Source&lt;/h4&gt;

&lt;pre&gt;
&amp;lt;label&gt;Departure&amp;lt;/label&gt;
&amp;lt;input /&gt;
&amp;lt;em&gt;dd.mm.yyyy&amp;lt;/em&gt;
&lt;/pre&gt;

&lt;h4&gt;Output&lt;/h4&gt;

&lt;label&gt;Departure&lt;/label&gt;
&lt;input /&gt;
&lt;em&gt;dd.mm.yyyy&lt;/em&gt;


&lt;p&gt;
Actually there are more specific HTML elements for this purpose. I found the &lt;a href="http://www.w3.org/TR/xhtml2/mod-text.html#sec_9.6." title="The kbd element"&gt;&lt;code&gt;&amp;lt;kbd/&gt;&lt;/code&gt;&lt;/a&gt; element to be just what I needed:
&lt;/p&gt;


&lt;h4&gt;Source&lt;/h4&gt;

&lt;pre&gt;
&amp;lt;label&gt;Departure&amp;lt;/label&gt;
&amp;lt;input /&gt;
&amp;lt;kbd&gt;dd.mm.yyyy&amp;lt;/kbd&gt;
&lt;/pre&gt;

&lt;h4&gt;Output&lt;/h4&gt;


&lt;label&gt;Departure&lt;/label&gt;
&lt;input type="text" /&gt;
&lt;kbd&gt;dd.mm.yyyy&lt;/kbd&gt;

&lt;p&gt;
I admit that the default styling is not that pretty but that is easy enough to fix with little CSS. It is also nice to use a little lighter colour on the hint than the label/input text. I will leave that to the professionals.
&lt;/p&gt;

&lt;pre&gt;
kbd { font-style : italic; }
&lt;/pre&gt;

&lt;p&gt;
I am pretty found of this last example and it is easy to use the markup to implement the same popular focus/blur hint functionality. After finding a nice &lt;a href="http://jquery.com"&gt;jQuery&lt;/a&gt; &lt;a href="http://onehackoranother.com/projects/jquery/jquery-grab-bag/input-hint.html"&gt;input-hint plugin&lt;/a&gt; that works on the &lt;var&gt;hint&lt;/var&gt; attribute and modifying it a little, I came up with a simple solution that degrades nicely. The plugin accepts a selector to find the element that is to provide the hint text. In the case of using &lt;code&gt;kbd&lt;/code&gt; for the hint, the  selector would be &lt;code&gt;"+kbd"&lt;/code&gt;.
&lt;/p&gt;

&lt;h4&gt;Demo&lt;/h4&gt;
&lt;div id="demo"&gt;
&lt;label&gt;Departure&lt;/label&gt;
&lt;input type="text" /&gt;
&lt;kbd&gt;dd.mm.yyyy&lt;/kbd&gt;
&lt;/div&gt;
&lt;h4&gt;
Code
&lt;/h4&gt;

&lt;pre name="code" class="javascript:nogutter"&gt;
$(function(){
    $('#demo input').inputHint({using: '+ kbd'});
});
&lt;/pre&gt;

&lt;script type="text/javascript"&gt;
$(function(){
    $('#demo input').inputHint({using: '+ kbd'});
});
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-5725538996202557593?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/5725538996202557593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=5725538996202557593' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/5725538996202557593?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/5725538996202557593?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/12/fancy-form-input-hints-with-legal.html' title='Fancy form input hints with legal markup'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>5</thr:total></entry><entry gd:etag='W/&quot;AkUMSHk6eip7ImA9WxVUEU8.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-965179543096982252</id><published>2008-11-27T17:02:00.028Z</published><updated>2009-03-15T14:44:49.712Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-03-15T14:44:49.712Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='jython'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='portlets'/><title>Python on Portals - portlet.py</title><content type='html'>&lt;p&gt;
Now you can run Python on Java Portals with the help of &lt;a href="http://www.jython.org"&gt;Jython&lt;/a&gt; and a small project I have been working on: &lt;a href="http://code.google.com/p/portletpy/"&gt;portlet.py&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Jython is a Java implementation of python and allows you to run python code on the JVM. This is great on its own but I haven't been able to use it in my web development work. It does support servlets through the &lt;a href="http://www.jython.org/docs/api/org/python/util/PyServlet.html"&gt;PyServlet&lt;/a&gt; class. However, I prefer to use Spring controllers instead of boring vanilla servlets. 
&lt;/p&gt;

&lt;p&gt;
What I have been missing is to write portlets (JSR-168/268) in Python. This requires a similar dispatcher as &lt;code&gt;PyServlet&lt;/code&gt; is for servlets, but for portlets instead. So I gave Jython a change and &lt;code&gt;PyPortlet&lt;/code&gt; was born. Now I can enjoy the refreshing lack of Java for simple portlet development. Although I will still use the Spring Portlet MVC framework for larger projects.
&lt;/p&gt;

&lt;h3&gt;Usage&lt;/h3&gt;
&lt;p&gt;
Using &lt;code&gt;PyPortlet&lt;/code&gt; to dispatch portlet requests to you python portlet is pretty simple. Here is an example of the portlet definition in &lt;code&gt;portlet.xml&lt;/code&gt;, notice the init parameters:
&lt;/p&gt;

&lt;pre name="code" class="xml:nogutter"&gt;
    &amp;lt;portlet&gt;
        &amp;lt;portlet-name&gt;portletpy&amp;lt;/portlet-name&gt;
        &amp;lt;display-name&gt;Hello Jython Portlet&amp;lt;/display-name&gt;
        &amp;lt;portlet-class&gt;is.hax.portlet.PyPortlet&amp;lt;/portlet-class&gt;
        
        &amp;lt;init-param&gt;
               &amp;lt;name&gt;python.home&amp;lt;/name&gt;
               &amp;lt;value&gt;/usr/local/jython2.2.1&amp;lt;/value&gt;
        &amp;lt;/init-param&gt;        
        &amp;lt;init-param&gt;
         &amp;lt;name&gt;python.portlet&amp;lt;/name&gt;
         &amp;lt;value&gt;myportlet.HelloPortlet&amp;lt;/value&gt;
        &amp;lt;/init-param&gt;
        &amp;lt;!-- ... --&gt;
    &amp;lt;/portlet&gt;
&lt;/pre&gt;

&lt;p&gt;
What you have to do is to specify &lt;code&gt;PyPortlet&lt;/code&gt; as the &lt;code&gt;portlet-class&lt;/code&gt; and provide it with location of jython and the python portlet class. The you need jython.jar on your classpath. Here is a hello world portlet:
&lt;/p&gt;

&lt;pre name="code" class="python:nogutter"&gt;
from javax.portlet import GenericPortlet
 
class HelloPortlet(GenericPortlet):
    def render(self, request, response):
        res.writer.append('&amp;lt;p&gt;Hello World, how are we?&amp;lt;/p&gt;')
&lt;/pre&gt;

&lt;p&gt;
Simple eyhh? Now you have full access to the portlet API in python. And lets not forget no restarting between editing the python code!
&lt;/p&gt;
&lt;h3&gt;portlet.py&lt;/h3&gt;
&lt;p&gt;
After a while I realized that it is only so much fun to use python against a Java API. After all I still need to call all those long method names and there is little support for the gems of python you get when you override &lt;code&gt;__methods__&lt;/code&gt;. Fortunately it is simple to wrap the java APIs in a thin python layer that integrates the best of both worlds. So I added one module to the project, &lt;code&gt;portlet.py&lt;/code&gt;, which adds the needed sugar to the cake.
&lt;/p&gt;

&lt;p&gt;
Here is a very small dummy example of how it looks. More examples are on the &lt;a href="http://code.google.com/p/portletpy/w/list"&gt;Wiki&lt;/a&gt;:
&lt;/p&gt;

&lt;pre name="code" class="python:nogutter"&gt;
from portlet import Portlet

class ExampleUse(Portlet):
    def render(self, req, res):
        res &amp;lt;&amp;lt; '&amp;lt;p&gt;Hello World, how are we?&amp;lt;/p&gt;'
        counter = req.session['counter']
        url = res.action(name='python')      

    def action(self, req, res):
        name = req['name']
&lt;/pre&gt;


&lt;h3&gt;Next steps&lt;/h3&gt;
&lt;p&gt;
I am pretty happy with the result and I love to have a project with only one Java class (who said it couln't be done?). There are however a few things I want to add. First is a bundled portlet that allows you put the python portlet code in the portlet preferences instead of on the file system. What this means is that you could write a python portlet &amp;ndash; Through The Web  &amp;ndash; directly on a production/staging server with no deployment needed for simple use cases. Secondly, I want to support other python scripts than portlets, so the user can simply write a simple python script without conforming to the portlet API. Again, for even simpler cases.
&lt;/p&gt;

&lt;p&gt;
My initial reaction to jython has been very positive, and I am looking forward to trying out the upcoming 2.5 version. Hopefully this will run there too. There is a lot of effort in porting various popular python projects to jython but I find it at least as important to embrace existing java projects and make it easy to use them from jython. Hopefully this will be helpful to others in that direction. But there is a lot of ground to cover. My personal favorite would be python support in the &lt;a href="http://www.springframework.org"&gt;Spring framework&lt;/a&gt;.
&lt;/p&gt;

&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shCore.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushXml.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushPython.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-965179543096982252?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/965179543096982252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=965179543096982252' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/965179543096982252?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/965179543096982252?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/11/python-on-portals-portletpy.html' title='Python on Portals - portlet.py'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkUCRXk6eCp7ImA9WxVUEU8.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-3417301175853853112</id><published>2008-10-15T18:27:00.002Z</published><updated>2009-03-15T14:44:24.710Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-03-15T14:44:24.710Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='jadapter'/><category scheme='http://www.blogger.com/atom/ns#' term='dependency transformation'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='aop'/><title>JAdapter 0.2 is out</title><content type='html'>&lt;p&gt;
&lt;a href="http://jadapter.org"&gt;JAdapter&lt;/a&gt; 0.2 is now out and contains a few handy features. 
It is available for &lt;a title="JAdapter 0.2 download" href="http://jadapter.googlecode.com/files/jadapter-0.2.jar"&gt;download here&lt;/a&gt;. Like last time, I want to discuss the main features.
&lt;/p&gt;

&lt;h4&gt;
Less configuration
&lt;/h4&gt;
&lt;p&gt;
It is no longer needed to pass the transformer types to &lt;code&gt;JAdapter&lt;/code&gt;
if the adapter class follows a  
&lt;a title="JAdapter: Automatic Configuration"
href="http://code.google.com/p/jadapter/wiki/AutomaticConfiguration"&gt;conventional pattern&lt;/a&gt; and
I already &lt;a title="JAdapter: Convention over Configuration" 
href="http://wtf.hax.is/2008/09/jadapter-convention-over-configuration.html"&gt;blogged about this here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Optional Support for Spring Framework &lt;/h4&gt;
&lt;p&gt;
To make it easy to setup the adapters and the registry when using the Spring Framework, 
I added a new package &lt;code&gt;org.jadapter.spring&lt;/code&gt; that takes advantages of the
autowiring beans support. Documentation on this is already 
&lt;a title="JAdapter: Using with Spring Framework" href="http://code.google.com/p/jadapter/wiki/UsingWithSpring"&gt;on the wiki&lt;/a&gt; along with a 
&lt;a title="Spring cleaning my side project" href="http://wtf.hax.is/2008/10/spring-cleaning-my-side-project.html"&gt;recent post about the feature&lt;/a&gt;.
&lt;/p&gt;

&lt;h4&gt;AOP Support for Transparent Dependency Transformation&lt;/h4&gt;

&lt;p&gt;
The coolest feature in this release  (and perhaps the most useless :) is the possibility to &lt;em&gt;weave&lt;/em&gt; 
the transformer registry around objects. This is similar to the hack I described in 
&lt;a title="Java Syntax hacks using Generics and Proxies: Multiple Method Invocations" 
href="http://wtf.hax.is/2008/10/java-hacks-multiple-method-invocations.html"&gt;my last post and 
if anything is more brutal to the Java syntax&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;The main idea is that any object that is subject to transformation is weaved with the registry and the
result implements all interfaces that the object can be transformed to. Then it can be freely casted to any 
of those interfaces, although that cast would not be legal according  to the rules of inheritance.
&lt;/p&gt;

&lt;p&gt;
This makes most sense if you are using some kind of a factory to create your objects. Then it is simple
to pass them through a &lt;code&gt;Weaver&lt;/code&gt; to enable this feature. There are a few implementations of 
the weaver interface to allow fined grained control of which objects should be weaved.
I also added a Spring &lt;code&gt;BeanPostProcessor&lt;/code&gt; to automate this in a Spring app.
&lt;/p&gt;

&lt;p&gt;
This feature is probably best explained with an example:

&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;
// Create a registry with two adapters Foo -&gt; Bar and Bar -&gt; Csv
TransitiveAdapterRegistry registry = new TransitiveAdapterRegistry(
        new JAdapter(FooBar.class),
        new JAdapter(BarCsv.class));

// Create a AOP weaver with access to the initalised registry
Weaver weaver = new RegistryWeaver(registry);                 

// Create a new object and weave it
Foo foo = new FooBean(2);
foo = weaver.weave(foo);

assertEquals(2, foo.foo());

// Cast the object to a different type,
// the transformation to bar is done on demand
Bar bar = (Bar) foo;
assertEquals(3, bar.bar());

// Combined transitivity and weaving to transform Foo -&gt; Csv
Csv csv = (Csv)foo;
assertEquals("3", csv.csv());  
&lt;/pre&gt;

&lt;p&gt;
A side effect of using weaving instead of dependency injection to access a registry instance in application code
is that the client code will not depend on JAdapter on compile time. If you are using a framework to instantiate
your objects than it will be easy to plug this in.&lt;/p&gt; 

&lt;p&gt;I have received  blended feelings about abusing the language in 
this manner and am looking forward for more feedback on this. Personally I think it is neat and I like it. 
Besides, little hacks like this put all the fun into the project.
&lt;/p&gt;


&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shCore.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushJava.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-3417301175853853112?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/3417301175853853112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=3417301175853853112' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/3417301175853853112?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/3417301175853853112?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/10/jadapter-02-is-out.html' title='JAdapter 0.2 is out'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkUER3c-fip7ImA9WxVUEU8.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-32865596285267299</id><published>2008-10-08T22:34:00.003Z</published><updated>2009-03-15T14:43:26.956Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-03-15T14:43:26.956Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='generics'/><category scheme='http://www.blogger.com/atom/ns#' term='aop'/><title>Java Syntax hacks using Generics and Proxies: Multiple Method Invocations</title><content type='html'>&lt;p&gt;
When I first learned about &lt;a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming"&gt;
Aspect-oriented Programming (AOP)&lt;/a&gt;, I had a difficult time making up my mind if it was 
something that interested me or not. Then after working on two small projects using 
&lt;a href="http://eclipse.org/aspectj"&gt;AspectJ&lt;/a&gt; I was sure that there are great benefits in 
using AOP. But will AspectJ become mainstream enough that the average programmer will rely on it? 
&lt;/p&gt;

&lt;p&gt;
My prediction that I was not going to see much of AspectJ after joining the workforce proved partially correct.
Luckly I found out that people are using dynamic AOP without requiring more than the standard
JDK. 
&lt;/p&gt;

&lt;p&gt;
Java has this powerful thing called dynamic proxy classes and instances, which are used primeraly in
frameworks as far as I know. They can act as an replacement for more heavyweight AOP implementation
such as AspectJ.
I didn't know about their existence while hacking Java in College so it was a refreshing to learn
that I can enjoy the benefits of AOP without asking anyone for permission to introduce new tools 
to the development environment, which AspecJ inevitable does.
&lt;/p&gt;

&lt;p&gt;
Proxies are great for things such as transactional management, lazy loading, security, caching, and other common 
tasks that are preferred to be kept out of the application code. 
However there are other interesting thing to do with proxies. 
One such example are &lt;a href="http://code.google.com/p/open-traits/"&gt;traits&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
I have been playing with the JDK proxies in &lt;a href="http://jadapter.org"&gt;JAdapter&lt;/a&gt;
where I am pushing the Java syntax &amp;ndash; for the better or worse. The first example is just a simple hack
to invoke a method on multiple objects. The latter is a lot more useful as it introduces a way to 
use &lt;a href="wtf.hax.is/2008/09/introducing-jadapter-01.html"&gt;dependency transformation&lt;/a&gt;
transparently. I started writing this to introduce this but then decided to focus on the multiple method 
invocation trick. The plan is to expand this into a short series.  
I will go into details transparent dependency transformation when I release JAdapter 0.2
&lt;/p&gt;

&lt;h4&gt;Multiple Invocations of a Method Hack&lt;/h4&gt;
&lt;p&gt;
This is a very simple trick that really breaks the Java syntax. It uses generics and a proxy to
pack an iteration of objects and a method invocation on each object into a single statement.
This is probably easier to describe using an example. Lets say we have an implementation &lt;code&gt;Counter&lt;/code&gt; of a simple
interface &lt;code&gt;Incrementer&lt;/code&gt;, which is used to increment things.  

&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;
public interface Incrementer {
    public Incrementer inc();
}

public class Counter implements Incrementer {
    private int count = 0;
 
    public Counter inc() { 
        count++; 
        return this; 
    }
    public int count() { 
        return count; 
    }
}  
&lt;/pre&gt;

&lt;p&gt;
Now, if we have a collection of counters and want to increment them all at the same time, then we could 
do it using a loop and one statement:
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;
Incrementer[] counters = new Incrementer[]{c1, c2, c3};
for(Incrementer incrementer : counters) {
    incrementer.inc();    
}
&lt;/pre&gt;

&lt;p&gt;
I wrote a an &lt;code&gt;Iterable&lt;/code&gt; implementation for JAdapter, named &lt;code&gt;Query&lt;/code&gt; 
(suggestions for a better name are welcome!). While doing so, I hacked around with 
this idea and came up with the following alternative syntax:
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;
Query&amp;lt;Incrementer&gt; counters = Query.NEW(c1, c2, c3);
counters.each().inc();
&lt;/pre&gt;

&lt;p&gt;The resulting state of the counter objects will be the same in both examples.
The latter could of course also be written as a one-liner: &lt;code&gt;Query.NEW(c1, c2, c3).each().inc();&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
Lets have a better look at what the hell is going on here.
First, &lt;code&gt;NEW&lt;/code&gt; is a simple static factory that creates a new &lt;code&gt;Query&amp;lt;T&gt;&lt;/code&gt; instance where
&lt;code&gt;T&lt;/code&gt; is &lt;code&gt;Incrementer&lt;/code&gt; in this case. Yes I know that many would use another name
than &lt;code&gt;NEW&lt;/code&gt; for this. Perhaps &lt;code&gt;createInstance&lt;/code&gt;? Well, a programmer I greatly admire 
showed my this style and I really like it. But that is not important here.
The important part is the call to &lt;code&gt;each()&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Normally you would expect to see some kind of a function type passed to &lt;code&gt;each&lt;/code&gt; to simulate some sort of a 
functional style. However, if you simply want to call a method that is already defined in the type you 
are iterating, writing a anonymous class for that would be an overkill. Instead &lt;code&gt;each()&lt;/code&gt; 
returns a proxy of type &lt;code&gt;T&lt;/code&gt; that fakes the syntax. Now we can call the proxy like
we have a single instance of &lt;code&gt;Incrementer&lt;/code&gt;, and the proxy will do the dirty work of
iterating over each and perform the invocation.
&lt;/p&gt;

&lt;p&gt;
This is just a simple example of neat little hacks that are possible with proxy objects and generics.
It is up to you to judge if it pays off. Many will not like the syntax of the language being bent this much.
However, if you are like me then it is simply a refreshing change from the usual verbose syntax.
&lt;/p&gt;


&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shCore.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushJava.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-32865596285267299?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/32865596285267299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=32865596285267299' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/32865596285267299?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/32865596285267299?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/10/java-hacks-multiple-method-invocations.html' title='Java Syntax hacks using Generics and Proxies: Multiple Method Invocations'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkQGQns_eip7ImA9WxVUEU8.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-843802474053237332</id><published>2008-10-01T18:37:00.002Z</published><updated>2009-03-15T14:45:23.542Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-03-15T14:45:23.542Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='jadapter'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><title>Spring cleaning my side project</title><content type='html'>&lt;p&gt;It is still early fall over here but I am already doing spring cleaning. Well, actually I just wanted to write a little about the new support for Spring 2.5 configuration in JAdapter. &lt;/p&gt;

&lt;p&gt;
In my &lt;a href="http://wtf.hax.is/2008/09/introducing-jadapter-01.html" title="Introducing JAdapter 0.1"&gt;first post&lt;/a&gt; on &lt;a href="http://jadapter.org" title="JAdapter"&gt;JAdapter&lt;/a&gt; I mentioned how &lt;a href="http://wtf.hax.is/2008/09/jadapter-convention-over-configuration.html" title="JAdapter: Convention over configuration"&gt;hairy the configuration was&lt;/a&gt;. Now that I am a couple of weeks from releasing version 0.2, I wanted to give a quick update on how much cleaner things are becoming. 
&lt;/p&gt;

&lt;p&gt;
The following example demonstrates the same configuration from my previous post. There are a few things to note here. First, there is a new registry implementation undir the &lt;code&gt;org.jadapter.spring&lt;/code&gt; package. This implementation simply delegates to beans that are automatically injected using &lt;code&gt;@Autowired&lt;/code&gt;. Here, &lt;code&gt;CustomAdapter&lt;/code&gt; will be injected and made available as an adapter; the &lt;code&gt; TransitiveAdapterRegistry&lt;/code&gt; will be injected as the registry implementation. Another feature is that you can simply list all POJO classes that can act as adapters in the new bean. They are then automatically handled using reflection.
&lt;/p&gt;

&lt;pre name="code" class="xml:nogutter"&gt;
&amp;lt;context:annotation-config /&gt;

&amp;lt;bean class="com.example.CustomAdapter" /&gt;

&amp;lt;bean class="org.jadapter.registry.TransitiveAdapterRegistry" /&gt;
        
&amp;lt;bean name="adapters" class="org.jadapter.spring.SpringAdapterRegistry" &gt;
    &amp;lt;property name="adapterClasses"&gt;
        &amp;lt;list&gt;
            &amp;lt;value&gt;net.martinaspeli.blog.ReceiptPayment&amp;lt;/value&gt;
            &amp;lt;value&gt;net.martinaspeli.blog.RansomPayment&amp;lt;/value&gt;
        &amp;lt;/list&gt;
    &amp;lt;/property&gt;
&amp;lt;/bean&gt;
&lt;/pre&gt;

&lt;p&gt;
The reason for injecting an actual registry implementation into the Spring registry is both to support multiple registry implementations without bloating the Spring package. And to support another feature that I have not yet written about (but is already in trunk). More on that soon. You can read more about &lt;a href="http://code.google.com/p/jadapter/wiki/UsingWithSpring" title="Using JAdapter with Spring"&gt;Spring support on the wiki&lt;/a&gt;. I have also updated the &lt;a href="http://jadapter.googlecode.com/svn/trunk/docs/api/index.html" title="JAdapter JavaDoc API"&gt;JavaDoc&lt;/a&gt; for 0.2.
&lt;/p&gt;

&lt;p&gt;
After I release the final version of 0.2, which will be in two weeks, I plan to slow down the development and focus on example applications of the framework and start working on another side project that will be heavily based this work. The reason for that is that it will be a lot about object trees and performing stuff on those object using Java interfaces, which the the objects may or may not implement. 
&lt;/p&gt;

&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shCore.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushXml.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-843802474053237332?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/843802474053237332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=843802474053237332' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/843802474053237332?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/843802474053237332?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/10/spring-cleaning-my-side-project.html' title='Spring cleaning my side project'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkQBQHY6cCp7ImA9WxVUEU8.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-7001575631006272935</id><published>2008-09-26T18:10:00.005Z</published><updated>2009-03-15T14:45:51.818Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-03-15T14:45:51.818Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='jadapter'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='convention over configuration'/><title>JAdapter: Convention over Configuration</title><content type='html'>&lt;p&gt;
As consumers of various frameworks, most of us know how dreadful it can be to write boilerplate configuration.
This configuration can often be omitted when applying the princible of 
&lt;a href="http://en.wikipedia.org/wiki/Convention_over_Configuration"&gt;convention over configuration&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
When writing &lt;a href="http://jadapter.org"&gt;JAdapter&lt;/a&gt;, I was constantly comparing it to the 
&lt;a title="Zope Component Architecture" href="http://wiki.zope.org/zope3/ComponentArchitectureOverview"&gt;
Zope Component Architecture&lt;/a&gt; (ZCA). The result is that I
did not think much about explointing the fact that I was using static typing, while ZCA does not 
(Zope is a Python framework). 
&lt;/p&gt;

&lt;p&gt;
In Zope, you provide the type information in configuration. Given the following adapter (implementation omitted):

&lt;/p&gt;

&lt;pre name="code" class="python:nogutter"&gt;
&gt;&gt;&gt; class FooBar(object):
...     def __init__(self, foo):
...         self.foo = foo
&lt;/pre&gt;
&lt;p&gt;

This adapter could be configured in ZCML as follows to configure it to 
provide the Bar interface for anything that implements Foo:

&lt;/p&gt;
&lt;pre name="code" class="xml:nogutter"&gt;
&amp;lt;adapter
    factory="example.FooBar"
    provides="example.Bar"
    for="example.Foo"
    /&gt;
&lt;/pre&gt;

&lt;p&gt;

You could move the type properties to the adapter code, but you &lt;em&gt;need&lt;/em&gt; to 
provide the information in one way or another. Here is the Python code (implementation omitted):
&lt;/p&gt;

&lt;pre name="code" class="python:nogutter"&gt;
&gt;&gt;&gt; class FooBar(object):
...     implements(Bar)
...     adapts(Foo)
...
...     def __init__(self, foo):
...         self.foo = foo
&lt;/pre&gt;

&lt;p&gt;
Without line 2 and 3, the ZCA would not be able to use the adapter since Python is dynamically typed.
In JAdapter, I would write the same adapter in plain Java:
&lt;/p&gt;
&lt;pre name="code" class="java:nogutter"&gt;
public class FooBar implements Bar {
    
    private Foo foo;
    
    public FooBar(Foo foo) {
        this.foo = foo;
    }
&lt;/pre&gt;
&lt;p&gt;
So how much configuration is needed to tell the runtime that this is an adapter &lt;em&gt;Foo &amp;rarr; Bar&lt;/em&gt;?
The type of the interface in naturally given since the interface is part of the class declaration. 
The adaptee type is also available in the constructor argument. The only catch is that we follow this convention
when writing adapters. But the benefit of skipping verbose boilerplate configuration is definitely worth it.
&lt;/p&gt;

&lt;h3&gt;Automatic resolution of adapter types&lt;/h3&gt;
&lt;p&gt;
When writing introduction the the 0.1 release of JAdapter I told myself that the amount of configuration was
just too much. Especially using something as Spring to configure it (which is quite verbose). 
Version 0.2 will introduce an automatic resolution of the type parameters. 
In the current trunk, the following code will suffice to create a &lt;code&gt;FooBar&lt;/code&gt; transformer as &lt;em&gt;Foo &amp;rarr; Bar&lt;/em&gt;:
&lt;/p&gt;
&lt;pre name="code" class="java:nogutter"&gt;
 Transformer&amp;lt;Bar,Foo&gt; fooBar = new JAdapter&amp;lt;Bar,Foo&gt;(FooBar.class);
&lt;/pre&gt;

&lt;p&gt;
The transformer can now be used freely to get a &lt;code&gt;Bar&lt;/code&gt; instance:
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;
 Bar bar = fooBar.transform(someFooObject);
 
 // or using the registry
 registry.register(fooBar);
 bar = registry.transform(someFooObject, Bar.class);
&lt;/pre&gt;

&lt;p&gt;
As an example is Spring. This is a configuration for a single adapter in 0.1:
&lt;/p&gt;

&lt;pre name="code" class="xml:nogutter"&gt;
&amp;lt;bean class="org.jadapter.JAdapter"&gt;
 &amp;lt;property name="factory" value="net.martinaspeli.blog.ReceiptPayment" /&gt;
 &amp;lt;property name="to" value="net.martinaspeli.blog.Payment" /&gt;
 &amp;lt;property name="for" value="net.martinaspeli.blog.Receipt" /&gt;               
&amp;lt;/bean&gt;
&lt;/pre&gt;

&lt;p&gt;
Using the automatic configuration in version 0.2, the same adapter can be declared as follows:
&lt;/p&gt;

&lt;pre name="code" class="xml:nogutter"&gt;
&amp;lt;bean class="org.jadapter.JAdapter"&gt;
 &amp;lt;constructor-arg value="net.martinaspeli.blog.ReceiptPayment" /&gt;               
&amp;lt;/bean&gt;
&lt;/pre&gt;

&lt;p&gt;
This might not be much, but I am quite happy with it. It will help a lot when the number of adapters becomes significant.
&lt;/p&gt;


&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shCore.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushXml.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushPython.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushJava.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-7001575631006272935?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/7001575631006272935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=7001575631006272935' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/7001575631006272935?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/7001575631006272935?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/09/jadapter-convention-over-configuration.html' title='JAdapter: Convention over Configuration'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkQDRHc9fSp7ImA9WxVUEU8.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-5928217148077024622</id><published>2008-09-18T09:35:00.006Z</published><updated>2009-03-15T14:46:15.965Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-03-15T14:46:15.965Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='jadapter'/><category scheme='http://www.blogger.com/atom/ns#' term='dependency transformation'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><title>Introducing JAdapter 0.1</title><content type='html'>&lt;p&gt;
I have been working on and off for the last several months on a little project called &lt;a title="JAdapter" href="http://code.google.com/p/jadapter"&gt;JAdapter&lt;/a&gt; and version 0.1 is now available.

The aim of the project is to implement what I like to call a &lt;em&gt;Dependency Transformation&lt;/em&gt; framework, 
for &amp;ndash; you guessed it &amp;ndash; Java. 

It borrows a lot from the &lt;a title="Zope Component Architecture" href="http://wiki.zope.org/zope3/ComponentArchitectureOverview"&gt;
Zope Component Architecture&lt;/a&gt; and is similar to what 
&lt;a href="http://martinaspeli.net"&gt;Martin Aspeli&lt;/a&gt; 
describes as a &lt;a title="A Java Component Architecture" href="http://martinaspeli.net/articles/a-java-component-architecture"&gt;
Java Component Architecture&lt;/a&gt;. The code snippets below are adapted from his article.
&lt;/p&gt;

&lt;h4&gt;Dependency Transformation&lt;/h4&gt;
&lt;p&gt;
A dependency transformation is a technique based on the adapter pattern and is not invented here. You write adapters that by composition adapt 
one interface to another. Then in the client code, you declare the transformation you depend on. The framework then takes care of 
finding a suitable transformer (adapter) that meets the transformation dependency and keeps a registry of available transformers. 
It can be viewed as a graph between types, compared to traditional tree of object types. In the object tree, you can only transform 
(type cast) your objects up, while in the graph allows transformation between any types as long as there is a possible transformation
path available.
&lt;/p&gt;

&lt;p&gt;
Note that I both talk about &lt;em&gt;transformers&lt;/em&gt; and &lt;em&gt;adapters&lt;/em&gt;. When I refer to an adapter then I mean
a class that follows the adapter pattern, while a transformer is more generic and is simply a function that 
takes an input and transforms it to something different. Something you could pass to a &lt;em&gt;map&lt;/em&gt; function.
&lt;/p&gt;

&lt;h4&gt;An Example&lt;/h4&gt;

&lt;p&gt;Suppose we have two unrelated interfaces, &lt;code&gt;Receipt&lt;/code&gt; and &lt;code&gt;Payment&lt;/code&gt;. 
Your client code has access to an instance of Receipt but requires to work with Payment. 
Using the Adapter Pattern, one could write a simple adapter from Receipt to Payment:
&lt;/p&gt;


&lt;pre name="code" class="java:nogutter"&gt;
public class ReceiptPayment implements Payment {
    
    private Receipt receipt;
    
    public ReceiptPayment(Receipt receipt) {
        this.receipt = receipt;
    }
    
    public void pay() {
        int amountToPay = receipt.getAmount();
        ... // perform payment operation here
    }
}
&lt;/pre&gt;
&lt;p&gt;

The client code can then use this to explicitly transform an instance of Receipt to Payment:

&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;    
    public void makePayment(Receipt receipt) {
        Payment payment = new ReceiptPayment(receipt);
        payment.pay();
    }
&lt;/pre&gt;

&lt;p&gt;
A disadvantage of this approach is that you are tightening your client code with the implementation of &lt;code&gt;ReceiptPayment&lt;/code&gt;.
This can be solved by injecting a transformer that handles the dependency: 
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;    
    Transformer&amp;lt;Payment,Receipt&gt; receiptPayment; // inject this
 
    public void makePayment(Receipt receipt) {
        Payment payment = receiptPayment.transform(receipt);
        payment.pay();
    }
&lt;/pre&gt;

&lt;p&gt;
Now you only depend an a &lt;code&gt;Transformer&lt;/code&gt;, which can be configured at runtime.
This is quite important when you would have different adapters for different runtime environments, 
as an added value, you can now mock it too.
&lt;/p&gt;

&lt;p&gt;
If you need a lot of transformers, or that you don't know the type of the adaptee at compile time, 
then it might be better to inject a registry of transformers. This makes it easy resolve multiple dependencies
at runtime without explicitly mapping them.
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;    
    AdapterRegistry transformers; // inject this 

    public void makePayment(Receipt receipt) {
        Payment payment = transformers.transform(receipt);
        payment.pay();
    }    
&lt;/pre&gt;

&lt;p&gt;
A nice property of the the transformer graph is that it is transitive. This allows us to make syllogistic inferences to resolve 
transformation dependencies. Suppose we have a third interface, &lt;code&gt;Tax&lt;/code&gt;, 
that is unrelated to the previously defined interfaces, 
but you have written an adapter for &lt;em&gt;Payment &amp;rarr; Tax&lt;/em&gt;. Then the original client code might look something like:
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;    
    public void calculateTax(Receipt receipt) {
        Tax tax = new TaxPayment(new ReceiptPayment(receipt));
        tax.vat();
    }
&lt;/pre&gt;
&lt;p&gt;
Now you are both explicitly declaring two implementation dependencies, and the composition path. 
This could be replaced by the following code:
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;     
    public void calculateTax(Receipt receipt) {
        Tax tax = transformers.transform(receipt, Tax.class);
        tax.vat();
    }
&lt;/pre&gt;
&lt;p&gt;
I am not quite sure if this use case will ever arise though. But is an interesting case nonetheless. 
Without it you can reach the same state by calling transform twice, first to Payment, and then to Tax. 
Doing so requires you to know at compile time the composition path. 
&lt;/p&gt;

&lt;h4&gt;Benefits&lt;/h4&gt;

&lt;p&gt;
Besides the benefits of loose coupling mentioned above, and the added bonus of transitive composition. 
Martin Aspeli mentions 
&lt;a href="http://martinaspeli.net/articles/a-java-component-architecture"&gt;three key advantages of this technique&lt;/a&gt;.

&lt;blockquote&gt;
By factoring behaviour out into separate adapters, value objects 
(those that store persistent or transient state) are kept as simple as possible.
&lt;/blockquote&gt;


&lt;blockquote&gt;
Adding new behaviour simply means adding new adapters. General behaviour can be generalised into general adapters. 
This avoids the need to modify existing classes to add new types of behaviour. 
In the case of Java, this is doubly important, since Java does not support multiple inheritance. 
Thus, generalisable behaviour that needs to apply to multiple objects cannot be "mixed into" concrete classes by 
inheriting from multiple base classes 
(in any case, this type of design leads to very large class hierarchies and is probably best avoided).
&lt;/blockquote&gt;

Related to this. 
You can get rid of a lot of your &amp;ldquo;Managers&amp;rdquo; that you usually need to inject into your client code to access 
a particular functionality, 
which might or might not need to be configured at runtime.

I am not a big fan of multiple inheritance, but this touches the point of eliminating managers that are injected 
all over some codebases. 

&lt;blockquote&gt;
By using adapter lookups to generalise code, we gain a powerful method of re-use and customisation. 
Quite often, there will be one standard adapter that is registered for a very general object type. 
More specific adapters for more specific types (e.g. subclasses of the class that the general adapter 
was registered for) can be registered to provide specific behaviour, 
overriding the general implementation. The "client code" using the adapter is none the wiser.
&lt;/blockquote&gt;

This is very powerful when the client code is working on a tree of arbitrary types.
Consider for example writing code that outputs an HTML representation of any given object,
using special treatment to collections, maps, value objects, and such. Or if you need 
to retrieve an object from a repository as a specific interface.
The repository could be for example an object database or a Java Content Repository.
&lt;/p&gt;


&lt;h4&gt;Configuration&lt;/h4&gt;
&lt;p&gt;
As always, you will need to configure the components to use them. 
There is no specific configuration machinery in JAdapter, but you should be able to use your favorite DI framework.
If you are using Spring, then configuring an adapter registry is relatively simple, although verbose:
&lt;/p&gt;


&lt;pre name="code" class="xml:nogutter"&gt;
&amp;lt;bean id="transformers" class="org.jadapter.registry.TransitiveAdapterRegistry"&gt;
   &amp;lt;property name="adapters"&gt;
       &amp;lt;list&gt; &amp;lt;!-- declare your adapters here --&gt;
            &amp;lt;bean class="org.jadapter.JAdapter"&gt;
                &amp;lt;property name="factory" value="net.martinaspeli.blog.RansomPayment" /&gt;
                &amp;lt;property name="to" value="net.martinaspeli.blog.Payment" /&gt;
                &amp;lt;property name="for" value="net.martinaspeli.blog.Ransom" /&gt;                  
            &amp;lt;/bean&gt;
            &amp;lt;bean class="org.jadapter.JAdapter"&gt;
                &amp;lt;property name="factory" value="net.martinaspeli.blog.ReceiptPayment" /&gt;
                &amp;lt;property name="to" value="net.martinaspeli.blog.Payment" /&gt;
                &amp;lt;property name="for" value="net.martinaspeli.blog.Receipt" /&gt;               
            &amp;lt;/bean&gt;
            &amp;lt;bean class="com.example.CustomAdapter" /&gt;
       &amp;lt;/list&gt;
   &amp;lt;/property&gt;
&amp;lt;/bean&gt;
&lt;/pre&gt;

&lt;p&gt;
The example above is my current style of configuring adapters.
Note that the next version will not require nearly as much configuration. 
But as I stated in my last post,
&lt;a title="Throw away those features" href="wtf.hax.is/2008/09/throw-away-those-features.html"&gt;it is better to release it sooner with fewer features than not releasing it at all&lt;/a&gt;.
Version 0.2 will will simplify this a bit with automatic configuration of 
the &lt;code&gt;to&lt;/code&gt; and &lt;code&gt;from&lt;/code&gt; type information and possibly configuration using annotations. 
&lt;/p&gt;
&lt;p&gt;
Since I use Spring a lot, I am throwing in optional support for it. Such as auto-wiring, bean processors, and proxies.
Implementing a custom  
&lt;a href="http://static.springframework.org/spring/docs/2.0.x/reference/xsd-config.html"&gt;XML Schema-based configuration&lt;/a&gt;
is also interesting, but I will need to read up on that.
&lt;/p&gt;


&lt;p&gt;
Of course it is also possible to configure the registry directly in Java.
The bean definition above can be defined using the infamous &lt;code&gt;new&lt;/code&gt; 
operator in plain Java, for example:
&lt;/p&gt;

&lt;pre name="code" class="java:nogutter"&gt;
JAdapter ransomPaymentAdapter = 
    new JAdapter(RansomPayment.class)
        .to(Payment.class).from(Ransom.class);

JAdapter receiptPaymentAdapter = 
    new JAdapter(ReceiptPayment.class)
        .to(Payment.class).from(Receipt.class);

AdapterRegistry transformers = 
    new TransitiveAdapterRegistry(ransomPaymentAdapter, 
                                  receiptPaymentAdapter, 
                                  new CustomAdapter());
&lt;/pre&gt;



&lt;h4&gt;Try It&lt;/h4&gt;

&lt;p&gt;
Here, I mainly touched on two classes in JAdapter, 
namely &lt;code&gt;TransitiveAdapterRegistry&lt;/code&gt; 
and &lt;code&gt;JAdapter&lt;/code&gt;. These are currently the most important components of the framework
and are pretty much the only thing needed to get up and running with dependency 
transformation. The former provides the actually dependency lookup and composition of 
transformations. The latter is reflection based adapter. That is, it 
uses normal java classes that follow the adapter pattern 
to the &lt;code&gt;Adapter&lt;/code&gt; interface. This is the interface used internally by the 
adapter registry. 
&lt;/p&gt;

&lt;p&gt;
I will go in more detail into each component that makes up the framework in separate postings.
I hope others will find this useful. 
If you are interested then grab the 
&lt;a title="JAdapter 0.1" href="http://jadapter.googlecode.com/files/jadapter-0.1.jar"&gt;0.1 Version&lt;/a&gt;, 
and check the &lt;a title="JAdapter JavaDoc" href="http://jadapter.googlecode.com/svn/trunk/docs/api/index.html"&gt;JavaDoc&lt;/a&gt;. 
&lt;/p&gt;


&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shCore.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushJava.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushXml.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-5928217148077024622?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/5928217148077024622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=5928217148077024622' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/5928217148077024622?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/5928217148077024622?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/09/introducing-jadapter-01.html' title='Introducing JAdapter 0.1'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;C0cHRHg6fSp7ImA9WxRTF0Q.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-443987122865162219</id><published>2008-09-07T12:30:00.004Z</published><updated>2008-09-07T12:37:15.615Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2008-09-07T12:37:15.615Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='test driven development'/><category scheme='http://www.blogger.com/atom/ns#' term='project management'/><title>Throw Away those Features!</title><content type='html'>&lt;p&gt;
So you got excited about some programming idea and spent countless hours of your free time, 
coding it into reality.
Then you find yourself adding some code that you don't really need, at least not for the first
release. But it sure is more fun coding away than getting that initial release out of the door.
&lt;/p&gt;

&lt;p&gt;
Many advocates of Test Driven Development will tell you that they always write one test, 
then write the code that will make that test pass (along with the rest of the tests), and continue.
And by the way, throw in some refactoring while you are at it.
This approach may sound all good and valid, but it can just as easily go terribly wrong.
I am not talking about problems because it can be hard to write the test first, or any variant
of that argument. I am talking about when &lt;strong&gt;you don't know when to stop writing tests&lt;/strong&gt;
and get stuck in an infinite loop of writing and passing test after test. 
&lt;/p&gt;

&lt;p&gt;
This might not seem like a problem, especially in a corporate environment where you have 
a schedule to stick to, or in a larger community where there is a clear concensus of where
the project should be going. But in a solo project setting, where you are your own boss and
nobody tells you that they need you code yesterday! This is not always so simple.
&lt;/p&gt;

&lt;p&gt;If you find yourself adding a new test after test that each introduces a
new feature without making a release, then you are probably doing it wrong.
It might be time to stop for a moment and think, &lt;strong&gt;do I really need to add this code?&lt;/strong&gt; Or should I perhaps start working on &lt;strong&gt;getting what I already have out of the door?&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
The problem is that as features are added early on, getting to a release state 
becomes a lot harder. Not to mention the increased amount of documentation that has
to be written. You also have to worry about the level of maintenance your project will
require.
&lt;p&gt;

&lt;p&gt;
I have been trying to justify it to myself whether I should remove features that I have implemented
while working on a small solo project. It is also a question if it too late to shave off those extra 
features because someone might actually be using them already. From the top 
of my head, here are a few reasons I want to throw those features into the bin.
&lt;/p&gt;

&lt;h4&gt;Less to document&lt;/h4&gt;
&lt;p&gt;
This both applies to official documentation and other sources, such as blogs. 
If the project contains more than five important features in the first release, 
then you can't really write one post about the it. On the other hand if it only 
has 2-3 features, then it should fit nicely in a single post.
&lt;/p&gt;
&lt;h4&gt;Less to learn&lt;/h4&gt;
&lt;p&gt;Since there are fewer features, new users will have easier time getting to know your
project, which will probably attract more users who would be thrown off by a large 
stack of undocumented features. Developers might also get involved since entry barrier is still very low.&lt;/p&gt;


&lt;h4&gt;Less to maintain&lt;/h4&gt;
&lt;p&gt;
The last thing you probably want is to ship some premature features that add little 
value to &lt;em&gt;your&lt;/em&gt; project, but will require time for maintenance from &lt;em&gt;you&lt;/em&gt;, and add
unnecessary complexity to &lt;em&gt;your&lt;/em&gt; code base. As soon as a user discovers one of those
features and starts using it, you better be prepared to support it!
&lt;/p&gt;


&lt;blockquote&gt;
While it is difficult to create even a first implementation, 
it is even more difficult to maintain the level of commitment and arrive at a stable release. 
&amp;ndash; Kirill Grouchnikov
&lt;/blockquote&gt;

&lt;p&gt;
I encourage anyone who is working on a hobby project to read Grouchnikov's blog series on 
&lt;a href="http://www.pushing-pixels.org/?p=305" title="Party Of One: Surviving A Hobby Open-Source Project"&gt;Surviving A Hobby Open-Source Project&lt;/a&gt;. 
&lt;/p&gt;

&lt;h3&gt;Ship It&lt;/h3&gt;
&lt;p&gt;
Instead of writing one test at a time and at some arbitrary time decide that you have enough
features to ship. 
Try to write all the tests you think you need to ship that first release. 
See if you could describe them all in a single blog post. 
Writing that post before coding might actually not be a bad idea. Only then, start writing the code.
&lt;/p&gt;

&lt;p&gt;
I am not saying that you shouldn't add more test while working on that first release.
The only thing keep in mind is that those tests should never or rarely 
introduce new functionality  but instead increase test coverage.
&lt;/p&gt;

&lt;p&gt;
It is to be expected that you will get fresh ideas while working on the first set of features.
It might feel natural to drop whatever you are doing and implement this new cool idea.
It will only take five minutes right? Forget it. Just write the damn tests that capture the idea
and add it somewhere to your backlog so you can get back to it after shipping your original idea.
It was the idea that got you motivated to start the project in the first place. Right? 
Perhaps after the big &amp;ldquo;one point ooh&amp;rdquo; you will discover that this must have feature was 
actually a bad idea and you can simply throw it out of the backlog.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-443987122865162219?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/443987122865162219/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=443987122865162219' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/443987122865162219?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/443987122865162219?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/09/throw-away-those-features.html' title='Throw Away those Features!'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkMGR30-fip7ImA9WxVUEU8.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-4137092588420041286</id><published>2008-05-25T20:09:00.013Z</published><updated>2009-03-15T14:47:06.356Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2009-03-15T14:47:06.356Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><title>jQuery DatePicker and Selectbox</title><content type='html'>&lt;p&gt;
I have recently been drinking the &lt;a href="http://jquery.com"&gt;jQuery&lt;/a&gt; kool aid. One of my favorite plugins for it is the excellent &lt;a href="http://marcgrabanski.com/code/ui-datepicker/" title="UI/Datepicker"&gt;Datepicker plugin&lt;/a&gt;, which I am using whenever I want to display a nice calendar to users.&lt;/p&gt;

&lt;p&gt;Last week I needed it to work on a single selectbox that listed available dates but couldn't find any documentation for it. There are some examples of a datepicker for multiple selectboxes (day/month/year), but not when you only have a single one. So here is my attempt at it.
&lt;/p&gt;

&lt;p class="note"&gt;I am using the &lt;a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery.ui-1.5b4.zip" title="jQuery UI 1.5B4"&gt;jQuery UI 1.5 beta release&lt;/a&gt;, so your milage may vary since the API has changed quite a bit lately.&lt;/p&gt;

&lt;h4&gt;The Markup&lt;/h4&gt;
&lt;p&gt;The example I am working with has the following structure:&lt;/p&gt;

&lt;pre name="code" class="html:nogutter"&gt;
&amp;lt;select id="date"&gt;
   &amp;lt;option&gt;Select date&amp;lt;/option&gt;
   &amp;lt;option value="2008-05-01"&gt;May 1, 2008&amp;lt;/option&gt;
   &amp;lt;option value="2008-05-03"&gt;May 3, 2008&amp;lt;/option&gt;
   &amp;lt;option value="2008-05-05"&gt;May 5, 2008&amp;lt;/option&gt;
   &amp;lt;option value="2008-05-25"&gt;May 25, 2008&amp;lt;/option&gt;
&amp;lt;/select&gt;
&lt;/pre&gt;

&lt;p&gt;
Datepicker primarily works with &lt;code&gt;input&lt;/code&gt; elements so you will need to add a hidden element for it. This is kind of essential anyways if you want to have separated display format for the dates because datepicker supports only one format for each instance.
&lt;/p&gt;
&lt;p&gt;I prefer to have the value as an ISO date string and then use more user friendly format that is visible so I tend to do this anywhere the UI is important. The extra element is as simple as:&lt;/p&gt;
&lt;pre name="code" class="html:nogutter"&gt;
&amp;lt;input id="datepicker" type="hidden"/&gt;
&lt;/pre&gt;

&lt;h4&gt;DatePicker, Setting the Scene&lt;/h4&gt;
&lt;p&gt;
We need to tell the datepicker which dates are available from the selectbox. For performance reasons, I have created a map of available &lt;code&gt;dates&lt;/code&gt;, which the datepicker references to determine if a date is available or not.
&lt;/p&gt;

&lt;pre name="code" class="js:nogutter"&gt;
$(document).ready(function() {

  var dates = {};
  $('#date option').slice(1).each(function() {
      var date  = $(this).val();
      var year  = date.substring(0, 4);
      var month = date.substring(5, 7) - 1;
      var day   = date.substring(8, 10);
      dates[new Date(year, month, day)] = true;
  });
  // ...  
&lt;/pre&gt;

&lt;p&gt;
The datepicker can now be instantiated on the hidden element and made available through its button feature:
&lt;/p&gt;

&lt;pre name="code" class="js:nogutter"&gt;
  $('#datepicker').datepicker({
      dateFormat: 'yy-mm-dd',
      buttonImage: 'calendar.png',
      buttonImageOnly: true,
      showOn: 'button',
      // ...
&lt;/pre&gt;

&lt;h4&gt;Restricting DatePicker to dates in the datepicker&lt;/h4&gt;
&lt;p&gt;I already created a map of available dates, we now need to connect that data to the datepicker. This is trivial with the &lt;code&gt;beforeShowDay&lt;/code&gt; datepicker configuration option. We simply reference the &lt;code&gt;dates&lt;/code&gt; map to determine if the date should be allowed or not. 
&lt;/p&gt;

&lt;pre name="code" class="js:nogutter"&gt;
      beforeShowDay: function(date) {
          return [dates[date], ''];
      },
&lt;/pre&gt;


&lt;h4&gt;Synching the two Elements on a Change&lt;/h4&gt;
&lt;p&gt;The selectbox needs to be updated immediately when a date is selected using the datepicker. It is not as important to update the datepicker value as we are only using that for display. This means that we can get away with only updating it when we need to display it.&lt;/p&gt; 
&lt;p&gt;Both cases can be solved using options in the datepicker object, we update the selecbox with &lt;code&gt;onSelect&lt;/code&gt; and the datepicker with beforeShow. Since I am using the ISO format on both sides, it is simply a matter of synching the values. 
&lt;/p&gt;
&lt;pre name="code" class="js:nogutter"&gt;
      onSelect: function(date) {
          $('#date').val(date);
      },
      beforeShow: function() {
          $(this).val($('#date').val());
          return {};
      }
&lt;/pre&gt;


&lt;h4&gt;Demo&lt;/h4&gt;

&lt;select id="date"&gt;
    &lt;option&gt;Select date&lt;/option&gt;
    &lt;option value="2008-05-01"&gt;May 1, 2008&lt;/option&gt;
    &lt;option value="2008-05-03"&gt;May 3, 2008&lt;/option&gt;
    &lt;option value="2008-05-05"&gt;May 5, 2008&lt;/option&gt;
    &lt;option value="2008-05-25"&gt;May 25, 2008&lt;/option&gt;
&lt;/select&gt;

&lt;input id="datepicker" type="hidden"/&gt;



&lt;style type="text/css" media="screen"&gt;
@import url('http://static.hax.is/scripts/jquery.ui-1.5b4/themes/flora/flora.datepicker.css');
img.datepicker_trigger{ border:none; }
&lt;/style&gt;

    &lt;script type="text/javascript" src="http://static.hax.is/scripts/jquery.ui-1.5b4/ui.datepicker.js"&gt;&lt;/script&gt;

    &lt;script type="text/javascript"&gt;
        $(document).ready(function() {

            var dates = {};
            $('#date option').slice(1).each(function() {
                var date  = $(this).val();
                var year  = date.substring(0, 4);
                var month = date.substring(5, 7) - 1;
                var day   = date.substring(8, 10);
                dates[new Date(year, month, day)] = true;
            });

            $('#datepicker').datepicker({
                dateFormat: 'yy-mm-dd',
                buttonImage: 'http://cachefile.net/graphics/ui/famfamfam/silk/icons/calendar.png',
                buttonImageOnly: true,
                showOn: 'button',
                defaultDate: new Date(2008, 4, 1),
                onSelect: function(date) {
                    $('#date').val(date);
                },
                beforeShowDay: function(date) {
                    return [dates[date], ''];
                },
                beforeShow: function() {
                    $(this).val($('#date').val());
                    return {};
                }
            });
        });
    &lt;/script&gt;

&lt;h4&gt;The Complete Script&lt;/h4&gt;
&lt;pre name="code" class="js:nogutter"&gt;
$(document).ready(function() {

    var dates = {};
    $('#date option').slice(1).each(function() {
        var date  = $(this).val();
        var year  = date.substring(0, 4);
        var month = date.substring(5, 7) - 1;
        var day   = date.substring(8, 10);
        dates[new Date(year, month, day)] = true;
    });

    $('#datepicker').datepicker({
        dateFormat: 'yy-mm-dd',
        buttonImage: 'calendar.png',
        buttonImageOnly: true,
        showOn: 'button',
        onSelect: function(date) {
            $('#date').val(date);
        },
        beforeShowDay: function(date) {
            return [dates[date], ''];
        },
        beforeShow: function() {
            $(this).val($('#date').val());
            return {};
        }
    });
});
&lt;/pre&gt;



&lt;script src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shCore.js' type='text/javascript'&gt;&lt;/script&gt;
&lt;script src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushJScript.js' type='text/javascript'&gt;&lt;/script&gt;
&lt;script src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/shBrushXml.js' type='text/javascript'&gt;&lt;/script&gt;
&lt;script type='text/javascript'&gt;
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-4137092588420041286?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/4137092588420041286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=4137092588420041286' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/4137092588420041286?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/4137092588420041286?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/05/jquery-datepicker-and-selectbox.html' title='jQuery DatePicker and Selectbox'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>8</thr:total></entry><entry gd:etag='W/&quot;C0MDQXg4eCp7ImA9WxdRFEk.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-7213038320778041376</id><published>2008-05-10T10:13:00.002Z</published><updated>2008-06-02T21:17:50.630Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2008-06-02T21:17:50.630Z</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Mule'/><category scheme='http://www.blogger.com/atom/ns#' term='SOA'/><category scheme='http://www.blogger.com/atom/ns#' term='ESB'/><title>Use the Source, Mule!</title><content type='html'>&lt;p&gt;
I recently attended developers and architecture courses for &lt;a href="http://mulesource.org"&gt;Mule&lt;/a&gt;, the open source enterprise service bus (ESB). Compared to the competing proprietary solutions that I have used, Mule is a blessing. The number of transports that it supports is astounding and it is really easy to wire services. Almost too easy in fact.
&lt;/p&gt;
&lt;p&gt;
Here are a few examples of what I am looking forward to try out in Mule.
&lt;/p&gt;
&lt;h4&gt;
Embed Mule in existing applications
&lt;/h4&gt;
&lt;p&gt;
Mule is relatively lightweight and can either be run as a standalone instance, or embedded in other Java application. This means that you can include Mule in your webapp. The advantages of that are many. You can for example use it as the web service layer for all the components in the webapp, and expose the webapp’s API as a service without any code (generated or not).
&lt;/p&gt;
&lt;h4&gt;
Build new applications with Mule
&lt;/h4&gt;
&lt;p&gt;Since it is incredibly easy to connect bunch of services together, you can basically create new ones by wiring existing ones together using message flow logic in the Mule configuration. I am quite found of modeling programs as message flows and channels and Mule seems to fit the bill.
&lt;/p&gt;&lt;h4&gt;
Reuse all existing services and build new on top of them
&lt;/h4&gt;
&lt;p&gt;
Mule integrates well with Spring and you can reuse all your Spring beans as services in Mule. It also supports some other containers that I am not familiar with (it does not support Guice however).
&lt;/p&gt;
&lt;h4&gt;
Expose any data as services directly from the Mule configuration
&lt;/h4&gt;
&lt;p&gt;It is easy to connect any data you have into Mule. For example, you can expose SQL statements as services directly from the Mule configuration via JDBC. Either as an outbound endpoint using SELECT, or inbound with INSERT or UPDATE. I believe that other SQL statements or possible but I haven’t seen any examples of it. But I am definitely trying this one out.
&lt;/p&gt;&lt;p&gt;
Once the service has been configured in Mule, it is simply a matter of configuring an endpoint for it of your choice, such as SOAP, JMS, Atom, FTP, or whatever protocol you want. It is relatively easy to write a custom transport if the protocol is not supported (working on one myself in fact).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-7213038320778041376?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/7213038320778041376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=7213038320778041376' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/7213038320778041376?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/7213038320778041376?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/05/use-source-mule.html' title='Use the Source, Mule!'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>1</thr:total></entry><entry gd:etag='W/&quot;DEQASHoyfip7ImA9WxdSF0k.&quot;'><id>tag:blogger.com,1999:blog-7038817.post-7259765743189111619</id><published>2008-04-30T18:16:00.000Z</published><updated>2008-05-25T20:12:29.496Z</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2008-05-25T20:12:29.496Z</app:edited><title>My most anticipated GSOC 2008 projects</title><content type='html'>&lt;p&gt;These are my most anticipated projects of the summer 2008, in no particular order.&lt;/p&gt;

&lt;h4&gt;&lt;a href="http://code.google.com/soc/2008/psf/appinfo.html?csaid=ED7313929E2B9E39"&gt;The Jython compiler&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Python is the language I look most forward for using on the JVM. There are other cool languages such as Scala and Groovy, but there are simply too many Python applications I want to run on the JVM and all the fancy features of those languages can not compensate for them. &lt;/p&gt;
&lt;h4&gt;&lt;a href="http://code.google.com/soc/2008/psf/appinfo.html?csaid=DA6AC3DE94E157E"&gt;Django on Jython: Supporting Python Web App Frameworks on the JVM&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;There have been some efforts in making Django work on Jython already and this project seems to aim on a more than just Django, but Python webapps in general. &lt;/p&gt;
&lt;h4&gt;&lt;a href="http://code.google.com/soc/2008/psf/appinfo.html?csaid=59C7870763174C10"&gt;Improvement of Zope support on Jython&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Don&amp;#8217;t know what to say about this one, except that &lt;a href="http://zope.org"&gt;Zope&lt;/a&gt;  on the JVM sounds like a wet dream. And perhaps is too good to be true. But starting small and do it on package-by-package basis will go a long way.&lt;/p&gt;
&lt;p&gt;I don&amp;#8217;t expect to see the ZODB running on a JVM any time soon though. However, there are other solutions in the Java world that could potentially substitute it.&lt;/p&gt;
&lt;p&gt;These projects will hopefully make it easier to integrate Python in the enterprise, which will eventually make my job a lot more fun! Other than scripting, I am really excited about leveraging all the nice web frameworks that are written in Python (three of them are mentioned in this post). This is a blessing for me since I write &lt;em&gt;a lot&lt;/em&gt; of Java web applications.&lt;/p&gt;
&lt;h4&gt;&lt;a href="http://code.google.com/soc/2008/zope/appinfo.html?csaid=D03B177E4CFF8E51"&gt;OCQL a Query Language for ZODB&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;ZODB is a cool database that persists Python objects. It is the default storage backend Zope based applications, such as Plone. This project aims to add querying capabilities to it. This might be the perfect alternative to ORMs by simply getting rid of the RDBMS if it is not really needed. &lt;/p&gt;
&lt;p&gt;I have a couple of other object database systems that I am planning on evaluating for potential projects. Comparing ZODB to them will be interesting, but they seem to be more focused on querying while ZODB is more about navigation (traversing). Expect postings on my exploration into the object database world this summer.&lt;/p&gt;
&lt;h4&gt;&lt;a href="http://code.google.com/soc/2008/zope/appinfo.html?csaid=3B4AE1B198100838"&gt;Flint: a simple Grok-based CMS&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://grok.zope.org"&gt;Grok&lt;/a&gt; is a cool framework built on top of &lt;a href="http://en.wikipedia.org/wiki/Zope_3"&gt;Zope 3&lt;/a&gt;. An application like Flint could very well be what is needed to expose the power of the Zope Component Architecture to the rest of the Python community and beyond. It also has the potential to be a great starting point for a custom lightweight CMS project as an alternative to the more heavyweight but excellent &lt;a&gt;Plone CMS&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;If everything above falls into place, could we be running Flint on the JVM? Probably not, but if the projects above will be a success, then we are getting something truly special. &lt;/p&gt;
&lt;p&gt;We already have a WSGI support for Java, what we need is JDBC support for the Python ORM libraries and of course, more Jython compatible packages (whatever that means). Persisting objects from either Java or Python in the same object database sounds interesting as well.&lt;/p&gt;
&lt;h4&gt;WordPress Performance Projects [&lt;a href="http://code.google.com/soc/2008/wordpress/appinfo.html?csaid=E05064640152A20F"&gt;benchmarking&lt;/a&gt;, &lt;a href="http://code.google.com/soc/2008/wordpress/appinfo.html?csaid=7E1A38664ABC103C"&gt;caching&lt;/a&gt;]&lt;/h4&gt;
&lt;p&gt;I don&amp;#8217;t have much to say about this except that WordPress makes an awful lot of database queries to render a page and has no caching support built-in. Any improvements here are very much welcome.&lt;/p&gt;
&lt;h4&gt;&lt;a href="http://code.google.com/soc/2008/eclipse/appinfo.html?csaid=12D824BC5E0CB4A3"&gt;JavaScript debugger for IE&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;If there is one thing I hate doing, it must be debuging JavaScript code on Internet Explorer. Yes there are some debuggers available and no they are nothing compared to Firebug. I am not sure how this project will help me, but the title is just so appealing!&lt;/p&gt;
&lt;h4&gt;&lt;a href="http://code.google.com/soc/2008/plone/appinfo.html?csaid=69983137B55A28A5"&gt;Buildout Builder - An automated buildout configuration system.&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Buildout is great way to manage file artifacts in projects and offer a nice and intuitive way to manage all your Python package dependencies, especially compared to what we have in the non-Python world. This is extremely valuable for both deployment and development. Not to mention that will be based on Grok!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7038817-7259765743189111619?l=wtf.hax.is' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wtf.hax.is/feeds/7259765743189111619/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7038817&amp;postID=7259765743189111619' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/7259765743189111619?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7038817/posts/default/7259765743189111619?v=2'/><link rel='alternate' type='text/html' href='http://wtf.hax.is/2008/05/my-most-anticipated-gsoc-2008-projects.html' title='My most anticipated GSOC 2008 projects'/><author><name>pjesi</name><uri>http://www.blogger.com/profile/10468602721541388201</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry></feed>