JaxMe 2 JaxMe 2

the JaxMe 2 site
 
   

The JaxMe JavaSource framework

PDF
PDF

The JaxMe JavaSource framework

This is a framework for generating Java sources. It is based on an abstraction of the Java sources. For instance, there is an object called JavaSource. This object can have embedded instances of JavaMethod or JavaField, it can have inner classes, constructors, and so on. You get the idea. Compared to a basic approach of just using Writer.write(String), the framework has the obvious disadvantage of additional complexity and overhead. However, it also has some advantages:

  1. Your sources become more readable and simpler, for example by automatically importing external classes, if required.
  2. Postprocessing the generated sources is much easier. You get the chance to generate sources in multiple steps, or in a pipeline like this:
    Sourge generation pipeline
    If collection: Generate an iterator loop, otherwise: Skip ----> Handle the case of a single value
  3. Your generator is much more controlled by the compiler and suitable for refactoring. This is best illustrated by looking at the following example:
    		    JavaMethod jm;
    		    jm.addLine(MyClass.class, " myInstance = new ", MyClass.class, "();");
    		  
    This example assumes the existance of a class "MyClass". The compiler verifies the existance and a refactoring module might, for example, rename this class.
  4. It has a lot of nice shortcuts, for example:
          addTry();
          addLine("int i = Integer.parseInt(s);");
          addCatch(NumberFormatException.class);
          addThrowNew(IllegalArgumentException.class,
                      JavaSource.getQuoted("Invalid integer argument: "), " + s");
          addEndTry();
        

History

The framework was originally part of the JaxMe 1 generator, the predecessor of JaxMe 2. It got greatly improved as part on the work of JaxMe 2. Roughly in January 2003 it began to live a live of its own, because the framework was picked up for other projects. So it made sense to separate JaxMeJS in an own jar file and make JaxMe 2 based on it.

In a way, the JavaSource framework is still a part of JaxMe, because it lives under the same Apache hat. The sources are located in the same SVN server and the distribution comes from the same file server. The administrators and developers are typically the same. We'll see, what the future brings.

Valid HTML 4.01!Valid CSS!Built with Apache Forrest logo