SPT Core API

com.sptci.echo.binding
Class JDOModelGenerator

java.lang.Object
  extended by com.sptci.CodeGenerator
      extended by com.sptci.echo.binding.ModelGenerator
          extended by com.sptci.echo.binding.JDOModelGenerator

public class JDOModelGenerator
extends ModelGenerator

A JDO JavaBean generator. In addition to generating the source file as implemented in ModelGenerator, generates an additional Factory class to implement interactions with the JDO datastore, and a default JDO metadata file.

The following shows the invocation semantics for this class:

  java -classpath <path to classes>:sptecho.jar:<path to Echo2_App.jar>:<path to jdom>:<path to jaxen> \
    com.sptci.echo.JDOModelGenerator \
    <fully qualified name of UI class>
 

Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: JDOModelGenerator.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2006-02-08
See Also:
JDOMetaDataGenerator

Field Summary
 
Fields inherited from class com.sptci.echo.binding.ModelGenerator
imports, source, uiFields
 
Fields inherited from class com.sptci.CodeGenerator
fields, name, primitives
 
Constructor Summary
JDOModelGenerator(String name)
          Delegates to the super-class constructor.
 
Method Summary
protected  StringBuilder changeDefinition(StringBuilder builder)
          Replace the class definition with a new definition as a sub-class of JDOObject.
 void generate()
          Over-ridden to generate the factory class source and metadata file in addition to the JavaBean source.
protected  String generateCloneMethod()
          Over-ridden to return an empty string.
protected  String generateCompareToMethod()
          Over-ridden to return an empty string.
protected  String generateCreateXStreamMethod()
          Return the custom implementation of the createXStream method.
protected  String generateDeleteMethod()
          Generate the delete method that will be used to delete a JDO JavaBean to the JDO data store.
protected  void generateFactory()
          Generate a Factory class that handles interactions between the JDO JavaBean objects and the JDO datastore.
protected  String generateFactoryInitialisers()
          Generate the initialiser methods for the factory class.
protected  String generateFactoryMethods()
          Generate additional factory methods for fetching the JDO JavaBean instances from the JDO data store.
protected  void generateMetaData()
          Generate the JDO meta-data file for the JDO JavaBean.
protected  String generateMethods()
          Generate the methods for the JavaBean.
protected  String generatePropertyChangeFields()
          Over-ridden to return an empty string.
protected  String generatePropertyChangeMethods()
          Over-ridden to return an empty string.
protected  String generateSaveMethod()
          Generate the save method that will be used to save a JDO JavaBean to the JDO data store.
protected  String generateToStringMethod()
          Over-ridden to return the createXStream method.
static void main(String[] args)
          Main method.
protected  StringBuilder removeHash(StringBuilder builder)
          Remove the fields for the hash code.
protected  StringBuilder removeObsoleteCode(StringBuilder builder)
          Remove code that is implemented in the parent JDOObject class.
protected  StringBuilder removeOldValue(StringBuilder builder)
          Remove assignment of old value to a temporary value used to fire property change events from mutator methods.
protected  StringBuilder removePropertyChange(StringBuilder builder)
          Remove the firePropertyChange method invocation in the mutator methods.
 
Methods inherited from class com.sptci.echo.binding.ModelGenerator
generateBeanMethods, generateConstructors, generateDefaultConstructor, generateDesignatedConstructor, generateFields, generateSource, processComponent
 
Methods inherited from class com.sptci.CodeGenerator
generateEqualsMethod, generateHashCodeMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDOModelGenerator

public JDOModelGenerator(String name)
                  throws ClassNotFoundException
Delegates to the super-class constructor.

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

generate

public void generate()
              throws Exception
Over-ridden to generate the factory class source and metadata file in addition to the JavaBean source.

Overrides:
generate in class ModelGenerator
Throws:
Exception - If errors are encountered while generating the source file.
See Also:
generateFactory(), generateMetaData()

generatePropertyChangeFields

protected String generatePropertyChangeFields()
Over-ridden to return an empty string. Property change support is not needed for JDO objects.

Overrides:
generatePropertyChangeFields in class ModelGenerator
Returns:
String The field declarations necessary for property change support

generatePropertyChangeMethods

protected String generatePropertyChangeMethods()
Over-ridden to return an empty string. Property change support is not needed for JDO objects.

Overrides:
generatePropertyChangeMethods in class ModelGenerator
Returns:
String The source code for property change event handling.

generateToStringMethod

protected String generateToStringMethod()
Over-ridden to return the createXStream method. The base JDOObject contains a default implementation of the toString method which is the same as the toXML method.

Overrides:
generateToStringMethod in class CodeGenerator
Returns:
String The source code for createXStream method.
See Also:
generateCreateXStreamMethod()

generateCreateXStreamMethod

protected String generateCreateXStreamMethod()
Return the custom implementation of the createXStream method.

Returns:
String The source code for the createXStream method.

generateCompareToMethod

protected String generateCompareToMethod()
Over-ridden to return an empty string. compareTo is implemented in the base JDOObject class.

Overrides:
generateCompareToMethod in class CodeGenerator
Returns:
String The field declarations necessary for property change support

generateCloneMethod

protected String generateCloneMethod()
Over-ridden to return an empty string. clone is implemented in the base JDOObject class.

Overrides:
generateCloneMethod in class CodeGenerator
Returns:
String The field declarations necessary for property change support

removeObsoleteCode

protected StringBuilder removeObsoleteCode(StringBuilder builder)
Remove code that is implemented in the parent JDOObject class.

Parameters:
builder - The StringBuilder to be cleaned.
Returns:
StringBuilder The modified builder instance. This is the same instance as the one passed in.
See Also:
changeDefinition(java.lang.StringBuilder), removeHash(java.lang.StringBuilder), removePropertyChange(java.lang.StringBuilder)

changeDefinition

protected StringBuilder changeDefinition(StringBuilder builder)
Replace the class definition with a new definition as a sub-class of JDOObject.

Parameters:
builder - The StringBuilder to be cleaned.
Returns:
StringBuilder The modified builder instance. This is the same instance as the one passed in.

removeHash

protected StringBuilder removeHash(StringBuilder builder)
Remove the fields for the hash code.

Parameters:
builder - The StringBuilder to be cleaned.
Returns:
StringBuilder The modified builder instance. This is the same instance as the one passed in.

removeOldValue

protected StringBuilder removeOldValue(StringBuilder builder)
Remove assignment of old value to a temporary value used to fire property change events from mutator methods.

Parameters:
builder - The StringBuilder to be cleaned.
Returns:
StringBuilder The modified builder instance. This is the same instance as the one passed in.

removePropertyChange

protected StringBuilder removePropertyChange(StringBuilder builder)
Remove the firePropertyChange method invocation in the mutator methods.

Parameters:
builder - The StringBuilder to be cleaned.
Returns:
StringBuilder The modified builder instance. This is the same instance as the one passed in.

generateMethods

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

Overrides:
generateMethods in class ModelGenerator
Returns:
String The source code for the methods to be included in the JavaBean.
See Also:
ModelGenerator.generateMethods()

generateFactory

protected void generateFactory()
                        throws IOException
Generate a Factory class that handles interactions between the JDO JavaBean objects and the JDO datastore.

Throws:
IOException - If errors are encountered while writing the generated source file.
See Also:
generateFactoryInitialisers(), generateSaveMethod(), generateFactoryMethods()

generateFactoryInitialisers

protected String generateFactoryInitialisers()
Generate the initialiser methods for the factory class.

Returns:
String The source code for the initialisers.

generateSaveMethod

protected String generateSaveMethod()
Generate the save method that will be used to save a JDO JavaBean to the JDO data store.

Returns:
String The source code for the save method.

generateDeleteMethod

protected String generateDeleteMethod()
Generate the delete method that will be used to delete a JDO JavaBean to the JDO data store.

Returns:
String The source code for the save method.

generateFactoryMethods

protected String generateFactoryMethods()
Generate additional factory methods for fetching the JDO JavaBean instances from the JDO data store.

Returns:
String The source code for the factory methods.

generateMetaData

protected void generateMetaData()
                         throws org.jdom.JDOMException,
                                IOException
Generate the JDO meta-data file for the JDO JavaBean.

Uses JDOM and Jaxen for parsing an existing meta-data file and for creating or updating the file.

Throws:
org.jdom.JDOMException - If errors are encountered while fetching the element.
IOException - If errors are encountered while writing to the meta-data file.
See Also:
JDOMetaDataGenerator.generate()

main

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

Parameters:
args - The command line arguments use.

SPT Core API