org.apache.openjpa.enhance
Class ApplicationIdTool

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

public class ApplicationIdTool
extends Object

Generates a class appropriate for use as an application identity class.

Author:
Patrick Linskey, Abe White

Nested Class Summary
static class ApplicationIdTool.Flags
          Run flags.
static interface ApplicationIdTool.ObjectIdLoader
          Interface implemented by metadata factories that can load non-existant object id classes.
 
Field Summary
static String TOKEN_DEFAULT
           
 
Constructor Summary
ApplicationIdTool(OpenJPAConfiguration conf, Class type)
          Constructs a new ApplicationIdTool capable of generating an object id class for type.
ApplicationIdTool(OpenJPAConfiguration conf, Class type, ClassMetaData meta)
          Constructs a new tool instance capable of generating an object id class for meta.
 
Method Summary
 String getCode()
          Return the code generated for the application id, or null if invalid class or the run() method has not been called.
 CodeFormat getCodeFormat()
          The code formatter for the generated Java code.
 File getDirectory()
          The directory to write source to.
 boolean getIgnoreErrors()
          Return false if this tool is configured to throw an exception on an attempt to generate an id class for a type that does not use application identity.
 Set getImportPackages()
          Returns the collection of packages that need to be imported.
 ClassMetaData getMetaData()
          Return metadata for the type we are generating an application id for.
 String getToken()
          The token to use to separate stringified primary key field values.
 Class getType()
          Return the type we are generating an application id for.
 Writer getWriter()
          The writer to write source to, or null to write to default file.
 boolean isInnerClass()
          Returns true if the application identity class should be an inner class.
static void main(String[] args)
          Usage: java org.apache.openjpa.enhance.ApplicationIdTool [option]* <class name | .java file | .class file | .jdo file>+ Where the following options are recognized.
 void record()
          Writes the generated code to the proper file.
 boolean run()
          Generates the sourcecode for the application id class; returns false if the class is invalid.
static boolean run(OpenJPAConfiguration conf, String[] args, ApplicationIdTool.Flags flags, ClassLoader loader)
          Run the tool.
static boolean run(OpenJPAConfiguration conf, String[] args, Options opts)
          Run the application id tool with the given command-line and given configuration.
 void setCodeFormat(CodeFormat format)
          Set the code formatter for the generated Java code.
 void setDirectory(File dir)
          The directory to write source to.
 void setIgnoreErrors(boolean ignore)
          Set to false if this tool should throw an exception on an attempt to generate an id class for a type that does not use application identity.
 void setToken(String token)
          The token to use to separate stringified primary key field values.
 void setWriter(Writer writer)
          The writer to write source to, or null to write to default file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOKEN_DEFAULT

public static final String TOKEN_DEFAULT
See Also:
Constant Field Values
Constructor Detail

ApplicationIdTool

public ApplicationIdTool(OpenJPAConfiguration conf,
                         Class type)
Constructs a new ApplicationIdTool capable of generating an object id class for type.


ApplicationIdTool

public ApplicationIdTool(OpenJPAConfiguration conf,
                         Class type,
                         ClassMetaData meta)
Constructs a new tool instance capable of generating an object id class for meta.

Method Detail

getIgnoreErrors

public boolean getIgnoreErrors()
Return false if this tool is configured to throw an exception on an attempt to generate an id class for a type that does not use application identity.


setIgnoreErrors

public void setIgnoreErrors(boolean ignore)
Set to false if this tool should throw an exception on an attempt to generate an id class for a type that does not use application identity.


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.


getDirectory

public File getDirectory()
The directory to write source to. Defaults to the directory of the Java file for the set type. If the given directory does not match the package of the object id, the package structure will be created below the directory.


setDirectory

public void setDirectory(File dir)
The directory to write source to. Defaults to the directory of the Java file for the set type. If the given directory does not match the package of the object id, the package structure will be created below the directory.


getToken

public String getToken()
The token to use to separate stringified primary key field values.


setToken

public void setToken(String token)
The token to use to separate stringified primary key field values.


getWriter

public Writer getWriter()
The writer to write source to, or null to write to default file.


setWriter

public void setWriter(Writer writer)
The writer to write source to, or null to write to default file.


getType

public Class getType()
Return the type we are generating an application id for.


getMetaData

public ClassMetaData getMetaData()
Return metadata for the type we are generating an application id for.


getCode

public String getCode()
Return the code generated for the application id, or null if invalid class or the run() method has not been called.


isInnerClass

public boolean isInnerClass()
Returns true if the application identity class should be an inner class.


run

public boolean run()
Generates the sourcecode for the application id class; returns false if the class is invalid.


record

public void record()
            throws IOException
Writes the generated code to the proper file.

Throws:
IOException

getImportPackages

public Set getImportPackages()
Returns the collection of packages that need to be imported.


main

public static void main(String[] args)
                 throws IOException,
                        ClassNotFoundException
Usage: java org.apache.openjpa.enhance.ApplicationIdTool [option]* <class name | .java file | .class file | .jdo file>+ Where the following options are recognized. Each additional argument can be either the full class name of the type to create an id class for, the path to the .java file for the type, the path to the .class file for the type, or the path to a .jdo file listing one or more types. If a .java file already exists for an application id, it will be backed up to a file named <orig file name>~.

Throws:
IOException
ClassNotFoundException

run

public static boolean run(OpenJPAConfiguration conf,
                          String[] args,
                          Options opts)
                   throws IOException,
                          ClassNotFoundException
Run the application id tool with the given command-line and given configuration. Returns false if invalid options were given.

Throws:
IOException
ClassNotFoundException

run

public static boolean run(OpenJPAConfiguration conf,
                          String[] args,
                          ApplicationIdTool.Flags flags,
                          ClassLoader loader)
                   throws IOException,
                          ClassNotFoundException
Run the tool. Returns false if invalid options were given.

Throws:
IOException
ClassNotFoundException


Copyright © 2006 Apache Software Foundation. All Rights Reserved.