com.caucho.java
Class AbstractGenerator

java.lang.Object
  extended by com.caucho.java.AbstractGenerator
Direct Known Subclasses:
EntityGenerator, ListenerGenerator

public abstract class AbstractGenerator
extends java.lang.Object

Generates the Java code for the wrapped object.


Field Summary
protected  JavaWriter _out
           
 
Constructor Summary
AbstractGenerator()
           
 
Method Summary
 java.lang.Class compile()
          Compiles the Java code
 void compileJava()
          Compiles the class.
 void generate()
          Call to generate the java source.
 void generateJava()
          Starts generation of the Java code
 Path getClassDir()
          Returns the class dir for the generated class.
 java.lang.String getClassName()
          Returns the generated class name
 JavaCompilerUtil getCompiler()
           
 java.lang.String getFullClassName()
          Returns the full class name
 GenClass getGenClass()
          Gets the java class.
 JavaWriter getOut()
          Returns the java writer.
 java.lang.String getPackageName()
          Returns the generated package name
 java.lang.ClassLoader getParentLoader()
          Sets the parent class loader.
 Path getSearchPath()
           
 java.lang.Class loadClass(boolean preload)
          Loads the generated class.
 java.lang.Class loadClass(java.lang.String fullClassName, boolean preload)
          Loads the generated class.
 void popDepth()
          Pops an indentation depth.
 java.lang.Class<?> preload()
          Try to preload the class.
 void print(char ch)
          Prints a character
 void print(int ch)
          Prints a character
 void print(java.lang.String s)
          Prints a string
 void printClass(java.lang.Class cl)
          Prints the Java represention of the class
protected  void printDependList(java.util.ArrayList<PersistentDependency> depends)
          Generates the class dependency code.
 void println()
          Prints a new line.
 void println(java.lang.String s)
          Prints a string with a new line
 void printMethodHeader(java.lang.reflect.Method method)
          Prints a method header.
 void printMethodHeader(java.lang.String methodName, java.lang.Class[] parameters, java.lang.Class returnType, java.lang.Class[] exn)
          Prints a method header.
 void printMethodHeader(java.lang.String name, java.lang.reflect.Method method)
          Prints a method header.
 void printStr(java.lang.String s)
          Prints a string
 void pushDepth()
          Pushes an indentation depth.
 void setClassDir(Path workPath)
          Sets the work path for the generated class.
 void setFullClassName(java.lang.String fullClassName)
          Sets the full generated class.
 void setGenClass(GenClass genClass)
          Sets the java class.
 void setLoader(java.lang.ClassLoader loader)
          Sets the class loader.
 void setParentLoader(java.lang.ClassLoader loader)
          Sets the parent class loader.
 void setSearchPath(Path path)
          Sets the search path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_out

protected JavaWriter _out
Constructor Detail

AbstractGenerator

public AbstractGenerator()
Method Detail

setSearchPath

public void setSearchPath(Path path)
Sets the search path.


getSearchPath

public Path getSearchPath()

setFullClassName

public void setFullClassName(java.lang.String fullClassName)
Sets the full generated class.


getFullClassName

public java.lang.String getFullClassName()
Returns the full class name


getPackageName

public java.lang.String getPackageName()
Returns the generated package name


getClassName

public java.lang.String getClassName()
Returns the generated class name


setGenClass

public void setGenClass(GenClass genClass)
Sets the java class.


getGenClass

public GenClass getGenClass()
Gets the java class.


setParentLoader

public void setParentLoader(java.lang.ClassLoader loader)
Sets the parent class loader.

Parameters:
loader - parent class loader

setLoader

public void setLoader(java.lang.ClassLoader loader)
Sets the class loader.

Parameters:
loader - parent class loader

getParentLoader

public java.lang.ClassLoader getParentLoader()
Sets the parent class loader.

Returns:
the parent class loader

setClassDir

public void setClassDir(Path workPath)
Sets the work path for the generated class.


getClassDir

public Path getClassDir()
Returns the class dir for the generated class.


preload

public java.lang.Class<?> preload()
                           throws java.io.IOException
Try to preload the class.

Returns:
true if the preloaded class is still valid.
Throws:
java.io.IOException

generate

public void generate()
              throws java.lang.Exception
Call to generate the java source.

Throws:
java.lang.Exception

compile

public java.lang.Class compile()
                        throws java.lang.Exception
Compiles the Java code

Throws:
java.lang.Exception

generateJava

public void generateJava()
                  throws java.lang.Exception
Starts generation of the Java code

Throws:
java.lang.Exception

printDependList

protected void printDependList(java.util.ArrayList<PersistentDependency> depends)
                        throws java.io.IOException
Generates the class dependency code.

Parameters:
depends - list of Paths representing dependencies
Throws:
java.io.IOException

printMethodHeader

public void printMethodHeader(java.lang.reflect.Method method)
                       throws java.io.IOException
Prints a method header.

Parameters:
method - the method to print
Throws:
java.io.IOException

printMethodHeader

public void printMethodHeader(java.lang.String name,
                              java.lang.reflect.Method method)
                       throws java.io.IOException
Prints a method header.

Parameters:
name - the method name to print
method - the method to print
Throws:
java.io.IOException

printMethodHeader

public void printMethodHeader(java.lang.String methodName,
                              java.lang.Class[] parameters,
                              java.lang.Class returnType,
                              java.lang.Class[] exn)
                       throws java.io.IOException
Prints a method header.

Parameters:
methodName - the method name to print
param - the method argument classes
returnType - the return type of the method
exn - array of exceptions thrown by the method
Throws:
java.io.IOException

printClass

public void printClass(java.lang.Class cl)
                throws java.io.IOException
Prints the Java represention of the class

Throws:
java.io.IOException

compileJava

public void compileJava()
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Compiles the class.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

getCompiler

public JavaCompilerUtil getCompiler()

loadClass

public java.lang.Class loadClass(boolean preload)
                          throws java.io.IOException
Loads the generated class. If any class dependencies have changed, return null.

Throws:
java.io.IOException

loadClass

public java.lang.Class loadClass(java.lang.String fullClassName,
                                 boolean preload)
                          throws java.io.IOException
Loads the generated class. If any class dependencies have changed, return null.

Throws:
java.io.IOException

getOut

public JavaWriter getOut()
Returns the java writer.


pushDepth

public void pushDepth()
               throws java.io.IOException
Pushes an indentation depth.

Throws:
java.io.IOException

popDepth

public void popDepth()
              throws java.io.IOException
Pops an indentation depth.

Throws:
java.io.IOException

print

public void print(int ch)
           throws java.io.IOException
Prints a character

Throws:
java.io.IOException

print

public void print(char ch)
           throws java.io.IOException
Prints a character

Throws:
java.io.IOException

print

public void print(java.lang.String s)
           throws java.io.IOException
Prints a string

Throws:
java.io.IOException

printStr

public void printStr(java.lang.String s)
              throws java.io.IOException
Prints a string

Throws:
java.io.IOException

println

public void println()
             throws java.io.IOException
Prints a new line.

Throws:
java.io.IOException

println

public void println(java.lang.String s)
             throws java.io.IOException
Prints a string with a new line

Throws:
java.io.IOException