org.enhydra.zeus.generator
Class SimpleGenerator

java.lang.Object
  |
  +--org.enhydra.zeus.generator.SimpleGenerator
All Implemented Interfaces:
Generator

public class SimpleGenerator
extends java.lang.Object
implements Generator

Generator is the portion of Zeus that will convert a set of constraints, visible through a Binding, and output them as generated Java classes (to a File [directory]).

SimpleGenerator is the simplest form of a Generator and takes in either a single Binding or a List of them, and directly generates Java classes.

Author:
Brett McLaughlin, Maciej Zawadzki, Sean Ogle

Field Summary
protected  java.util.List collapsedElements
          This instances's collapsed elements
protected  java.util.List globalImplementationImports
          A list of classes to import for all implementations
protected  java.util.List globalInterfaceImports
          A list of classes to import for all interfaces
protected  java.util.List globalUnmarshallerImports
          A list of classes to import for all unmarshallers
protected  java.util.List ignoredBindings
          A list of bindings to ignore
protected  boolean initialized
          Keeps track of whether the Generator needs to be reinitialized.
protected  java.io.File outputDir
          Base directory for generated files.
 
Constructor Summary
SimpleGenerator()
           This will construct a new instance of SimpleGenerator.
 
Method Summary
 void generate(Binding binding)
           This will convert from a set of constraints to Java classes.
protected  void generateImplementation(Container container)
           This will generate the implementation (or implemenations, through recursion) for the supplied Container.
protected  void generateInterface(Container container)
           This will generate the interface (or interfaces, through recursion) for the supplied Container.
protected  void generatePrimitiveAssignment(java.io.Writer writer, Property property, java.lang.String value)
           This method will write to the writer an expression that evaluates to the value of the string value, but as the type of the property.
protected  void generateUnmarshallableInterface(Container container)
           This will generate the Unmarshallable interface for use by generated classes in the unmarshalling process.
protected  void generateUnmarshaller(Container container)
           This will generate the Unmarshaller class for this container, which calls out to the implementation class for static unmarshalling from XML to Java.
protected  boolean isIgnoredBinding(java.lang.String xmlName, java.lang.String xmlNamespaceURI)
          This will determine if a particular binding should be ignored.
 void setIgnoreBinding(java.lang.String xmlName)
           This allows a binding to be ignored.
 void setIgnoreBinding(java.lang.String xmlName, java.lang.String xmlNamespaceURI)
           This allows a binding to be ignored.
 void setOutputDirectory(java.io.File outputDir)
           This sets the output directory to output generated classes to.
 void setOutputDirectory(java.lang.String outputDir)
           This sets the output directory to output generated classes to.
protected  void writeImplementationConstructor(java.io.Writer writer, java.lang.String className, java.util.List properties)
           This writes out the constructor for an implementation class
protected  void writeImplementationDeclaration(java.io.Writer writer, java.lang.String interfaceName)
           This writes out the implementation declaration (the class header).
protected  void writeImplementationImportStatements(java.io.Writer writer, java.util.List importClasses)
           This will take the supplied list of class names, and add import statements for each of the classes in the list.
protected  void writeImplementationMarshalMethods(java.io.Writer writer, Container container)
           This will write out the implementation of the various marshal.
protected  void writeImplementationMethods(java.io.Writer writer, Container container)
           This writes out the properties for an implementation as methods, including accessors, mutators, and collection-style methods if needed.
protected  void writeImplementationProperties(java.io.Writer writer, java.util.List properties)
           This writes out the properties for an implementation as variables.
protected  void writeImplementationSAXHandlerMethods(java.io.Writer writer, Container container)
           This will write out methods that implements various SAX handlers for use in unmarshalling.
protected  void writeImplementationUnmarshallerProperties(java.io.Writer writer, Container container)
           This will write out properties required for unmarshalling from XML into this Java class.
protected  void writeImplementationUnmarshalMethods(java.io.Writer writer, Container container)
           This will write out the implementation of the various unmarshal methods supported by generated classes.
protected  void writeInterfaceDeclaration(java.io.Writer writer, Container container)
           This writes out the interface declaration (the class header).
protected  void writeInterfaceImportStatements(java.io.Writer writer, java.util.List importClasses)
           This will take the supplied list of class names, and add import statements for each of the classes in the list.
protected  void writeInterfaceMarshalMethods(java.io.Writer writer)
           This will write out the declaration of the various marshal methods supported by generated classes.
protected  void writeInterfaceMethods(java.io.Writer writer, java.util.List properties)
           This writes out the various method declarations for an interface.
protected  void writePackageDeclaration(java.io.Writer writer, java.lang.String packageName)
           This writes out the package declaration for this class, if needed.
protected  void writeProperty(java.io.Writer writer, Property property)
           This will take a Property and generate the code for that property as a member variable.
protected  void writePropertyMethodDecl(java.io.Writer writer, Property property)
           This will take a Property and generate the code for that property as an accessor/mutator method (definition only).
protected  void writePropertyMethodImplementation(java.io.Writer writer, Property property)
           This will take a Property and generate the code for that property as an accessor/mutator method (with implementation).
protected  void writeUnmarshallerDeclaration(java.io.Writer writer, Container container)
           This writes out the unmarshaller declaration (the class header).
protected  void writeUnmarshallerImportStatements(java.io.Writer writer, java.util.List importClasses)
           This will take the supplied list of class names, and add import statements for each of the classes in the list.
protected  void writeUnmarshallerProperties(java.io.Writer writer, Container container)
           This will write out the unmarshaller properties.
protected  void writeUnmarshallerUnmarshalMethods(java.io.Writer writer, Container container)
           This will write out the unmarshaller version of the various unmarshal methods supported by generated classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ignoredBindings

protected java.util.List ignoredBindings
A list of bindings to ignore

globalUnmarshallerImports

protected java.util.List globalUnmarshallerImports
A list of classes to import for all unmarshallers

globalInterfaceImports

protected java.util.List globalInterfaceImports
A list of classes to import for all interfaces

globalImplementationImports

protected java.util.List globalImplementationImports
A list of classes to import for all implementations

collapsedElements

protected java.util.List collapsedElements
This instances's collapsed elements

outputDir

protected java.io.File outputDir
Base directory for generated files.

initialized

protected boolean initialized
Keeps track of whether the Generator needs to be reinitialized.
Constructor Detail

SimpleGenerator

public SimpleGenerator()

This will construct a new instance of SimpleGenerator.

Method Detail

setOutputDirectory

public void setOutputDirectory(java.lang.String outputDir)

This sets the output directory to output generated classes to.

Specified by:
setOutputDirectory in interface Generator
Parameters:
baseDir - the name of the base directory where all generated classes should be placed

setOutputDirectory

public void setOutputDirectory(java.io.File outputDir)

This sets the output directory to output generated classes to.

Specified by:
setOutputDirectory in interface Generator
Parameters:
outputDir - the File (directory) where all generated classes should be placed

setIgnoreBinding

public void setIgnoreBinding(java.lang.String xmlName,
                             java.lang.String xmlNamespaceURI)

This allows a binding to be ignored. This is an intermediary step towards allowing binding schemas. The name of the binding should be passed in here, and no property generation for it will occur.

Specified by:
setIgnoreBinding in interface Generator
Parameters:
xmlName - the XML local name of the binding to ignore.
xmlNamespaceURI - the XML namespace URI of the binding to ignore. The empty string indicates there is no namespace associated with the binding.

setIgnoreBinding

public void setIgnoreBinding(java.lang.String xmlName)

This allows a binding to be ignored. This is an intermediary step towards allowing binding schemas. The name of the binding should be passed in here, and no property generation for it will occur. This convenience version supplies an empty string for the namespace URI.

Specified by:
setIgnoreBinding in interface Generator
Parameters:
xmlName - the XML local name of the binding to ignore.

isIgnoredBinding

protected boolean isIgnoredBinding(java.lang.String xmlName,
                                   java.lang.String xmlNamespaceURI)
This will determine if a particular binding should be ignored. The binding is identified by its XML local name and its XML namespace URI.
Parameters:
xmlName - the XML local name of the binding.
xmlNamespaceURI - the XML namespace URI associated with the binding. An empty string indicates that there is no namespace associated with the binding.
Returns:
true if and only if the binding should be ignored

generate

public void generate(Binding binding)
              throws java.io.IOException,
                     ZeusException

This will convert from a set of constraints to Java classes. It accesses those constraints through the Binding interface, which provides them in a representation-independent format, and then converts them into Java code.

Specified by:
generate in interface Generator
Parameters:
binder - Binder with ability to convert from constraints to Zeus Bindings.
root - whether this is the root element
Throws:
IOException - - when errors in writing to the supplied Result occur.
ZeusException - - when errors in class generation occur.

generateUnmarshaller

protected void generateUnmarshaller(Container container)
                             throws java.io.IOException

This will generate the Unmarshaller class for this container, which calls out to the implementation class for static unmarshalling from XML to Java.

Parameters:
container - Container to generate classes from.
Throws:
IOException - - when generation errors occur.

generateUnmarshallableInterface

protected void generateUnmarshallableInterface(Container container)
                                        throws java.io.IOException

This will generate the Unmarshallable interface for use by generated classes in the unmarshalling process.

Parameters:
container - Container to generate classes from.
Throws:
IOException - - when generation errors occur.

generateInterface

protected void generateInterface(Container container)
                          throws java.io.IOException

This will generate the interface (or interfaces, through recursion) for the supplied Container.

Parameters:
container - Container to generate classes from.
Throws:
IOException - - when generation errors occur.

generateImplementation

protected void generateImplementation(Container container)
                               throws java.io.IOException

This will generate the implementation (or implemenations, through recursion) for the supplied Container.

Parameters:
container - Container to generate classes from.
Throws:
IOException - - when generation errors occur.

writePackageDeclaration

protected void writePackageDeclaration(java.io.Writer writer,
                                       java.lang.String packageName)
                                throws java.io.IOException

This writes out the package declaration for this class, if needed.

Parameters:
writer - Writer to perform output to
packageName - the package of this class
Throws:
IOException - - when errors in output occur.

writeUnmarshallerImportStatements

protected void writeUnmarshallerImportStatements(java.io.Writer writer,
                                                 java.util.List importClasses)
                                          throws java.io.IOException

This will take the supplied list of class names, and add import statements for each of the classes in the list. It will also write out all global import statements for unmarshaller classes.

Parameters:
writer - Writer to output to
importClasses - List of classes to add imports for
Throws:
IOException - - when errors in output occur.

writeUnmarshallerDeclaration

protected void writeUnmarshallerDeclaration(java.io.Writer writer,
                                            Container container)
                                     throws java.io.IOException

This writes out the unmarshaller declaration (the class header).

Parameters:
writer - Writer to output to
container - the container for the class
Throws:
IOException - - when errors in output occur.

writeUnmarshallerProperties

protected void writeUnmarshallerProperties(java.io.Writer writer,
                                           Container container)
                                    throws java.io.IOException

This will write out the unmarshaller properties.

Parameters:
writer - Writer to output to
container - the container to write the unmarshalling for.
Throws:
IOException - - when errors in output occur.

writeUnmarshallerUnmarshalMethods

protected void writeUnmarshallerUnmarshalMethods(java.io.Writer writer,
                                                 Container container)
                                          throws java.io.IOException

This will write out the unmarshaller version of the various unmarshal methods supported by generated classes.

Parameters:
writer - Writer to output to
container - the container to write the unmarshalling for.
Throws:
IOException - - when errors in output occur.

writeInterfaceImportStatements

protected void writeInterfaceImportStatements(java.io.Writer writer,
                                              java.util.List importClasses)
                                       throws java.io.IOException

This will take the supplied list of class names, and add import statements for each of the classes in the list. It will also write out all global import statements for interface classes.

Parameters:
writer - Writer to output to
importClasses - List of classes to add imports for
Throws:
IOException - - when errors in output occur.

writeInterfaceDeclaration

protected void writeInterfaceDeclaration(java.io.Writer writer,
                                         Container container)
                                  throws java.io.IOException

This writes out the interface declaration (the class header).

Parameters:
writer - Writer to output to
container - the container to write the interface for.
Throws:
IOException - - when errors in output occur.

writeInterfaceMethods

protected void writeInterfaceMethods(java.io.Writer writer,
                                     java.util.List properties)
                              throws java.io.IOException

This writes out the various method declarations for an interface.

Parameters:
writer - Writer to output to
properties - List of properties to write out method declarations for
Throws:
IOException - - when errors in output occur.

writePropertyMethodDecl

protected void writePropertyMethodDecl(java.io.Writer writer,
                                       Property property)
                                throws java.io.IOException

This will take a Property and generate the code for that property as an accessor/mutator method (definition only).

Parameters:
writer - Writer to write method declarations to.
property - Property to generate methods for.
Throws:
IOException - - when errors in writing to the supplied Result occur.

writeInterfaceMarshalMethods

protected void writeInterfaceMarshalMethods(java.io.Writer writer)
                                     throws java.io.IOException

This will write out the declaration of the various marshal methods supported by generated classes.

Parameters:
writer - Writer to output to
Throws:
IOException - - when errors in output occur.

writeImplementationImportStatements

protected void writeImplementationImportStatements(java.io.Writer writer,
                                                   java.util.List importClasses)
                                            throws java.io.IOException

This will take the supplied list of class names, and add import statements for each of the classes in the list. It will also write out all global import statements for implementation classes.

Parameters:
writer - Writer to output to
importClasses - List of classes to add imports for
Throws:
IOException - - when errors in output occur.

writeImplementationDeclaration

protected void writeImplementationDeclaration(java.io.Writer writer,
                                              java.lang.String interfaceName)
                                       throws java.io.IOException

This writes out the implementation declaration (the class header).

Parameters:
writer - Writer to output to
interfaceName - the name of the interface class being implemented
Throws:
IOException - - when errors in output occur.

writeImplementationProperties

protected void writeImplementationProperties(java.io.Writer writer,
                                             java.util.List properties)
                                      throws java.io.IOException

This writes out the properties for an implementation as variables.

Parameters:
writer - Writer to output to
properties - List of properties to write out as member variables
Throws:
IOException - - when errors in output occur.

writeProperty

protected void writeProperty(java.io.Writer writer,
                             Property property)
                      throws java.io.IOException

This will take a Property and generate the code for that property as a member variable.

Parameters:
writer - Writer to write variable declaration to.
property - Property to generate code for.
Throws:
IOException - - when errors in writing to the supplied Result occur.

writeImplementationUnmarshallerProperties

protected void writeImplementationUnmarshallerProperties(java.io.Writer writer,
                                                         Container container)
                                                  throws java.io.IOException

This will write out properties required for unmarshalling from XML into this Java class.

Parameters:
writer - Writer to output to
container - the container writing out for
Throws:
IOException - - when errors in output occur.

writeImplementationConstructor

protected void writeImplementationConstructor(java.io.Writer writer,
                                              java.lang.String className,
                                              java.util.List properties)
                                       throws java.io.IOException

This writes out the constructor for an implementation class

Parameters:
writer - Writer to output to
className - the name of the implementation class
properties - List of properties to write out as member variables
Throws:
IOException - - when errors in output occur.

writeImplementationMethods

protected void writeImplementationMethods(java.io.Writer writer,
                                          Container container)
                                   throws java.io.IOException

This writes out the properties for an implementation as methods, including accessors, mutators, and collection-style methods if needed.

Parameters:
writer - Writer to output to
container - Container with properties to generate methods for
Throws:
IOException - - when errors in output occur.

writePropertyMethodImplementation

protected void writePropertyMethodImplementation(java.io.Writer writer,
                                                 Property property)
                                          throws java.io.IOException

This will take a Property and generate the code for that property as an accessor/mutator method (with implementation).

Parameters:
writer - Writer to write method implementations to.
property - Property to generate code for.
Throws:
IOException - - when errors in writing to the supplied Result occur.

writeImplementationMarshalMethods

protected void writeImplementationMarshalMethods(java.io.Writer writer,
                                                 Container container)
                                          throws java.io.IOException

This will write out the implementation of the various marshal. methods supported by generated classes.

Parameters:
writer - Writer to output to
Throws:
IOException - - when errors in output occur.

writeImplementationUnmarshalMethods

protected void writeImplementationUnmarshalMethods(java.io.Writer writer,
                                                   Container container)
                                            throws java.io.IOException

This will write out the implementation of the various unmarshal methods supported by generated classes.

Parameters:
writer - Writer to output to
container - the container to write methods for.
Throws:
IOException - - when errors in output occur.

writeImplementationSAXHandlerMethods

protected void writeImplementationSAXHandlerMethods(java.io.Writer writer,
                                                    Container container)
                                             throws java.io.IOException

This will write out methods that implements various SAX handlers for use in unmarshalling.

Parameters:
writer - Writer to output to
container - the container to write class for.
Throws:
IOException - - when errors in output occur.

generatePrimitiveAssignment

protected void generatePrimitiveAssignment(java.io.Writer writer,
                                           Property property,
                                           java.lang.String value)
                                    throws java.io.IOException

This method will write to the writer an expression that evaluates to the value of the string value, but as the type of the property. Only use this if the property has a primitive Java type.

Parameters:
writer - the output writer
property - the property that defines the primitive type
value - the string value for the primitive (i.e. "true" for boolean or "1.8" for float)


Copyright © 2001 Enhydra. All Rights Reserved.