org.fuin.srcgen4javassist
Class ByteCodeGenerator

java.lang.Object
  extended by org.fuin.srcgen4javassist.ByteCodeGenerator

public final class ByteCodeGenerator
extends java.lang.Object

Creates the byte code for a model class and has some more helper methods.


Constructor Summary
ByteCodeGenerator()
          Default constructor that uses ClassPool.getDefault(), default class loader and default domain.
ByteCodeGenerator(javassist.ClassPool pool)
          Constructor with user defined class pool, default class loader and default protection domain.
ByteCodeGenerator(javassist.ClassPool pool, java.lang.ClassLoader classLoader)
          Constructor with user defined class pool, class loader and default protection domain.
ByteCodeGenerator(javassist.ClassPool pool, java.lang.ClassLoader classLoader, java.security.ProtectionDomain domain)
          Constructor with user defined class pool, class loader and domain.
 
Method Summary
 java.lang.Class createClass(SgClass modelClass)
          Generates the byte code for a model class and returns it.
 java.lang.Object createInstance(java.lang.Class clasz)
          Creates an instance using the nor-arguments constructor and maps all exceptions into RuntimeException.
 java.lang.Object createInstance(java.lang.Class clasz, java.lang.Class[] argTypes, java.lang.Object[] initArgs)
          Creates an instance mapping all exceptions into RuntimeException.
 java.lang.Object createInstance(SgClass clasz)
          Creates an instance from a model class with it's no argument constructor and maps all exceptions into RuntimeException.
 java.lang.Object createInstance(SgClass clasz, java.lang.Class[] argTypes, java.lang.Object[] initArgs)
          Creates an instance from a model class mapping all exceptions into RuntimeException.
static ByteCodeGenerator createWithCurrentThreadContextClassLoader()
          Creates a generator initialized with default class pool and the context class loader of the current thread.
 java.lang.Class loadClass(SgClass modelClass)
          Tries to load the model class calling Class.forName(..)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteCodeGenerator

public ByteCodeGenerator()
Default constructor that uses ClassPool.getDefault(), default class loader and default domain.


ByteCodeGenerator

public ByteCodeGenerator(javassist.ClassPool pool)
Constructor with user defined class pool, default class loader and default protection domain.

Parameters:
pool - Class pool to use - If it's null ClassPool.getDefault()

ByteCodeGenerator

public ByteCodeGenerator(javassist.ClassPool pool,
                         java.lang.ClassLoader classLoader)
Constructor with user defined class pool, class loader and default protection domain.

Parameters:
pool - Class pool to use - If it's null ClassPool.getDefault()
classLoader - The class loader used to load classes. If it is null, the class loader returned by ClassPool.getClassLoader() is used.

ByteCodeGenerator

public ByteCodeGenerator(javassist.ClassPool pool,
                         java.lang.ClassLoader classLoader,
                         java.security.ProtectionDomain domain)
Constructor with user defined class pool, class loader and domain.

Parameters:
pool - Class pool to use - If it's null ClassPool.getDefault()
classLoader - The class loader used to load classes. If it is null, the class loader returned by ClassPool.getClassLoader() is used.
domain - The protection domain that classes belong to. If it is null, the default domain created by java.lang.ClassLoader is used.
Method Detail

createClass

public final java.lang.Class createClass(SgClass modelClass)
Generates the byte code for a model class and returns it. The class will only be created if it's not known (Class.forName(..) throws a ClassNotFoundException). If it's known the class will be returned instead of creating a new one.

Parameters:
modelClass - Model class to create the byte code for.
Returns:
Class.

loadClass

public java.lang.Class loadClass(SgClass modelClass)
Tries to load the model class calling Class.forName(..).

Parameters:
modelClass - Model class to lookup.
Returns:
Class (if it already exists) or null if it's unknown.

createInstance

public final java.lang.Object createInstance(java.lang.Class clasz)
Creates an instance using the nor-arguments constructor and maps all exceptions into RuntimeException.

Parameters:
clasz - Class to create an instance for.
Returns:
New instance.

createInstance

public final java.lang.Object createInstance(java.lang.Class clasz,
                                             java.lang.Class[] argTypes,
                                             java.lang.Object[] initArgs)
Creates an instance mapping all exceptions into RuntimeException.

Parameters:
clasz - Class to create an instance for.
argTypes - Argument types of the constructor to use.
initArgs - Argument values for the constructor.
Returns:
New instance.

createInstance

public final java.lang.Object createInstance(SgClass clasz,
                                             java.lang.Class[] argTypes,
                                             java.lang.Object[] initArgs)
Creates an instance from a model class mapping all exceptions into RuntimeException.

Parameters:
clasz - Class to create an instance for.
argTypes - Argument types of the constructor to use.
initArgs - Argument values for the constructor.
Returns:
New instance.

createInstance

public final java.lang.Object createInstance(SgClass clasz)
Creates an instance from a model class with it's no argument constructor and maps all exceptions into RuntimeException.

Parameters:
clasz - Class to create an instance for.
Returns:
New instance.

createWithCurrentThreadContextClassLoader

public static ByteCodeGenerator createWithCurrentThreadContextClassLoader()
Creates a generator initialized with default class pool and the context class loader of the current thread.

Returns:
New byte code generator instance.


Copyright © 2011 Future Invent Informationsmanagement GmbH. All Rights Reserved.