The JaxMe JavaSource framework
Note:
As of Oct 2003, JaxMeJS is discontinued as a standalone project. The
further development is happening as a part of the Apache Incubator
project. See
http://ws.apache.org/jaxme/js/
for details. |
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:
- Your sources become more readable and simpler, for example by
automatically importing external classes, if required.
- Postprocessing the generated sources is much easier. You get
the chance to generate sources in multiple steps, or in a pipeline
like this:
Handle the case of a single element
|
|
----> |
Handle the case of a Collection
|
|
- Your generator is much more controlled by the compiler and
well suited 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.
- 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();
Table of Contents
Links
|