Package org.jibx.binding.classes
Class MungedClass
- java.lang.Object
-
- org.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.- Author:
- Dennis M. Sosnoski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MungedClass.JiBXFilter
Filter for class files generated by JiBX.
-
Field Summary
Fields Modifier and Type Field Description 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.HashSet
s_classNameSet
Set of class names in list (used to assure uniqueness).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
Constructors Modifier Constructor Description private
MungedClass(ClassFile cf)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (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[][]
fixDispositions()
Finalize class name assignments and dispositions.(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.static void
writeChanges()
Write all modified class files, and delete all obsolete class files from previous runs of the binding compiler.
-
-
-
Field Detail
-
EMPTY_CLASSFILE_ARRAY
private static final ClassFile[] EMPTY_CLASSFILE_ARRAY
Empty class file array.
-
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_classNameSet
private static java.util.HashSet s_classNameSet
Set of class names in list (used to assure uniqueness).
-
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()
Delete pre-existing binding methods that are no longer needed.
-
getUniqueMethod
BindingMethod getUniqueMethod(MethodBuilder builder, boolean suffix)
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 definedsuffix
- append name suffix to assure uniqueness flag- Returns:
- defined method item
-
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 which have not been added to the preserve list.- Parameters:
root
- class path root for directory (non-null
)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()
Generate factory list. Adds or replaces the existing static array of factories in the class.
-
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 thefixDispositions()
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. This uses the class name as a identifier to prevent duplicate entries in the list, so that classes which are still under construction can be handled.- Parameters:
cf
-
-
fixDispositions
public static ClassFile[][] fixDispositions()
Finalize class name assignments and dispositions.- Returns:
- three-way array of class files, for modified, unchanged, and deleted
-
writeChanges
public static void writeChanges() throws JiBXException
Write all modified class files, and delete all obsolete class files from previous runs of the binding compiler.- Throws:
JiBXException
- on write error
-
reset
public static void reset()
Discard cached information and reset in preparation for a new binding run.
-
-