August 23, 2009

Generating Java Code on the fly!

Filed under: Java,JEE — khangharoth @ 3:31 pm

Currently I am working on a Grid based Cache (Coherence) in my regular job.

The concept is that differenct System can just use the Cache and do the stuff and its very easy and fast to share information.No XMl’s being excahnged and no bickering on XSD’s etc.

The thing  is in this process we were end up writing so much similar code for Serialisation purpose (PofSerialisers) and thought the this code can be auto generated.

And with this thought in mind when we looked at the problem that our Cluster needs to support various version of our core Domain model ,let me explain this problem better :

Let’s assume we have a class with 2 attribute and we call this versionV1 so we have T-V1.Now some new attributes are added and we have T-V2 and henceforth.But its very likely that some clients of this Cluster would not like to upgrade and would still be using T-V1 .


To code and maintain multiple versions of Data model is big task and so we decided to go ahead with concept of auto-generating the java code giving a schema file.

This is the first time i am doing something like this.Its ok to generate Stubs/Skeletons which we use in Web-Services to get auto generated but to use auto generated domain objects and this is used everywhere in project is something first time for me.

So initally our project just have Classes having business logic and these are not compilable becuase all domain classes which they use are just not their ! and when we invoke compile goal of Maven pom file ,these domain classes get generated with their Serialsers and now we have fully fuctional code 🙂 which can be deployed.


Create a free website or blog at