SPT Core API

com.sptci
Class CodeGenerator

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

public abstract class CodeGenerator
extends Object

An abstract code generator. Generates the code for common methods that are implemented in source code.

Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: CodeGenerator.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2006-02-07

Field Summary
protected  Map<String,String> fields
          A Map of fields for the generated class.
protected  String name
          The name of the class that is being generated.
protected  HashSet<String> primitives
          A HashSet containing the primitive types defined for Java.
 
Constructor Summary
CodeGenerator()
          Default constructor.
 
Method Summary
abstract  void generate()
          The abstract method that will generate the full source code.
protected  String generateBeanMethods()
          Generate the accessor and mutator methods for the JavaBean.
protected  String generateCloneMethod()
          Generate the clone method for the JavaBean.
protected  String generateCompareToMethod()
          Generate the compareTo method for the JavaBean.
protected  String generateEqualsMethod()
          Generate the equals method for the JavaBean.
protected  String generateFields()
          Generate the default fields for the class.
protected  String generateHashCodeMethod()
          Generate the equals method for the JavaBean.
protected  String generateToStringMethod()
          Generate the toString method for the JavaBean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected String name
The name of the class that is being generated.


fields

protected Map<String,String> fields
A Map of fields for the generated class. The name of the field is stored as the key and the type of the field as the value.


primitives

protected HashSet<String> primitives
A HashSet containing the primitive types defined for Java.

Constructor Detail

CodeGenerator

public CodeGenerator()
Default constructor. Initialises code generator containers.

Method Detail

generate

public abstract void generate()
                       throws Exception
The abstract method that will generate the full source code.

Throws:
Exception - If errors are encountered while generating the source file.

generateFields

protected String generateFields()
Generate the default fields for the class. Sub-classes must over-ride this method, while usually using the results of this method to enhance their output.

Returns:
String The default fields to be added to each source file.

generateToStringMethod

protected String generateToStringMethod()
Generate the toString method for the JavaBean. Generate an XML representation of the class and its fields.

Returns:
String The default toString method implementation.

generateEqualsMethod

protected String generateEqualsMethod()
Generate the equals method for the JavaBean.

Returns:
String The default equals method implementation.

generateHashCodeMethod

protected String generateHashCodeMethod()
Generate the equals method for the JavaBean.

Returns:
String The default hashCode method implementation.

generateCompareToMethod

protected String generateCompareToMethod()
Generate the compareTo method for the JavaBean.

Returns:
String The default compareTo method implementation.

generateCloneMethod

protected String generateCloneMethod()
Generate the clone method for the JavaBean.

Returns:
String The default clone method implementation.

generateBeanMethods

protected String generateBeanMethods()
Generate the accessor and mutator methods for the JavaBean.

Returns:
String The default accessor and mutator methods for the fields.

SPT Core API