Package org.jibx.binding.classes
Class BoundClass
java.lang.Object
org.jibx.binding.classes.BoundClass
Bound class handler. Each instance controls and organizes information for a
class included in one or more binding definitions.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
Prefix used for access methods.private static final Type[]
Empty argument type array.private final ClassFile
Bound class file information.private final MungedClass
Munged version of target class (null
if target class completely unmodifiable).private HashMap
Map from field or method to load access method (lazy create,null
if not used).private final MungedClass
Class receiving code generated for target class (may be same asm_directMungedClass
.private HashMap
Map from field or method to store access method (lazy create,null
if not used).private static MungedClass
Class used for code generation proxy with unmodifiable classes (lazy create,null
if not yet needed).private static String
Package of first modifiable class.private static File
Root for package of first modifiable class.private static String
Name to be used for code generation proxy class.private static HashMap
Map from bound class name (or bound and munged combination) to binding information. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
BoundClass
(ClassFile bound, MungedClass dmunge, MungedClass munge) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFactory
(String fact) Add binding factory to class.private static BoundClass
createInstance
(String key, ClassFile bound, MungedClass dmunge, MungedClass munge) Create binding information for class.deriveClassName
(String prefix, String suffix) Derive generated class name for bound class.private static BoundClass
findOrCreateInstance
(ClassFile bound, MungedClass munge) Find or create binding information for class.Get bound class file information.Get bound class file name.Get direct munged class file information, if available.private static MungedClass
Get the generic munge class.static BoundClass
getInstance
(String name, BoundClass context) Get binding information for class.static BoundClass
getInstance
(ClassFile cf, BoundClass context) Get binding information for class.getLoadMethod
(ClassItem item, ClassFile from) Get load access method for member of this class.Get munged class file information.getStoreMethod
(ClassItem item, ClassFile from) Get store access method for member of this class.getUniqueMethod
(MethodBuilder builder) Get unique method.getUniqueNamed
(MethodBuilder builder) Get unique method.boolean
Check if class being changed directly.boolean
Check if class being changed directly with restrictions.static void
reset()
Discard cached information and reset in preparation for a new binding run.static void
Set override modification information.
-
Field Details
-
ACCESS_PREFIX
Prefix used for access methods.- See Also:
-
EMPTY_TYPE_ARGS
private static final Type[] EMPTY_TYPE_ARGSEmpty argument type array. -
s_nameMap
Map from bound class name (or bound and munged combination) to binding information. -
s_modifyPackage
Package of first modifiable class. -
s_modifyRoot
Root for package of first modifiable class. -
s_mungeName
Name to be used for code generation proxy class. -
s_genericMunge
Class used for code generation proxy with unmodifiable classes (lazy create,null
if not yet needed). -
m_boundClass
Bound class file information. -
m_directMungedClass
Munged version of target class (null
if target class completely unmodifiable). -
m_mungedClass
Class receiving code generated for target class (may be same asm_directMungedClass
. -
m_loadMap
Map from field or method to load access method (lazy create,null
if not used). -
m_storeMap
Map from field or method to store access method (lazy create,null
if not used).
-
-
Constructor Details
-
BoundClass
Constructor.- Parameters:
bound
- target class file informationdmunge
- information for bound class (null
if not modifiable)munge
- class file for class hosting generated code (may be same asinvalid reference
dmunge
-
-
Method Details
-
getClassFile
Get bound class file information.- Returns:
- class file information for bound class
-
getClassName
Get bound class file name.- Returns:
- name of bound class
-
getDirectMungedFile
Get direct munged class file information, if available.- Returns:
- class file information for class receiving binding code
-
getMungedFile
Get munged class file information.- Returns:
- class file information for class receiving binding code
-
isDirectAccess
public boolean isDirectAccess()Check if class being changed directly.- Returns:
true
if bound class is being modified,false
if using a surrogate
-
isLimitedDirectAccess
public boolean isLimitedDirectAccess()Check if class being changed directly with restrictions. This is used for the special case of modifiable Java 7 class files, which still require a separate class for most of the code generation but are modified directly with binding factory information and basic implementations of the binding interface methods.- Returns:
true
if bound class can be modified directly with basic binding information,false
if using a surrogate
-
getLoadMethod
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 accessedfrom
- 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
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 accessedfrom
- 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
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
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
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
-
createInstance
private static BoundClass createInstance(String key, ClassFile bound, MungedClass dmunge, 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 combinationbound
- class information for bound classdmunge
- information for bound class (null
if not modifiable)munge
- information for class receiving generated code (may be the same asinvalid reference
dmunge
- Returns:
- binding information for class
-
findOrCreateInstance
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 classmunge
- information for surrogate class receiving generated code- Returns:
- binding information for class
-
getInstance
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 informationcontext
- context class for code generation, ornull
if no context- Returns:
- binding information for class
- Throws:
JiBXException
- on configuration error
-
getGenericMunge
Get the generic munge class. If one does not already exist, this will create it.- Returns:
- munge
- Throws:
JiBXException
-
getInstance
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 classcontext
- context class for code generation, ornull
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
Set override modification information. This allows the binding to control directly the root directory and package for added classes, and also to set the binding name used as a modifier on the generic munge adapter class. It may be called multiple times withnull
values for unknown parameters that may later be overridden.- Parameters:
root
- classpath root directory for added classespkg
- package for added classesname
- binding name
-
deriveClassName
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 prefixsuffix
- generated class name suffix- Returns:
- derived class name
-