com.sptci.echo2
Class ModelGenerator

java.lang.Object
  extended by com.sptci.CodeGenerator
      extended by com.sptci.echo2.ModelGenerator
Direct Known Subclasses:
JDOModelGenerator

public class ModelGenerator
extends CodeGenerator

A JavaBean generator. Uses reflection to create a JavaBean that maps to the UI component fields in the specified class.

The following shows the invocation semantics for this class:

  java -classpath <path to classes>:sptecho.jar:<path to Echo2_App.jar> \
    com.sptci.echo2.ModelGenerator \
    <fully qualified name of UI class>
 

Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: ModelGenerator.java,v 1.3 2006/02/15 00:48:26 rakesh Exp $
Author:
Rakesh Vidyadharan 2006-02-07

Field Summary
protected  java.util.List<java.lang.String> imports
          A List of import statements for the generated class.
protected  java.lang.Class source
          The class for which the JavaBean is to be generated.
protected  java.util.Map<java.lang.String,java.lang.reflect.Field> uiFields
          A Map of fields in source.
 
Fields inherited from class com.sptci.CodeGenerator
fields, name, primitives
 
Constructor Summary
ModelGenerator(java.lang.String name)
          Instantiates a new instance of source from the specified name.
 
Method Summary
 void generate()
          Load the class specified, and generate a JavaBean representing its UI components.
protected  java.lang.String generateBeanMethods()
          Over-ridden to fire PropertyChangeEvents for mutator methods.
protected  java.lang.String generateConstructors()
          Generate the constructors for the JavaBean.
protected  java.lang.String generateDefaultConstructor()
          Generate the default constructor for the JavaBean
protected  java.lang.String generateDesignatedConstructor()
          Generate the designated constructor for the JavaBean
protected  java.lang.String generateFields()
          Generate the fields for the JavaBean.
protected  java.lang.String generateMethods()
          Generate the methods for the JavaBean.
protected  java.lang.String generatePropertyChangeFields()
          Generate the fields necessary to support PropertyChangeListener ability for the bean.
protected  java.lang.String generatePropertyChangeMethods()
          Generate the methods to support property change events.
protected  void generateSource()
          Generate the source code for the JavaBean.
static void main(java.lang.String[] args)
          Main method.
protected  void processComponent(java.lang.reflect.Field field)
          Generate a Field for the JavaBean class that will be generated from the specified Echo2 UI component
 
Methods inherited from class com.sptci.CodeGenerator
generateCloneMethod, generateCompareToMethod, generateEqualsMethod, generateHashCodeMethod, generateToStringMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected java.lang.Class source
The class for which the JavaBean is to be generated.


imports

protected java.util.List<java.lang.String> imports
A List of import statements for the generated class.


uiFields

protected java.util.Map<java.lang.String,java.lang.reflect.Field> uiFields
A Map of fields in source.

Constructor Detail

ModelGenerator

public ModelGenerator(java.lang.String name)
               throws java.lang.ClassNotFoundException
Instantiates a new instance of source from the specified name. Initialises code geneartor containers.

Parameters:
name - The fully qualified name of the class. Example: com.sptci.demo.InputForm.
Throws:
java.lang.ClassNotFoundException - If the class corresponding to the name cannot be found in the classpath.
Method Detail

generate

public void generate()
              throws java.lang.Exception
Load the class specified, and generate a JavaBean representing its UI components.

Specified by:
generate in class CodeGenerator
Throws:
java.lang.Exception - If errors are encountered while writing to the source file.
See Also:
processComponent(java.lang.reflect.Field), generateSource()

processComponent

protected void processComponent(java.lang.reflect.Field field)
Generate a Field for the JavaBean class that will be generated from the specified Echo2 UI component

Parameters:
field - The Field that represents the Echo2 component.

generateSource

protected void generateSource()
                       throws java.io.IOException
Generate the source code for the JavaBean.

Throws:
java.io.IOException - If errors are encountered while writing the generated source file.

generateFields

protected java.lang.String generateFields()
Generate the fields for the JavaBean. Over-ridden to add code specific to the JavaBean.

Overrides:
generateFields in class CodeGenerator
Returns:
String The field declarations for the JavaBean.
See Also:
generatePropertyChangeFields()

generatePropertyChangeFields

protected java.lang.String generatePropertyChangeFields()
Generate the fields necessary to support PropertyChangeListener ability for the bean.

Returns:
String The field declarations necessary for property change support

generateConstructors

protected java.lang.String generateConstructors()
Generate the constructors for the JavaBean.

See Also:
generateDefaultConstructor(), generateDesignatedConstructor()

generateDefaultConstructor

protected java.lang.String generateDefaultConstructor()
Generate the default constructor for the JavaBean


generateDesignatedConstructor

protected java.lang.String generateDesignatedConstructor()
Generate the designated constructor for the JavaBean


generateMethods

protected java.lang.String generateMethods()
Generate the methods for the JavaBean.

Returns:
String The source code for the methods to be included in the JavaBean.
See Also:
CodeGenerator.generateToStringMethod(), CodeGenerator.generateEqualsMethod(), CodeGenerator.generateHashCodeMethod(), CodeGenerator.generateCompareToMethod(), CodeGenerator.generateCloneMethod(), generatePropertyChangeMethods(), generateBeanMethods()

generatePropertyChangeMethods

protected java.lang.String generatePropertyChangeMethods()
Generate the methods to support property change events.

Returns:
String The source code for property change event handling.

generateBeanMethods

protected java.lang.String generateBeanMethods()
Over-ridden to fire PropertyChangeEvents for mutator methods.

Overrides:
generateBeanMethods in class CodeGenerator
Returns:
String The default accessor and mutator methods for the CodeGenerator.fields.

main

public static void main(java.lang.String[] args)
Main method.



Copyright © 2006 Sans Pareil Technologies, Inc. All Rights Reserved.