org.apache.openjpa.enhance
Class CodeGenerator

java.lang.Object
  extended by org.apache.openjpa.enhance.CodeGenerator

public class CodeGenerator
extends Object

Generates Java class code from metadata.

Since:
0.3.0
Author:
Abe White, Stephen Kim

Constructor Summary
CodeGenerator(ClassMetaData meta)
          Constructor.
CodeGenerator(OpenJPAConfiguration conf, Class type)
          Constructor.
 
Method Summary
protected  void closeClassBrace(CodeFormat code)
          Append the closing code-level brace to the code; this can be overridden to add code to the bottom of the class.
 void generateCode()
          Writes the generated code to the proper directory.
protected  String getClassCode()
          Return a code template for the given class, or null to use the standard system-generated Java code.
 String getCode()
          Return the generated code, or null if generateCode() has not been called.
 File getCodeDirectory()
          The directory to write source to.
 CodeFormat getCodeFormat()
          The code formatter for the generated Java code.
protected  String getDeclaration(FieldMetaData field)
          Return a code template for the declaration of the given field, or null to use the system-generated default Java code.
protected  String getFieldCode(FieldMetaData field)
          Return a code template for the get/set methods of the given field, or null to use the system-generated default Java code.
 File getFile()
          Return Java file to write to.
 Set getImportPackages()
          Returns the set of packages that needs to be imported for this code.
protected  String getInitialValue(FieldMetaData field)
          Return code for the initial value for the given field, or null to use the default generated by the system.
 ClassMetaData getMetaData()
          Return metadata for the type being generated.
 Class getType()
          Return the type being generated.
protected  CodeFormat newCodeFormat()
          Return a copy of the internal code format.
protected  void openClassBrace(CodeFormat code)
          Append the opening code-level brace to the code; this can be overridden to add code to the top of the class.
 void setCodeFormat(CodeFormat format)
          Set the code formatter for the generated Java code.
 void setDirectory(File dir)
          The directory to write source to.
 void writeCode()
          Write the generated code to the proper file.
 void writeCode(Writer out)
          Write the code to the specified Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeGenerator

public CodeGenerator(OpenJPAConfiguration conf,
                     Class type)
Constructor. Supply configuration and class to generate code for.


CodeGenerator

public CodeGenerator(ClassMetaData meta)
Constructor. Supply configuration and metadata to generate code for.

Method Detail

getCodeDirectory

public File getCodeDirectory()
The directory to write source to. Defaults to the current directory. If the given directory does not match the package of the metadata, the package structure will be created below the directory.


setDirectory

public void setDirectory(File dir)
The directory to write source to. Defaults to the current directory. If the given directory does not match the package of the metadata, the package structure will be created below the directory.


getCodeFormat

public CodeFormat getCodeFormat()
The code formatter for the generated Java code.


setCodeFormat

public void setCodeFormat(CodeFormat format)
Set the code formatter for the generated Java code.


getType

public Class getType()
Return the type being generated.


getMetaData

public ClassMetaData getMetaData()
Return metadata for the type being generated.


getCode

public String getCode()
Return the generated code, or null if generateCode() has not been called.


generateCode

public void generateCode()
Writes the generated code to the proper directory.


writeCode

public void writeCode()
               throws IOException
Write the generated code to the proper file.

Throws:
IOException

writeCode

public void writeCode(Writer out)
               throws IOException
Write the code to the specified Writer.

Throws:
IOException

getImportPackages

public Set getImportPackages()
Returns the set of packages that needs to be imported for this code.


openClassBrace

protected void openClassBrace(CodeFormat code)
Append the opening code-level brace to the code; this can be overridden to add code to the top of the class.


closeClassBrace

protected void closeClassBrace(CodeFormat code)
Append the closing code-level brace to the code; this can be overridden to add code to the bottom of the class.


getFile

public File getFile()
Return Java file to write to.


newCodeFormat

protected CodeFormat newCodeFormat()
Return a copy of the internal code format.


getClassCode

protected String getClassCode()
Return a code template for the given class, or null to use the standard system-generated Java code. To facilitate template reuse, the following parameters can appear in the template; the proper values will be subtituted by the system: Returns null by default.


getInitialValue

protected String getInitialValue(FieldMetaData field)
Return code for the initial value for the given field, or null to use the default generated by the system. Returns null by default.


getDeclaration

protected String getDeclaration(FieldMetaData field)
Return a code template for the declaration of the given field, or null to use the system-generated default Java code. To facilitate template reuse, the following parameters can appear in your template; the proper values will be subtituted by the system: Returns null by default.


getFieldCode

protected String getFieldCode(FieldMetaData field)
Return a code template for the get/set methods of the given field, or null to use the system-generated default Java code. To facilitate template reuse, the following parameters can appear in your template; the proper values will be subtituted by the system:



Copyright © 2006-2007 Apache Software Foundation. All Rights Reserved.