org.jibx.binding.classes
Class BoundClass

java.lang.Object
  extended by org.jibx.binding.classes.BoundClass

public class BoundClass
extends java.lang.Object

Bound class handler. Each instance controls and organizes information for a class included in one or more binding definitions.

Version:
1.0
Author:
Dennis M. Sosnoski

Field Summary
private static java.lang.String ACCESS_PREFIX
          Prefix used for access methods.
private static org.apache.bcel.generic.Type[] EMPTY_TYPE_ARGS
          Empty argument type array.
private static java.lang.String GENERIC_MUNGE_CLASS
          Class used for code munging when no specific class available.
private  ClassFile m_boundClass
          Bound class file information.
private  java.util.HashMap m_loadMap
          Map from field or method to load access method (lazy create, null if not used).
private  MungedClass m_mungedClass
          Class receiving code generated for target class.
private  java.util.HashMap m_storeMap
          Map from field or method to store access method (lazy create, null if not used).
private static MungedClass s_genericMunge
          Class used for code generation proxy with unmodifiable classes.
private static java.lang.String s_modifyPackage
          Package of first modifiable class.
private static java.io.File s_modifyRoot
          Root for package of first modifiable class.
private static java.util.HashMap s_nameMap
          Map from bound class name (or bound and munged combination) to binding information.
 
Constructor Summary
private BoundClass(ClassFile bound, MungedClass munge)
          Constructor.
 
Method Summary
 void addFactory(java.lang.String fact)
          Add binding factory to class.
private static BoundClass createInstance(java.lang.String key, ClassFile bound, MungedClass munge)
          Create binding information for class.
 java.lang.String deriveClassName(java.lang.String prefix, java.lang.String suffix)
          Derive generated class name for bound class.
private static BoundClass findOrCreateInstance(ClassFile bound, MungedClass munge)
          Find or create binding information for class.
 ClassFile getClassFile()
          Get bound class file information.
 java.lang.String getClassName()
          Get bound class file name.
static BoundClass getInstance(ClassFile cf, BoundClass context)
          Get binding information for class.
static BoundClass getInstance(java.lang.String name, BoundClass context)
          Get binding information for class.
 ClassItem getLoadMethod(ClassItem item, ClassFile from)
          Get load access method for member of this class.
 ClassFile getMungedFile()
          Get munged class file information.
 ClassItem getStoreMethod(ClassItem item, ClassFile from)
          Get store access method for member of this class.
 BindingMethod getUniqueMethod(MethodBuilder builder)
          Get unique method.
 BindingMethod getUniqueNamed(MethodBuilder builder)
          Get unique method.
 boolean isDirectAccess()
          Check if class being changed directly.
static void reset()
          Discard cached information and reset in preparation for a new binding run.
 void setFactoryList()
          Generate factory list.
static void setModify(java.io.File root, java.lang.String pkg)
          Discard cached information and reset in preparation for a new binding run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERIC_MUNGE_CLASS

private static final java.lang.String GENERIC_MUNGE_CLASS
Class used for code munging when no specific class available.

See Also:
Constant Field Values

ACCESS_PREFIX

private static final java.lang.String ACCESS_PREFIX
Prefix used for access methods.

See Also:
Constant Field Values

EMPTY_TYPE_ARGS

private static final org.apache.bcel.generic.Type[] EMPTY_TYPE_ARGS
Empty argument type array.


s_nameMap

private static java.util.HashMap s_nameMap
Map from bound class name (or bound and munged combination) to binding information.


s_modifyPackage

private static java.lang.String s_modifyPackage
Package of first modifiable class.


s_modifyRoot

private static java.io.File s_modifyRoot
Root for package of first modifiable class.


s_genericMunge

private static MungedClass s_genericMunge
Class used for code generation proxy with unmodifiable classes.


m_boundClass

private final ClassFile m_boundClass
Bound class file information.


m_mungedClass

private final MungedClass m_mungedClass
Class receiving code generated for target class.


m_loadMap

private java.util.HashMap m_loadMap
Map from field or method to load access method (lazy create, null if not used).


m_storeMap

private java.util.HashMap m_storeMap
Map from field or method to store access method (lazy create, null if not used).

Constructor Detail

BoundClass

private BoundClass(ClassFile bound,
                   MungedClass munge)
Constructor.

Parameters:
bound - target class file information
munge - class file for class hosting generated code
Method Detail

getClassFile

public ClassFile getClassFile()
Get bound class file information.

Returns:
class file information for bound class

getClassName

public java.lang.String getClassName()
Get bound class file name.

Returns:
name of bound class

getMungedFile

public ClassFile getMungedFile()
Get munged class file information.

Returns:
class file information for class being modified

isDirectAccess

public boolean isDirectAccess()
Check if class being changed directly.

Returns:
true if bound class is being modified, false if using a surrogate

getLoadMethod

public ClassItem getLoadMethod(ClassItem item,
                               ClassFile from)
                        throws JiBXException
Get load access method for member of this class. If the access method does not already exist it's created by this call. If the access method does exist but without access from the context class, the access permission on the method is broadened (from package to protected or public, or from protected to public).

Parameters:
item - field or method to be accessed
from - context class from which access is required
Returns:
the item itself if it's accessible from the required context, an access method that is accessible if the item is not itself
Throws:
JiBXException - on configuration error

getStoreMethod

public ClassItem getStoreMethod(ClassItem item,
                                ClassFile from)
                         throws JiBXException
Get store access method for member of this class. If the access method does not already exist it's created by this call. If the access method does exist but without access from the context class, the access permission on the method is broadened (from package to protected or public, or from protected to public).

Parameters:
item - field or method to be accessed
from - context class from which access is required
Returns:
the item itself if it's accessible from the required context, an access method that is accessible if the item is not itself
Throws:
JiBXException - on configuration error

getUniqueMethod

public BindingMethod getUniqueMethod(MethodBuilder builder)
                              throws JiBXException
Get unique method. Just delegates to the modified class handling, with unique suffix appended to method name.

Parameters:
builder - method to be defined
Returns:
defined method item
Throws:
JiBXException - on configuration error

getUniqueNamed

public BindingMethod getUniqueNamed(MethodBuilder builder)
                             throws JiBXException
Get unique method. Just delegates to the modified class handling. The supplied name is used without change.

Parameters:
builder - method to be defined
Returns:
defined method item
Throws:
JiBXException - on configuration error

addFactory

public void addFactory(java.lang.String fact)
Add binding factory to class. Makes sure that there's no surrogate class for code generation, then delegates to the modified class handling.

Parameters:
fact - binding factory name

setFactoryList

public void setFactoryList()
                    throws JiBXException
Generate factory list. Makes sure that there's no surrogate class for code generation, then delegates to the modified class handling.

Throws:
JiBXException - on configuration error

createInstance

private static BoundClass createInstance(java.lang.String key,
                                         ClassFile bound,
                                         MungedClass munge)
Create binding information for class. This creates the combination of bound class and (if different) munged class and adds it to the internal tables.

Parameters:
key - text identifier for this bound class and munged class combination
bound - class information for bound class
munge - information for surrogate class receiving generated code, or null if no separate class
Returns:
binding information for class

findOrCreateInstance

private static BoundClass findOrCreateInstance(ClassFile bound,
                                               MungedClass munge)
Find or create binding information for class. If the combination of bound class and munged class already exists it's returned directly, otherwise it's created and returned.

Parameters:
bound - class information for bound class
munge - information for surrogate class receiving generated code
Returns:
binding information for class

getInstance

public static BoundClass getInstance(ClassFile cf,
                                     BoundClass context)
                              throws JiBXException
Get binding information for class. This finds the class in which code generation for the target class takes place. Normally this class will be the target class itself, but in cases where the target class is not modifiable an alternate class will be used. This can take two forms. If the context class is provided and it is a subclass of the target class, code for the target class is instead added to the context class. If there is no context class, or if the context class is not a subclass of the target class, a unique catch-all class is used.

Parameters:
cf - bound class information
context - context class for code generation, or null if no context
Returns:
binding information for class
Throws:
JiBXException - on configuration error

getInstance

public static BoundClass getInstance(java.lang.String name,
                                     BoundClass context)
                              throws JiBXException
Get binding information for class. This version takes a fully-qualified class name, calling the paired method if necessary to create a new instance.

Parameters:
name - fully qualified name of bound class
context - context class for code generation, or null if no context
Returns:
binding information for class
Throws:
JiBXException - on configuration error

reset

public static void reset()
Discard cached information and reset in preparation for a new binding run.


setModify

public static void setModify(java.io.File root,
                             java.lang.String pkg)
Discard cached information and reset in preparation for a new binding run.


deriveClassName

public java.lang.String deriveClassName(java.lang.String prefix,
                                        java.lang.String suffix)
Derive generated class name for bound class. This generates a JiBX class name from the name of this class, using the supplied prefix and suffix information. The derived class name is always in the same package as the munged class for this class.

Parameters:
prefix - generated class name prefix
suffix - generated class name suffix
Returns:
derived class name


Project Web Site