Package org.jibx.binding.classes
Class ClassFile
- java.lang.Object
-
- org.jibx.binding.classes.ClassFile
-
public class ClassFile extends java.lang.ObjectClass file information. Wraps the actual class file data as well as associated management information.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description protected static byte[]EMPTY_BYTESstatic ClassItem[]EMPTY_CLASS_ITEMSprotected static ExistingMethod[]EMPTY_METHOD_ARRAYprivate static intJAVA7_MAJOR_VERSIONMajor version number for Java 7.private JavaClassm_curClassBase class information as loaded by BCEL.private ClassItemm_defaultConstructorAdded default constructor for class.private java.io.Filem_fileActual class file information.private ClassGenm_genClassModified class generator (lazy create, only if needed).private ConstantPoolGenm_genPoolConstant pool generator for modified class (lazy create, only if needed).private intm_hashCodeCached hash code value for class.private intm_inheritDepthDepth of superclass hierarchy for class (lazy computation).private java.lang.String[]m_instanceOfsAll classes and interfaces of which this is an instance (lazy create, only if needed.protected InstructionBuilderm_instBuilderInstruction factory for modified class (lazy create, only if needed).protected java.lang.String[]m_interfaceNamesNames of all interfaces directly implemented by this class.private booleanm_isExtendableBinding code can be added to class flag.private booleanm_isHashCurrentHash code computation for class is current flag.private booleanm_isModifiedFlag for class modified.private booleanm_isSamePackageClass in same package as superclass flag.private booleanm_isWritableFile is writable flag.private java.util.HashMapm_itemMapMap to class item information.private Method[]m_methodsAll methods defined by this class or interface (lazy create, only if needed).private java.lang.Stringm_nameFully qualified class name.private java.lang.Stringm_pathLoad path (used to report source of unmodifiable class).private java.io.Filem_rootDirectory root for class.private java.lang.Stringm_signatureSignature for class as type.private java.util.HashMapm_suffixMapMap for method names with possibly generated suffixes (lazy create, only if needed).protected ClassFilem_superClassSuper class of this class (set by caller, since it may require additional information to find the class file).private ClassFile[]m_superInterfacesClass files of interfaces extended by interface.private Typem_typeClass as type.private intm_uniqueIndexSuffix number for making method names unique (lazy computation).private intm_useCountUsage count for this class.static intPACKAGE_ACCESSstatic intPRIVATE_ACCESSprotected static intPRIVATEFIELD_ACCESSstatic intPROTECTED_ACCESSstatic intPUBLIC_ACCESSprivate static java.net.URLClassLoaders_directLoaderDirect class loader.private static ClassPaths_loaderSingleton loader from classpath.static intSYNTHETIC_ACCESS_FLAG
-
Constructor Summary
Constructors Modifier Constructor Description privateClassFile(java.lang.String name, ClassPath.ClassFile cf)Constructor for preexisting class file from classpath.ClassFile(java.lang.String name, java.io.File root, java.io.File file)Constructor for preexisting class file.ClassFile(java.lang.String name, java.io.File root, ClassFile sclas, int access, java.lang.String[] impls)Constructor for new class file.ClassFile(java.lang.String name, java.lang.String sig)Constructor for synthetic placeholder classfile with no backing class data.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaccumulateInterfaces(java.lang.String[] intfs, java.util.HashMap map, java.util.ArrayList accs)Accumulate interface signatures recursively.ClassItemaddDefaultConstructor()Add default constructor to a class.ClassItemaddField(java.lang.String type, java.lang.String name, int access)Add field to class without initialization.ClassItemaddField(java.lang.String type, java.lang.String name, int access, int init)Add field to class with initialintvalue.ClassItemaddField(java.lang.String type, java.lang.String name, int access, java.lang.String init)Add field to class with initialStringvalue.booleanaddInterface(java.lang.String intf)Add interface to class.ClassItemaddMethod(Method method)Add method to class.ClassItemaddPrivateField(java.lang.String type, java.lang.String name)Add private field to class without initialization.voidcodeComplete()Finalize current modified state of class.protected intcomputeHashCode()Computes a hash code based on characteristics of the class.voiddelete()Delete class file information.booleandeleteField(java.lang.String name)Delete field from class.booleandeleteMethod(java.lang.String name, java.lang.String sig)Delete method from class.java.lang.StringderiveClassName(java.lang.String prefix, java.lang.String suffix)Derive generated class name.static booleanequalFieldOrMethods(FieldOrMethod a, FieldOrMethod b)Compare two field or method items to see if they're equal.static booleanequalMethods(Method a, Method b)Compare two methods to see if they're equal.booleanequals(java.lang.Object obj)Check if objects are equal.protected FieldgetAccessibleField(java.lang.String name)Get internal information for field.protected MethodgetAccessibleMethod(java.lang.String name, java.lang.String sig)Get internal information for method without respect to potential trailing arguments or return value.private MethodgetBestAccessibleMethod(java.lang.String name, int access, Type ret, Type[] args)Get information for best matching method.ClassItemgetBestMethod(java.lang.String name, java.lang.String ret, java.lang.String[] args)Get information for best matching method.ExistingMethod[]getBindingMethods(java.lang.String prefix, java.lang.String[] matches)Get all binding methods currently defined in class.static ClassFilegetClassFile(java.lang.String name)Constructor for preexisting class file from classpath.private ClassGengetClassGen()Get generator for modifying class.static java.lang.ClassLoadergetClassLoader()Get the classloader used for classes referenced in the binding.ConstantPoolGengetConstPoolGen()Get constant pool generator for modifying class.protected FieldgetDefinedField(java.lang.String name)Get internal information for field.ClassItemgetDirectField(java.lang.String name)Get information for field.ClassItemgetField(java.lang.String name)Get information for field.ClassItem[]getFieldItems()Get array of fields defined by class.java.io.FilegetFile()Get actual file for class.ClassItemgetInitializerMethod(java.lang.String sig)Get information for initializer.java.lang.String[]getInstanceSigs()Get signatures for all types of which instances of this type are instances.InstructionBuildergetInstructionBuilder()Get instruction builder for modifying class.java.lang.String[]getInterfaces()Get names of all interfaces implemented by class.ClassItemgetMethod(java.lang.String name, java.lang.String sig)Get information for method without respect to potential trailing arguments or return value.ClassItemgetMethod(java.lang.String name, java.lang.String[] sigs)Get information for method matching one of several possible signatures.ClassItem[]getMethodItems()Get array of methods defined by class.private Method[]getMethods()Get array of methods defined by class or interface.java.lang.StringgetName()Get fully qualified class name.java.lang.StringgetPackage()Get package name.JavaClassgetRawClass()Get raw current class information.java.io.FilegetRoot()Get root directory for load path.java.lang.StringgetSignature()Get signature for class as type.ClassItemgetStaticMethod(java.lang.String name, java.lang.String sig)Get information for static method without respect to return value.ClassFilegetSuperFile()Get superclass information.java.lang.StringgetSuperName()Get superclass name.TypegetType()Get class as type.intgetUseCount()Get use count for class.inthashCode()Get hash code.intincrementUseCount()Increment use count for class.private voidinit(java.lang.String name, java.lang.String path, java.io.InputStream ins)Internal initialization method.private voidinitInterface()Retrieve superinterfaces for an interface class.booleanisAbstract()Check if class is abstract.booleanisAccessible(ClassItem item)Check accessible method.booleanisArray()Check if class is an array.private static booleanisAssignmentCompatible(Type have, Type need)Check if one type is assignment compatible with another type.booleanisComplete()Check if class is in complete state.booleanisExtendable()Check if binding methods can be added to class.booleanisImplements(java.lang.String sig)Check if class implements an interface.booleanisInterface()Check if class is an interface.booleanisModifiable()Check if class is modifiable.booleanisModified()Check if class has been modified.private static booleanisSuffixName(java.lang.String name)Check if a method name matches the pattern for a generated unique suffix.booleanisSuperclass(java.lang.String name)Check if another class is a superclass of this one.static java.lang.ClassloadClass(java.lang.String name)Try loading class from classpath.java.lang.StringmakeUniqueMethodName(java.lang.String name)Make method name unique with generated suffix.private static booleanmatchAccess(FieldOrMethod item, int access)Check for match to specified access level.voidremoveMethod(Method method)Remove method from class.voidsetModified()Set class modified flag.static voidsetPaths(java.lang.String[] paths)Set class paths to be searched.voidsetSuperFile(ClassFile sclas)Set superclass information.voidsetUnmodifiable()Force class to unmodifiable state.ClassItemupdateField(java.lang.String type, java.lang.String name, int access, java.lang.String init)Update class field with initialStringvalue.voidwriteFile()Write out modified class information.voidwriteFile(java.io.OutputStream os)Write out modified class information.
-
-
-
Field Detail
-
JAVA7_MAJOR_VERSION
private static final int JAVA7_MAJOR_VERSION
Major version number for Java 7.- See Also:
- Constant Field Values
-
PRIVATE_ACCESS
public static final int PRIVATE_ACCESS
- See Also:
- Constant Field Values
-
PACKAGE_ACCESS
public static final int PACKAGE_ACCESS
- See Also:
- Constant Field Values
-
PROTECTED_ACCESS
public static final int PROTECTED_ACCESS
- See Also:
- Constant Field Values
-
PUBLIC_ACCESS
public static final int PUBLIC_ACCESS
- See Also:
- Constant Field Values
-
SYNTHETIC_ACCESS_FLAG
public static final int SYNTHETIC_ACCESS_FLAG
- See Also:
- Constant Field Values
-
PRIVATEFIELD_ACCESS
protected static final int PRIVATEFIELD_ACCESS
-
EMPTY_METHOD_ARRAY
protected static final ExistingMethod[] EMPTY_METHOD_ARRAY
-
EMPTY_BYTES
protected static final byte[] EMPTY_BYTES
-
EMPTY_CLASS_ITEMS
public static final ClassItem[] EMPTY_CLASS_ITEMS
-
s_loader
private static ClassPath s_loader
Singleton loader from classpath.
-
s_directLoader
private static java.net.URLClassLoader s_directLoader
Direct class loader.
-
m_name
private java.lang.String m_name
Fully qualified class name.
-
m_signature
private java.lang.String m_signature
Signature for class as type.
-
m_type
private Type m_type
Class as type.
-
m_root
private java.io.File m_root
Directory root for class.
-
m_path
private java.lang.String m_path
Load path (used to report source of unmodifiable class).
-
m_file
private java.io.File m_file
Actual class file information.
-
m_isSamePackage
private boolean m_isSamePackage
Class in same package as superclass flag.
-
m_isWritable
private boolean m_isWritable
File is writable flag.
-
m_isExtendable
private boolean m_isExtendable
Binding code can be added to class flag.
-
m_superClass
protected ClassFile m_superClass
Super class of this class (set by caller, since it may require additional information to find the class file).
-
m_interfaceNames
protected java.lang.String[] m_interfaceNames
Names of all interfaces directly implemented by this class.
-
m_superInterfaces
private ClassFile[] m_superInterfaces
Class files of interfaces extended by interface.
-
m_instanceOfs
private java.lang.String[] m_instanceOfs
All classes and interfaces of which this is an instance (lazy create, only if needed.
-
m_methods
private Method[] m_methods
All methods defined by this class or interface (lazy create, only if needed).
-
m_curClass
private JavaClass m_curClass
Base class information as loaded by BCEL.
-
m_genClass
private ClassGen m_genClass
Modified class generator (lazy create, only if needed).
-
m_genPool
private ConstantPoolGen m_genPool
Constant pool generator for modified class (lazy create, only if needed).
-
m_instBuilder
protected InstructionBuilder m_instBuilder
Instruction factory for modified class (lazy create, only if needed).
-
m_suffixMap
private java.util.HashMap m_suffixMap
Map for method names with possibly generated suffixes (lazy create, only if needed).
-
m_itemMap
private java.util.HashMap m_itemMap
Map to class item information.
-
m_isModified
private boolean m_isModified
Flag for class modified.
-
m_useCount
private int m_useCount
Usage count for this class.
-
m_isHashCurrent
private boolean m_isHashCurrent
Hash code computation for class is current flag.
-
m_hashCode
private int m_hashCode
Cached hash code value for class.
-
m_inheritDepth
private int m_inheritDepth
Depth of superclass hierarchy for class (lazy computation).
-
m_uniqueIndex
private int m_uniqueIndex
Suffix number for making method names unique (lazy computation).
-
m_defaultConstructor
private ClassItem m_defaultConstructor
Added default constructor for class.
-
-
Constructor Detail
-
ClassFile
public ClassFile(java.lang.String name, java.io.File root, java.io.File file) throws java.io.IOException, JiBXExceptionConstructor for preexisting class file. Loads the class data and prepares it for use.- Parameters:
name- fully qualified class nameroot- directory root from class loading path listfile- actual class file- Throws:
java.io.IOException- if unable to open fileJiBXException- if error in reading class file
-
ClassFile
public ClassFile(java.lang.String name, java.lang.String sig)Constructor for synthetic placeholder classfile with no backing class data.- Parameters:
name- fully qualified class namesig- corresponding class signature
-
ClassFile
public ClassFile(java.lang.String name, java.io.File root, ClassFile sclas, int access, java.lang.String[] impls) throws JiBXExceptionConstructor for new class file. Initializes the class data and prepares it for use.- Parameters:
name- fully qualified class nameroot- directory root from class loading path listsclas- superclass of new classaccess- access flags for classimpls- array of interfaces implemented by new class (non-null, empty if none)- Throws:
JiBXException- on error loading interface information
-
ClassFile
private ClassFile(java.lang.String name, ClassPath.ClassFile cf) throws JiBXException, java.io.IOExceptionConstructor for preexisting class file from classpath. Loads the class data and prepares it for use.- Parameters:
name- fully qualified class name- Throws:
java.io.IOException- if unable to open fileJiBXException- if error loading superclass or other support file
-
-
Method Detail
-
getClassFile
public static ClassFile getClassFile(java.lang.String name) throws java.io.IOException, JiBXException
Constructor for preexisting class file from classpath. Loads the class data and prepares it for use.- Parameters:
name- fully qualified class name- Returns:
- null if unable to find class file
- Throws:
java.io.IOException- if error reading fileJiBXException- if error loading superclass or other support file
-
init
private void init(java.lang.String name, java.lang.String path, java.io.InputStream ins) throws JiBXExceptionInternal initialization method. This is used to handle common initialization for the constructors.- Parameters:
name- fully qualified class namepath- class file pathins- input stream for class file data- Throws:
JiBXException- if unable to load class file
-
initInterface
private void initInterface() throws JiBXExceptionRetrieve superinterfaces for an interface class. These are collected at initialization so that we can support getting the full set of methods later without worrying about throwing an exception.- Throws:
JiBXException- on error loading interface information
-
isInterface
public boolean isInterface()
Check if class is an interface. This only checks existing classes, assuming that no generated classes are interfaces.- Returns:
trueif an interface,falseif not
-
isAbstract
public boolean isAbstract()
Check if class is abstract. This only checks existing classes, assuming that no generated classes are abstract.- Returns:
trueif an abstract class,falseif not
-
isArray
public boolean isArray()
Check if class is an array. This only checks existing classes, assuming that no generated classes are arrays.- Returns:
trueif an array class,falseif not
-
isModifiable
public boolean isModifiable()
Check if class is modifiable.- Returns:
trueif class is modifiable,falseif not
-
isExtendable
public boolean isExtendable()
Check if binding methods can be added to class.- Returns:
trueif methods can be added,falseif not
-
getName
public java.lang.String getName()
Get fully qualified class name.- Returns:
- fully qualified name for class
-
getSignature
public java.lang.String getSignature()
Get signature for class as type.- Returns:
- signature for class used as type
-
getType
public Type getType()
Get class as type.- Returns:
- class as type
-
getPackage
public java.lang.String getPackage()
Get package name.- Returns:
- package name for class
-
getRoot
public java.io.File getRoot()
Get root directory for load path.- Returns:
- root directory in path used for loading file
-
getFile
public java.io.File getFile()
Get actual file for class.- Returns:
- file used for class
-
getRawClass
public JavaClass getRawClass()
Get raw current class information.- Returns:
- raw current class information
-
getSuperName
public java.lang.String getSuperName()
Get superclass name.- Returns:
- fully qualified name of superclass
-
setSuperFile
public void setSuperFile(ClassFile sclas)
Set superclass information.- Parameters:
sclas- superclass information
-
getSuperFile
public ClassFile getSuperFile()
Get superclass information.- Returns:
- super class information as loaded (
nullif no superclass - java.lang.Object, interface, or primitive)
-
getInterfaces
public java.lang.String[] getInterfaces()
Get names of all interfaces implemented by class.- Returns:
- names of all interfaces implemented directly by class
(non-
null, empty array if none)
-
addInterface
public boolean addInterface(java.lang.String intf)
Add interface to class. The interface is added to the class if not already defined.- Parameters:
intf- fully qualified interface name- Returns:
trueif added,falseif already present
-
accumulateInterfaces
protected void accumulateInterfaces(java.lang.String[] intfs, java.util.HashMap map, java.util.ArrayList accs) throws JiBXExceptionAccumulate interface signatures recursively.- Parameters:
intfs- names of interfaces implementedmap- map for interfaces already accumulatedaccs- accumulated interface names- Throws:
JiBXException- if configuration error
-
getInstanceSigs
public java.lang.String[] getInstanceSigs() throws JiBXExceptionGet signatures for all types of which instances of this type are instances.- Returns:
- all signatures suppored by instances
- Throws:
JiBXException- if configuration error
-
isImplements
public boolean isImplements(java.lang.String sig) throws JiBXExceptionCheck if class implements an interface.- Parameters:
sig- signature of interface to be checked- Returns:
trueif interface is implemented by class,falseif not- Throws:
JiBXException- if configuration error
-
isSuperclass
public boolean isSuperclass(java.lang.String name)
Check if another class is a superclass of this one.- Parameters:
name- of superclass to be checked- Returns:
trueif named class is a superclass of this one,falseif not
-
getFieldItems
public ClassItem[] getFieldItems()
Get array of fields defined by class.- Returns:
- array of fields defined by class
-
getDefinedField
protected Field getDefinedField(java.lang.String name)
Get internal information for field. This can only be used with existing classes, and only checks for fields that are actually members of the class (not superclasses).- Parameters:
name- field name- Returns:
- field information, or
nullif field not found
-
getAccessibleField
protected Field getAccessibleField(java.lang.String name)
Get internal information for field. This can only be used with existing classes. If the field is not found directly, superclasses are checked for inherited fields matching the supplied name.- Parameters:
name- field name- Returns:
- field information, or
nullif field not found
-
getDirectField
public ClassItem getDirectField(java.lang.String name)
Get information for field. This can only be used with existing classes, and only checks for fields that are actually members of the class (not superclasses).- Parameters:
name- field name- Returns:
- field information, or
nullif field not found
-
getField
public ClassItem getField(java.lang.String name) throws JiBXException
Get information for field. This can only be used with existing classes. If the field is not found directly, superclasses are checked for inherited fields matching the supplied name.- Parameters:
name- field name- Returns:
- field information
- Throws:
JiBXException- if field not found
-
getMethods
private Method[] getMethods()
Get array of methods defined by class or interface. In the case of an interface, this merges all methods from superinterfaces in the array returned.- Returns:
- array of methods defined by class
-
getMethodItems
public ClassItem[] getMethodItems()
Get array of methods defined by class.- Returns:
- array of methods defined by class
-
getAccessibleMethod
protected Method getAccessibleMethod(java.lang.String name, java.lang.String sig)Get internal information for method without respect to potential trailing arguments or return value. This can only be used with existing classes. If the method is not found directly, superclasses are checked for inherited methods matching the supplied name. This compares the supplied partial signature against the actual method signature, and considers it a match if the actual sigature starts with the supplied signature..- Parameters:
name- method namesig- partial method signature to be matched- Returns:
- method information, or
nullif method not found
-
getMethod
public ClassItem getMethod(java.lang.String name, java.lang.String sig)
Get information for method without respect to potential trailing arguments or return value. This can only be used with existing classes. If the method is not found directly, superclasses are checked for inherited methods matching the supplied name. This compares the supplied partial signature against the actual method signature, and considers it a match if the actual sigature starts with the supplied signature..- Parameters:
name- method namesig- partial method signature to be matched- Returns:
- method information, or
nullif method not found
-
getMethod
public ClassItem getMethod(java.lang.String name, java.lang.String[] sigs)
Get information for method matching one of several possible signatures. This can only be used with existing classes. If a match is not found directly, superclasses are checked for inherited methods matching the supplied name and signatures. The signature variations are checked in the order supplied.- Parameters:
name- method namesigs- possible signatures for method (including return type)- Returns:
- method information, or
nullif method not found
-
matchAccess
private static boolean matchAccess(FieldOrMethod item, int access)Check for match to specified access level. This treats a field or method as matching if the access level is the same as or more open than the required level.- Parameters:
item- information for field or method to be checkedaccess- required access level for match- Returns:
trueif access level match,falseif not
-
isAssignmentCompatible
private static boolean isAssignmentCompatible(Type have, Type need)Check if one type is assignment compatible with another type. This is an ugly replacement for apparently broken BCEL code.- Parameters:
have- type being checkedneed- type needed- Returns:
trueif compatible,falseif not
-
getBestAccessibleMethod
private Method getBestAccessibleMethod(java.lang.String name, int access, Type ret, Type[] args)Get information for best matching method. This tries to find a method which matches the specified name, return type, and argument types. If an exact match is not found it looks for a method with a return type that is extended or implemented by the specified type and arguments that are extended or implemented by the specified types. This can only be used with existing classes. If the method is not found directly, superclasses are checked for inherited methods.- Parameters:
name- method nameaccess- access level required for matching methodsret- return value type (nullif indeterminant)args- argument value types (nullif indeterminant)- Returns:
- method information, or
nullif method not found
-
getBestMethod
public ClassItem getBestMethod(java.lang.String name, java.lang.String ret, java.lang.String[] args)
Get information for best matching method. This tries to find a method which matches the specified name, return type, and argument types. If an exact match is not found it looks for a method with a return type that is extended or implemented by the specified type and arguments that are extended or implemented by the specified types. This can only be used with existing classes. If the method is not found directly, superclasses are checked for inherited methods.- Parameters:
name- method nameret- return value type (nullif indeterminant)args- argument value types (nullif indeterminant)- Returns:
- method information, or
nullif method not found
-
getInitializerMethod
public ClassItem getInitializerMethod(java.lang.String sig)
Get information for initializer. This can only be used with existing classes. Only the class itself is checked for an initializer matching the argument list signature.- Parameters:
sig- encoded argument list signature- Returns:
- method information, or
nullif method not found
-
getStaticMethod
public ClassItem getStaticMethod(java.lang.String name, java.lang.String sig)
Get information for static method without respect to return value. This can only be used with existing classes. Only the class itself is checked for a method matching the supplied name and argument list signature.- Parameters:
name- method namesig- encoded argument list signature- Returns:
- method information, or
nullif method not found
-
getBindingMethods
public ExistingMethod[] getBindingMethods(java.lang.String prefix, java.lang.String[] matches)
Get all binding methods currently defined in class. Binding methods are generally identified by a supplied prefix, but additional methods can be specified the the combination of exact name and signature. This is a little kludgy, but necessary to handle the "marshal" method added to mapped classes.- Parameters:
prefix- identifying prefix for binding methodsmatches- pairs of method name and signature to be matched as exceptions to the prefix matching- Returns:
- existing binding methods
-
isAccessible
public boolean isAccessible(ClassItem item)
Check accessible method. Check if a field or method in another class is accessible from within this class.- Parameters:
item- field or method information- Returns:
trueif accessible,falseif not
-
getClassGen
private ClassGen getClassGen()
Get generator for modifying class.- Returns:
- generator for class
-
getConstPoolGen
public ConstantPoolGen getConstPoolGen()
Get constant pool generator for modifying class.- Returns:
- constant pool generator for class
-
getInstructionBuilder
public InstructionBuilder getInstructionBuilder()
Get instruction builder for modifying class.- Returns:
- instruction builder for class
-
addMethod
public ClassItem addMethod(Method method)
Add method to class.- Parameters:
method- method to be added- Returns:
- added method information
-
removeMethod
public void removeMethod(Method method)
Remove method from class.- Parameters:
method- method to be removed
-
addField
public ClassItem addField(java.lang.String type, java.lang.String name, int access, java.lang.String init)
Add field to class with initialStringvalue. If a field with the same name already exists, it is overwritten.- Parameters:
type- fully qualified class name of field typename- field nameaccess- access flags for fieldinit- initial value for field- Returns:
- field information
-
addField
public ClassItem addField(java.lang.String type, java.lang.String name, int access, int init)
Add field to class with initialintvalue. If a field with the same name already exists, it is overwritten.- Parameters:
type- fully qualified class name of field typename- field nameaccess- access flags for fieldinit- initial value for field- Returns:
- field information
-
updateField
public ClassItem updateField(java.lang.String type, java.lang.String name, int access, java.lang.String init)
Update class field with initialStringvalue. If the field already exists with the same characteristics it is left unchanged; otherwise any existing field with the same name is overwritten.- Parameters:
type- fully qualified class name of field typename- field nameaccess- access flags for fieldinit- initial value for field- Returns:
- field information
-
addField
public ClassItem addField(java.lang.String type, java.lang.String name, int access)
Add field to class without initialization. If a field with the same name already exists, it is overwritten.- Parameters:
type- fully qualified class name of field typename- field nameaccess- access flags for field- Returns:
- field information
-
addPrivateField
public ClassItem addPrivateField(java.lang.String type, java.lang.String name)
Add private field to class without initialization. If a field with the same name already exists, it is overwritten.- Parameters:
type- fully qualified class name of field typename- field name- Returns:
- field information
-
addDefaultConstructor
public ClassItem addDefaultConstructor()
Add default constructor to a class. The added default constructor just calls the default constructor for the superclass. If the superclass doesn't have a default constructor, this method is called recursively to add one if possible.- Returns:
- constructor information
-
isSuffixName
private static boolean isSuffixName(java.lang.String name)
Check if a method name matches the pattern for a generated unique suffix.- Parameters:
name- method name to be checked- Returns:
trueif name matches suffix pattern,falseif not
-
makeUniqueMethodName
public java.lang.String makeUniqueMethodName(java.lang.String name)
Make method name unique with generated suffix. The suffixed method name is tracked so that it will not be used again.- Parameters:
name- base name before suffix is appended- Returns:
- name with unique suffix appended
-
deleteField
public boolean deleteField(java.lang.String name)
Delete field from class.- Parameters:
name- field name- Returns:
trueif field was present,falseif not
-
deleteMethod
public boolean deleteMethod(java.lang.String name, java.lang.String sig)Delete method from class.- Parameters:
name- method namesig- method signature- Returns:
trueif method was present,falseif not
-
getUseCount
public int getUseCount()
Get use count for class.- Returns:
- use count for this class
-
incrementUseCount
public int incrementUseCount()
Increment use count for class.- Returns:
- use count (after increment)
-
setUnmodifiable
public void setUnmodifiable()
Force class to unmodifiable state. This prevents any additions, changes, deletions to the file.
-
isModified
public boolean isModified()
Check if class has been modified.- Returns:
trueif class is modified,falseif not
-
setModified
public void setModified()
Set class modified flag.
-
isComplete
public boolean isComplete()
Check if class is in complete state.- Returns:
trueif class is complete,falseif not
-
computeHashCode
protected int computeHashCode()
Computes a hash code based on characteristics of the class. The characteristics used in computing the hash code include the base class, implemented interfaces, method names, field names, and package, but not the actual class name or signature. The current static version of the class is used for this computation, so if the class is being modifiedcodeComplete()should be called before this method. Note that this is designed for use with the classes generated by JiBX, and is not necessarily a good model for general usage.- Returns:
- computed hash code value
-
codeComplete
public void codeComplete()
Finalize current modified state of class. This converts the modified class state into a static form, then computes a hash code based on characteristics of the class. If the class has not been modified it just computes the hash code. Note that this won't initialize the array of superinterfaces if used with an interface, but that shouldn't be a problem since we don't create any interfaces.
-
hashCode
public int hashCode()
Get hash code. This is based on most characteristics of the class, including the actual methods, but excluding the class name. It is only valid after thecodeComplete()method is called.- Overrides:
hashCodein classjava.lang.Object- Returns:
- hash code based on code sequence
-
equalFieldOrMethods
public static boolean equalFieldOrMethods(FieldOrMethod a, FieldOrMethod b)Compare two field or method items to see if they're equal. This handles only the comparisons that apply to both fields and methods. It does not include comparing access flags, since these may be different due to access requirements.- Parameters:
a- first field or method itemb- second field or method item- Returns:
trueif the equal,falseif not
-
equalMethods
public static boolean equalMethods(Method a, Method b)Compare two methods to see if they're equal. This checks only the details of the exception handling and actual code, not the name or signature.- Parameters:
a- first methodb- second method- Returns:
trueif the equal,falseif not
-
equals
public boolean equals(java.lang.Object obj)
Check if objects are equal. Compares first based on hash code, then on the actual contents of the class, including package, implemented interfaces, superclass, methods, and fields (but not the actual class name). It is only valid after thecodeComplete()method is called.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj-- Returns:
trueif equal objects,falseif not
-
delete
public void delete()
Delete class file information. Deletes the class file for this class, if it exists. Does nothing if no class file has been generated.
-
writeFile
public void writeFile(java.io.OutputStream os) throws java.io.IOExceptionWrite out modified class information. Writes the modified class file to an output stream.- Parameters:
os- output stream for writing modified class- Throws:
java.io.IOException- if error writing to file
-
writeFile
public void writeFile() throws java.io.IOExceptionWrite out modified class information. Writes the modified class file back out to the original file. If the class file has not been modified, the original file is kept unchanged.- Throws:
java.io.IOException- if error writing to file
-
deriveClassName
public java.lang.String deriveClassName(java.lang.String prefix, java.lang.String suffix)Derive generated class name. 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 this class.- Parameters:
prefix- generated class name prefixsuffix- generated class name suffix- Returns:
- derived class name
-
setPaths
public static void setPaths(java.lang.String[] paths)
Set class paths to be searched.- Parameters:
paths- ordered set of paths to be searched for class files
-
loadClass
public static java.lang.Class loadClass(java.lang.String name)
Try loading class from classpath.- Parameters:
name- fully qualified name of class to be loaded- Returns:
- loaded class, or
nullif not found
-
getClassLoader
public static java.lang.ClassLoader getClassLoader()
Get the classloader used for classes referenced in the binding.- Returns:
- classloader
-
-