org.umber.ballast.schema
Class SchemaJavaGenerator

java.lang.Object
  extended byorg.umber.ballast.schema.BaseSchemaGenerator
      extended byorg.umber.ballast.schema.SchemaJavaGenerator
All Implemented Interfaces:
IGenerator

public class SchemaJavaGenerator
extends BaseSchemaGenerator

Generator to convert a BellowsSchema into JavaBeans, one Java source file per schema element node. Each generator creates code for a single schema, as passed into its constructor. One or more Velocity template can be passed into the generate() method; each input template will result in a different output JavaBean object model.

The template names in the BallastInput should be the package name for the object model. The BallastOutput will contain one output object for each JavaBean class generated; the output key will be the fully qualified Java class name.

Thus, given the DDL schema below:

 <!ELEMENT root (child1, child2)>
 <!ELEMENT child1 EMPTY>
 <!ELEMENT child2 EMPTY>
 
The output will contain three contents per input template. For example, using the DTD above, this code produces six outputs.
 BellowsSchema schema = BellowsSchemaLoader.getDtdLoader ().buildSchema (dtd);
 
 BallastInput in = new BallastInput (new Template[] {
   new Template ("org.myproj.model1", velocityTmpl1),
   new Template ("org.myproj.model2", velocityTmpl2) });
 
 IGenerator generator = new SchemaJavaGenerator (schema);
 BallastOutput out = generator.generate (in);
 
The first three outputs would be for the model1 and the other three for model2:
  1. org.myproj.model1.Root
  2. org.myproj.model1.Child1
  3. org.myproj.model1.Child2
  4. org.myproj.model2.Root
  5. org.myproj.model2.Child1
  6. org.myproj.model2.Child2

Author:
jsheets

Nested Class Summary
static class SchemaJavaGenerator.WrappedAttribute
          Emulates an ISchemaAttribute object, with all String parameters modified to return a PropertyName, for friendlier use in Velocity.
 
Constructor Summary
SchemaJavaGenerator(BellowsSchema schema)
           
 
Method Summary
protected  java.util.Map createNodeProps(ISchemaNode node, java.util.Map baseProps, BallastInput.Template template)
           
static java.lang.String packageToFile(java.lang.String packageName)
           
protected  java.lang.String parseClassName(java.lang.String content, java.util.Map nodeProps)
           
protected  void processVelocityTemplate(VelocityRunner velocity, BallastInput.Template template, BallastOutput out)
           
 
Methods inherited from class org.umber.ballast.schema.BaseSchemaGenerator
generate, getVelocityProps
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchemaJavaGenerator

public SchemaJavaGenerator(BellowsSchema schema)
                    throws BallastGeneratorException
Method Detail

packageToFile

public static java.lang.String packageToFile(java.lang.String packageName)

processVelocityTemplate

protected final void processVelocityTemplate(VelocityRunner velocity,
                                             BallastInput.Template template,
                                             BallastOutput out)
                                      throws UmberException
Specified by:
processVelocityTemplate in class BaseSchemaGenerator
Throws:
UmberException

createNodeProps

protected java.util.Map createNodeProps(ISchemaNode node,
                                        java.util.Map baseProps,
                                        BallastInput.Template template)

parseClassName

protected java.lang.String parseClassName(java.lang.String content,
                                          java.util.Map nodeProps)