org.jibx.binding.classes
Class MungedClass

java.lang.Object
  extended byorg.jibx.binding.classes.MungedClass

public class MungedClass
extends java.lang.Object

Modifiable class handler. Each instance controls changes to a particular class modified by one or more binding definitions. As methods are generated they're checked for uniqueness. If an already-generated method is found with the same characteristics (including byte code) as the one being generated, the already-generated is used instead.

Version:
1.0
Author:
Dennis M. Sosnoski

Nested Class Summary
private static class MungedClass.JiBXFilter
          Filter for class files generated by JiBX.
 
Field Summary
private static java.lang.String BINDING_LISTNAME
          Name for list of binding factory names.
private static ClassFile[] EMPTY_CLASSFILE_ARRAY
          Empty class file array.
private static java.lang.String[] EXTRA_METHODS_MATCHES
          Name and signature for generated methods without standard prefix.
private  ClassFile m_classFile
          Munged class file information.
private  ExistingMethod[] m_existingMethods
          Existing binding methods in class.
private  java.lang.String m_factoryList
          List of factory names for this class.
private  java.util.HashMap m_methodMap
          Map from method byte code and signature to method item.
private static java.util.ArrayList s_classes
          Munged class information.
private static java.util.HashMap s_classMap
          Map from generated class to binding information.
private static java.util.HashMap s_directories
          Map of directories already checked for JiBX classes.
private static java.util.HashMap s_nameMap
          Map from class name to binding information.
private static java.util.ArrayList s_pendingClasses
          Munged classes to be unique-added at end of binding.
 
Constructor Summary
private MungedClass(ClassFile cf)
          Constructor.
 
Method Summary
(package private)  void addFactory(java.lang.String fact)
          Add binding factory to class.
static void addModifiedClass(ClassFile cf)
          Add class file to set modified.
(package private) static void checkDirectory(java.io.File root, java.lang.String pack)
          Check directory for JiBX generated files.
static void delayedAddUnique(ClassFile cf)
          Add unique support class at end of binding process.
static ClassFile[][] fixChanges(boolean write)
          Finalize changes to modified class files.
(package private)  ClassFile getClassFile()
          Get munged class file information.
(package private) static MungedClass getInstance(ClassFile cf)
          Get modification tracking information for class.
(package private)  BindingMethod getUniqueMethod(MethodBuilder builder, boolean suffix)
          Get unique method.
static ClassFile getUniqueSupportClass(ClassFile cf)
          Get unique generated support class.
private  void purgeUnusedMethods()
          Delete pre-existing binding methods that are no longer needed.
static void reset()
          Discard cached information and reset in preparation for a new binding run.
(package private)  void setFactoryList()
          Generate factory list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_CLASSFILE_ARRAY

private static final ClassFile[] EMPTY_CLASSFILE_ARRAY
Empty class file array.


BINDING_LISTNAME

private static final java.lang.String BINDING_LISTNAME
Name for list of binding factory names.

See Also:
Constant Field Values

EXTRA_METHODS_MATCHES

private static final java.lang.String[] EXTRA_METHODS_MATCHES
Name and signature for generated methods without standard prefix.


s_classes

private static java.util.ArrayList s_classes
Munged class information.


s_classMap

private static java.util.HashMap s_classMap
Map from generated class to binding information.


s_directories

private static java.util.HashMap s_directories
Map of directories already checked for JiBX classes.


s_nameMap

private static java.util.HashMap s_nameMap
Map from class name to binding information.


s_pendingClasses

private static java.util.ArrayList s_pendingClasses
Munged classes to be unique-added at end of binding.


m_classFile

private ClassFile m_classFile
Munged class file information.


m_methodMap

private java.util.HashMap m_methodMap
Map from method byte code and signature to method item.


m_existingMethods

private ExistingMethod[] m_existingMethods
Existing binding methods in class.


m_factoryList

private java.lang.String m_factoryList
List of factory names for this class.

Constructor Detail

MungedClass

private MungedClass(ClassFile cf)
Constructor. This sets up for modifying a class with added methods.

Parameters:
cf - owning class file information
Method Detail

getClassFile

ClassFile getClassFile()
Get munged class file information.

Returns:
class file information for bound class

purgeUnusedMethods

private void purgeUnusedMethods()
                         throws JiBXException
Delete pre-existing binding methods that are no longer needed.

Throws:
JiBXException - on configuration error

getUniqueMethod

BindingMethod getUniqueMethod(MethodBuilder builder,
                              boolean suffix)
                        throws JiBXException
Get unique method. If a method matching the byte code of the supplied method has already been defined the existing method is returned. Otherwise the method is added to the definitions. If necessary, a number suffix is appended to the method name to prevent conflicts with existing names.

Parameters:
builder - method to be defined
suffix - append name suffix to assure uniqueness flag
Returns:
defined method item
Throws:
JiBXException - on configuration error

getUniqueSupportClass

public static ClassFile getUniqueSupportClass(ClassFile cf)
Get unique generated support class. Allows tracking of all generated classes for common handling with the bound classes. Each generated support class is associated with a particular bound class.

Parameters:
cf - generated class file
Returns:
unique class file information

checkDirectory

static void checkDirectory(java.io.File root,
                           java.lang.String pack)
                    throws JiBXException
Check directory for JiBX generated files. Scans through all class files in the target directory and loads any that start with the JiBX identifier string.

Parameters:
root - class path root for directory
pack - package relative to root directory
Throws:
JiBXException - on configuration error

addFactory

void addFactory(java.lang.String fact)
Add binding factory to class. The binding factories are accumulated as a delimited string during generation, then dumped to a static field in the class at the end.

Parameters:
fact - binding factory name

setFactoryList

void setFactoryList()
              throws JiBXException
Generate factory list. Adds or replaces the existing static array of factories in the class.

Throws:
JiBXException - on configuration error

getInstance

static MungedClass getInstance(ClassFile cf)
                        throws JiBXException
Get modification tracking information for class.

Parameters:
cf - information for class to be modified (must be writable)
Returns:
binding information for class
Throws:
JiBXException - on configuration error

delayedAddUnique

public static void delayedAddUnique(ClassFile cf)
Add unique support class at end of binding process. This allows a class to be constructed in steps during handling of one or more bindings, with the class finished and checked for uniqueness only after all bindings have been handled. The actual add of the class is done during the fixChanges(boolean) handling.

Parameters:
cf - class file to be added as unique support class at end of binding

addModifiedClass

public static void addModifiedClass(ClassFile cf)
Add class file to set modified.

Parameters:
cf -

fixChanges

public static ClassFile[][] fixChanges(boolean write)
                                throws JiBXException
Finalize changes to modified class files.

Parameters:
write - replace original class files with modified versions
Returns:
three-way array of class files, for written, unmodified, and deleted
Throws:
JiBXException - on write error

reset

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



Project Web Site