com.sptci
Class CodeGenerator

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

public abstract class CodeGenerator
extends java.lang.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,v 1.2 2006/02/09 16:09:13 rakesh Exp $
Author:
Rakesh Vidyadharan 2006-02-07

Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> fields
          A Map of fields for the generated class.
protected  java.lang.String name
          The name of the class that is being generated.
protected  java.util.HashSet<java.lang.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  java.lang.String generateBeanMethods()
          Generate the accessor and mutator methods for the JavaBean.
protected  java.lang.String generateCloneMethod()
          Generate the clone method for the JavaBean.
protected  java.lang.String generateCompareToMethod()
          Generate the compareTo method for the JavaBean.
protected  java.lang.String generateEqualsMethod()
          Generate the equals method for the JavaBean.
protected  java.lang.String generateFields()
          Generate the default fields for the class.
protected  java.lang.String generateHashCodeMethod()
          Generate the equals method for the JavaBean.
protected  java.lang.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 java.lang.String name
The name of the class that is being generated.


fields

protected java.util.Map<java.lang.String,java.lang.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 java.util.HashSet<java.lang.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 java.lang.Exception
The abstract method that will generate the full source code.

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

generateFields

protected java.lang.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 java.lang.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 java.lang.String generateEqualsMethod()
Generate the equals method for the JavaBean.

Returns:
String The default equals method implementation.

generateHashCodeMethod

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

Returns:
String The default hashCode method implementation.

generateCompareToMethod

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

Returns:
String The default compareTo method implementation.

generateCloneMethod

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

Returns:
String The default clone method implementation.

generateBeanMethods

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

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


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