org.apache.jdo.enhancer
Class Main

java.lang.Object
  extended byorg.apache.jdo.impl.enhancer.util.Assertion
      extended byorg.apache.jdo.impl.enhancer.util.Support
          extended byorg.apache.jdo.enhancer.Main

public class Main
extends Support

Main is the starting point for the persistent filter tool.


Nested Class Summary
private  class Main.CmdLineOptions
          A class for holding the command line options.
 
Field Summary
static int CLASS_LOCATOR_ERROR
           
protected  ResourceLocator classLocator
          The locator for classes.
private  ClassFileEnhancer enhancer
          The byte code enhancer.
private  java.io.PrintWriter err
          The stream to write error messages to.
static int INTERNAL_ERROR
           
private  EnhancerMetaData jdoMetaData
          The metadata for the enhancer.
static int METADATA_ERROR
           
static int OK
           
private  Main.CmdLineOptions opts
          The command line options.
private  java.io.PrintWriter out
          The stream to write messages to.
static int USAGE_ERROR
           
 
Fields inherited from class org.apache.jdo.impl.enhancer.util.Support
timer
 
Constructor Summary
Main()
          Construct a filter tool instance
 
Method Summary
private  void closeInputStream(java.io.InputStream in)
          Closes an input stream.
private  void closeOutputStream(java.io.OutputStream out)
          Closes an output stream.
private static java.lang.String createClassFileName(java.lang.String classname)
          Creates a filename from a classname.
private  int createEnhancer()
           
private  void createOutputFile(boolean enhanced, java.lang.String filename, java.io.File temp)
          Creates the output file for an enhaced class- or zipfile.
private static void createPathOfFile(java.io.File file)
          Creates only the path of the given file.
private  java.io.File createZipOutputFile(java.lang.String zipfilename)
          Creates a file object that represents the output zipfile for a given zipfile to enhance.
private  void enhanceClassFile(java.io.InputStream in)
          Enhances a classfile.
private  int enhanceInputFiles(java.util.List classNames, java.util.List classFileNames, java.util.List zipFileNames, java.util.List jdoFileNames)
          Enhances all files entered in the command line.
private  void enhanceZipFile(java.lang.String filename)
          Enhances a zipfile.
private  int initClassLocator()
           
private  int initEnhancerMetaData()
           
private static boolean isClassFileName(java.lang.String filename)
          Tests if a filename is a classfile name (by testing if the filename ends with ".class").
private static boolean isJdoFileName(java.lang.String filename)
          Tests if a filename is a jdo file name (by testing if the filename ends with ".jdo").
private static boolean isZipFileName(java.lang.String filename)
          Tests if a filename is a zipfile (by testing if the filename ends with ".zip" or ".jar").
static void main(java.lang.String[] argv)
          This is where it all starts.
private  java.io.InputStream openClassInputStream(java.lang.String classname)
          Opens an input stream for the given classname.
private static java.io.InputStream openFileInputStream(java.lang.String filename)
          Opens an input stream for the given filename
private  void printError(java.lang.String msg, java.lang.Throwable ex)
          Prints out an error.
private  void printMessage(java.lang.String msg)
          Prints out a message.
 int process(java.lang.String[] argv)
          Process command line options and run enhancer.
 
Methods inherited from class org.apache.jdo.impl.enhancer.util.Support
getI18N, getI18N, getI18N, getI18N, getI18N, getI18N
 
Methods inherited from class org.apache.jdo.impl.enhancer.util.Assertion
affirm, affirm, affirm, affirm
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OK

public static final int OK
See Also:
Constant Field Values

USAGE_ERROR

public static final int USAGE_ERROR
See Also:
Constant Field Values

METADATA_ERROR

public static final int METADATA_ERROR
See Also:
Constant Field Values

CLASS_LOCATOR_ERROR

public static final int CLASS_LOCATOR_ERROR
See Also:
Constant Field Values

INTERNAL_ERROR

public static final int INTERNAL_ERROR
See Also:
Constant Field Values

out

private final java.io.PrintWriter out
The stream to write messages to.


err

private final java.io.PrintWriter err
The stream to write error messages to.


opts

private final Main.CmdLineOptions opts
The command line options.


enhancer

private ClassFileEnhancer enhancer
The byte code enhancer.


classLocator

protected ResourceLocator classLocator
The locator for classes.


jdoMetaData

private EnhancerMetaData jdoMetaData
The metadata for the enhancer.

Constructor Detail

Main

public Main()
Construct a filter tool instance

Method Detail

main

public static void main(java.lang.String[] argv)
This is where it all starts.


process

public int process(java.lang.String[] argv)
Process command line options and run enhancer.


initClassLocator

private int initClassLocator()

initEnhancerMetaData

private int initEnhancerMetaData()

createEnhancer

private int createEnhancer()

enhanceInputFiles

private int enhanceInputFiles(java.util.List classNames,
                              java.util.List classFileNames,
                              java.util.List zipFileNames,
                              java.util.List jdoFileNames)
Enhances all files entered in the command line.

Parameters:
classNames - List of class names.
classFileNames - List of class file names.
zipFileNames - List of zip file names.
jdoFileNames - List of jdo file names.

enhanceClassFile

private void enhanceClassFile(java.io.InputStream in)
                       throws java.io.IOException,
                              EnhancerUserException,
                              EnhancerFatalError
Enhances a classfile.

Parameters:
in - The input stream of the classfile.
Throws:
java.io.IOException
EnhancerUserException
EnhancerFatalError

enhanceZipFile

private void enhanceZipFile(java.lang.String filename)
                     throws java.io.IOException,
                            EnhancerUserException,
                            EnhancerFatalError
Enhances a zipfile.

Parameters:
filename - The filename of the zipfile.
Throws:
java.io.IOException
EnhancerUserException
EnhancerFatalError

openFileInputStream

private static java.io.InputStream openFileInputStream(java.lang.String filename)
                                                throws java.io.FileNotFoundException
Opens an input stream for the given filename

Parameters:
filename - The name of the file.
Returns:
The input stream.
Throws:
java.io.FileNotFoundException - If the file could not be found.

openClassInputStream

private java.io.InputStream openClassInputStream(java.lang.String classname)
                                          throws java.io.IOException
Opens an input stream for the given classname. The input stream is created via an URL that is obtained by the value of the sourcepath option and zip/jar file arguments.

Parameters:
classname - The name of the class (dot-notation).
Returns:
The input stream.
Throws:
java.io.IOException - If an I/O error occured.

createZipOutputFile

private java.io.File createZipOutputFile(java.lang.String zipfilename)
Creates a file object that represents the output zipfile for a given zipfile to enhance.

Parameters:
zipfilename - The input zipfile name.
Returns:
The output zipfile name.

createOutputFile

private void createOutputFile(boolean enhanced,
                              java.lang.String filename,
                              java.io.File temp)
                       throws java.io.IOException
Creates the output file for an enhaced class- or zipfile. If the enhanced file is written back depends on the command line options.

Parameters:
enhanced - Has the input file been enhanced?
filename - The name of the output file.
temp - The temp file, the output is written to.
Throws:
java.io.IOException - If the file could not be created.

closeInputStream

private void closeInputStream(java.io.InputStream in)
Closes an input stream.

Parameters:
in - The input stream.

closeOutputStream

private void closeOutputStream(java.io.OutputStream out)
Closes an output stream.

Parameters:
out - The output stream.

isClassFileName

private static boolean isClassFileName(java.lang.String filename)
Tests if a filename is a classfile name (by testing if the filename ends with ".class").

Parameters:
filename - The name of the file.
Returns:
Do we have a potential classfile?

isZipFileName

private static boolean isZipFileName(java.lang.String filename)
Tests if a filename is a zipfile (by testing if the filename ends with ".zip" or ".jar").

Parameters:
filename - The name of the file.

isJdoFileName

private static boolean isJdoFileName(java.lang.String filename)
Tests if a filename is a jdo file name (by testing if the filename ends with ".jdo").

Parameters:
filename - The name of the file.
Returns:
Do we have a potential jdo file?

createClassFileName

private static java.lang.String createClassFileName(java.lang.String classname)
Creates a filename from a classname. This is done by replacing '.' by '/'.

Parameters:
classname - The classname.
Returns:
The filename.

createPathOfFile

private static void createPathOfFile(java.io.File file)
                              throws java.io.IOException
Creates only the path of the given file.

Parameters:
file - The file.
Throws:
java.io.IOException - If an error occured.

printError

private void printError(java.lang.String msg,
                        java.lang.Throwable ex)
Prints out an error.

Parameters:
msg - The error message (can be null).
ex - An optional exception (can be null).

printMessage

private void printMessage(java.lang.String msg)
Prints out a message.

Parameters:
msg - The message.