Author Archive for Philipp Meier

Where is inversion of control in JSR 296 (Swing Application Framework)?

JSR-296 will provide us with nice ressource management. You can get property settings like label texts, colors and other properties from ressource files easily:

ApplicationContext ctxt = ApplicationContext.getInstance();
ResourceManager mgr = ctxt.getResourceManager();
resource = mgr.getResourceMap(HelloWorld.class);
String helloText = (String) resource.getObject("helloLabel", String.class);

But… what is this ApplicationContext.getInstance() static method call? Where is dependency injection? Look into the API documentation of ApplicationContext: it’s a global service locator. That means it provides a fixed bunch of services which are accessible by a singleton instance. You can of course use aggregation, sub-classing and delegation to extend it’s abilities but dependency injection is the train everyone jumps onto, ain’t it?

There is another issue that puzzles me: where are the interfaces? A framework whithout any interface? It’s even worse, ApplicationContext returns instances of concrete classes, not even abstract classes. So you’ll always get an instance of class RessourceManager. I you like to provide your own, you can only sub-class it, at least, RessourceManager is not final.

Can I have some dependeny injection, please? Picocontainer, Guice or Spring, perhaps? Yes, I can but it would be more nice, if RessourceManager, ActionManager and all other services provided by the framework would be interfaces and I could use any implemention I wish.

By the way, there is some dependency injection in the framework: you can inject property values into any awt component with RessourceManager.injectComponent. I hope the method name is not final yet, because I expected an component to be injected into some other instance, not something to be injected into a component.

Generate application.xml from ivy.xml for packaging an ear

After a lot of trouble with maven 2 I tried ant with ivy as a build and dependency resolving system. For multi-project builds with ivy you’ll have to dig into the documentation and ivy samples a little deeper but finaly I must say I like it. One show stopper for me was that maven 2 generated an application.xml from the pom. I use now a xslt stylesheet to make an application.xml from an ivy resolution report:

<target name="appxml" depends="resolve">
<property name="meta.dir" value="${basedir}/src/main/resources/META-INF/"/>
<property name="appxml.filename" value="application.xml"/>
<property name="appxml.file" value="${build.dir}/${appxml.filename}"/>
<ivy:report todir="${build.dir}"
outputpattern="ivy.xml"
xml="true"/>
<xslt in="${build.dir}/ivy.xml" style="ivy2appxml.xslt" out="${appxml.file}"/>
</target>

The stylsheet I use currently is simple but does it job. No support for web archvies and connectors yet, or any configuration but it’s doing it’s job:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/javaee/application_5.xsd">
<xsl:template match="ivy-report">
<application>
<display-name>
<xsl:value-of select="info/module"/>
</display-name>
<xsl:apply-templates/>
</application>
</xsl:template>
<xsl:template match="dependencies">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="artifact[@type='jar']">
<module>
<java>
<xsl:value-of select="concat(@name, ‘.’, @ext)"/>
</java>
</module>
</xsl:template>
<xsl:template match="artifact[@type='ejb']">
<module>
<ejb>
<xsl:value-of select="concat(@name, ‘.’, @ext)"/>
</ejb>
</module>
</xsl:template>
<xsl:template match="artifact[@type='sar']">
<module>
<java>
<xsl:value-of select="concat(@name, ‘.’, @ext)"/>
</java>
</module>
</xsl:template>
</xsl:stylesheet>

EJB 3.0 Annotations Cheat Sheet - Reference 1.2.2

The sheet got it’s own url here.

Minor update: added @AssociationOverride from Java EE 5 API documentation. Thanks to Jonathan O’Connor for catching this one.

Just download it from here as pdf or OpenOffice Document.

EJB 3.0 Annotations Cheat Sheet - Reference 1.2.1

The sheet got it’s own url here.

Updates to the EJB 3.0 Annotations Cheat Sheet.

Changes

  • Title changed to EJB 2.1 and Ealier Client View
  • Update @RemoteHome and @LocalHome according to the latest spec.
  • Fixed spelling and typos (NamesQueries / SINGLE_TABLE)

Thanks to Jonathan O’Connor for pointing out this errors.

Just download it from here as pdf or OpenOffice Document.

Preview of (old) cheat sheet.

Interruptible RMI - Working with JBoss?

Neil O’Toole has a RMI Socket- and ThreadFactory which enables a RMI client to interrupt a RMI invokation. This seems like a nice addition to a fat swing client which accesses a JBoss server. What I wonder is if the library will be compatible with JBoss and EJB 3. Have to try out. More information available at Neil’s blog entry.