David Palmer

consultant, technical architect.

XMPP/Jabber: blinder.dave@gmail.com

AIM: b1inder

Posts written by David Palmer

January 15

XStream, Aliases and Spring

At some point in a complicated development project there will come a time when you need to translate a java object (assuming of course that you are working in java) into XML or back. Sure, we’ve all gone through the pain of Castor and the performance hits you take associated with that, and there are other tools, but what is now considered (by many) to be the standard is XStream. I won’t go into too much detail as to why XStream is as great as it is (two words: pull parsing), but suffice it to say it is, great.

XStream uses an aliasing feature so that you can “pretty up” your XML (by default XStream will just use the fully qualified package name for XML node names) which can be weird.

To use the aliasing feature, in your code, you simply do something like:

xstream.alias("node-name",MyClass.class);

Well, that’s all cool and all, but its very hard-coded. Wouldn’t it be cool if you could just wire something like this together in Spring?

There is a way to do this, its quite simple in fact. It just requires you to make an interface that defines a single method, something like: String:getNodeName(). Each class that must be serialized would implement said interface. Now, you just do something like the following in your Spring XML (in this case I created a configuration bean that contains a list of my “models” that must be serialized):

<bean id="config" class="com.marley.tmac.tools.Configuration">
<property id="serializableClass">
<list>
<bean class="com.marley.tmac.models.User"/>
<bean class="com.marley.tmac.models.UserElement"/>
</list>
</property>
</bean>

Now, in the class that handles setting up XStream, you would simply have something like:

for (YourInterface model : listFromSpring) {
xstream.alias(model.getNodeName(), model.getClass());
}

November 26

Sensitive Properties Files Give You The Willies?

As a good follow-up to Don’s piece, comes a new (Java) library that can make many of your security nightmares go away (with respect to all of those wonderful JDBC properties files with usernames and passwords for production systems, just sitting there, out in the open, just waiting to be discovered).

Jasypt, a library that supports encrypting properties files for Spring, Hibernate (and any other properties files you want to protect) will keep curious eyes confused when all they see are RSA encoded strings for what represents actual configuration data.

November 12

Fedora Core 8: The Java Developer’s OS?

Red Hat’s non-profit arm, project Fedora just released Core 8, Fedora’s/Red Hat’s distribution of Linux. Fedora has long been a very developer-friendly operating system (unlike Ubuntu which lacks any developer tools out of the box) has taken further steps to embrace Java development.

Included with FC8 is OpenJDK and IcedTea, the open source version of the JDK /JVM and build tools. With Sun setting Java “free” OpenJDK and the IcedTea projects have become the de-facto open source Java environment.

Also included with FC8 is Eclipse, Maven, Ant, Tomcat5 (this should probably be 6) and Jetty. So we are talking major hardcore Java development right out of the box.

October 10

For Real Hot Deploy For Java

While Java 1.4 promised hot deploy, many implementations of application servers have fallen quite flat on their collective faces in delivering on this promise. Then along comes JavaRebel. A nice little library that actually makes this time consuming and frustrating problem a non-issue. Check out some of the features:

  • Changing, adding and removing class/interface methods
  • Changing, adding and removing class fields
  • Changing, adding and removing class constructors
  • Overriding existing methods
  • Creating new classes or renaming old ones (as long as some other class superclass doesn’t change)
  • Changing method parameter or return types or field type without changing its name
  • Changing, adding and removing class/interface constant fields is supported, but will not get reinitialized and thus is only useful for primitive types and Strings

(taken, liberally, from their page here)

Yes, there is a performance penalty with this, so DO NOT EVER use something like this is a production environment, but it can make your life as a java developer, especially in a local environment, a bit more productive and a lot less infuriating (but, er, we never get mad at Java, because Java is infallible!)

August 23

Making the Case: Alfresco

With the recent release of Alfresco 2.1, this relatively new entry to the “enterprise-class” open source content management system is beginning to show some very real signs of being a major go-to tool for organizations who need all of the enterprise features of your Documentums, or Teamsites or Vignettes, but being completely open source.

Alfresco’s features are impressive, fully customizable workflow, document management, user roles, remote publishing features, as well as easily integrating other applications to create mashups. Built on a JEE platform, and runs in JBoss, Tomcat, Geronimo, it has real promising of being a mainstay in an Java open source enterprise stack.

While OpenCMS is the old timer in the enterprise-class open source CMS, Alfresco is showing remarkable maturity, in particular to documentation (if you’ve worked with OpenCMS I’m sure you know about the weakness in the documentation) and its feature set. There is also a well established organization backing up Alfresco, providing professional services and support, as well “enterprise” versions of their product, while maintaining a “community” edition.

I’m currently giving it a spin, and am incorporating it into our “home intranet” to publish web content to our various project sites, so the back-end content management is completely decoupled from the front-end content delivery (web) tier. So far, it seems to be working like a champ.

Technorati Profile

Browse posts by month

Browse by author

We're always looking for rockstars

Come take a look at careers with Molecular