Class ClassFile


  • public class ClassFile
    extends java.lang.Object
    Class 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_BYTES  
      static ClassItem[] EMPTY_CLASS_ITEMS  
      protected static ExistingMethod[] EMPTY_METHOD_ARRAY  
      private static int JAVA7_MAJOR_VERSION
      Major version number for Java 7.
      private JavaClass m_curClass
      Base class information as loaded by BCEL.
      private ClassItem m_defaultConstructor
      Added default constructor for class.
      private java.io.File m_file
      Actual class file information.
      private ClassGen m_genClass
      Modified class generator (lazy create, only if needed).
      private ConstantPoolGen m_genPool
      Constant pool generator for modified class (lazy create, only if needed).
      private int m_hashCode
      Cached hash code value for class.
      private int m_inheritDepth
      Depth of superclass hierarchy for class (lazy computation).
      private java.lang.String[] m_instanceOfs
      All classes and interfaces of which this is an instance (lazy create, only if needed.
      protected InstructionBuilder m_instBuilder
      Instruction factory for modified class (lazy create, only if needed).
      protected java.lang.String[] m_interfaceNames
      Names of all interfaces directly implemented by this class.
      private boolean m_isExtendable
      Binding code can be added to class flag.
      private boolean m_isHashCurrent
      Hash code computation for class is current flag.
      private boolean m_isModified
      Flag for class modified.
      private boolean m_isSamePackage
      Class in same package as superclass flag.
      private boolean m_isWritable
      File is writable flag.
      private java.util.HashMap m_itemMap
      Map to class item information.
      private Method[] m_methods
      All methods defined by this class or interface (lazy create, only if needed).
      private java.lang.String m_name
      Fully qualified class name.
      private java.lang.String m_path
      Load path (used to report source of unmodifiable class).
      private java.io.File m_root
      Directory root for class.
      private java.lang.String m_signature
      Signature for class as type.
      private java.util.HashMap m_suffixMap
      Map for method names with possibly generated suffixes (lazy create, only if needed).
      protected ClassFile m_superClass
      Super class of this class (set by caller, since it may require additional information to find the class file).
      private ClassFile[] m_superInterfaces
      Class files of interfaces extended by interface.
      private Type m_type
      Class as type.
      private int m_uniqueIndex
      Suffix number for making method names unique (lazy computation).
      private int m_useCount
      Usage count for this class.
      static int PACKAGE_ACCESS  
      static int PRIVATE_ACCESS  
      protected static int PRIVATEFIELD_ACCESS  
      static int PROTECTED_ACCESS  
      static int PUBLIC_ACCESS  
      private static java.net.URLClassLoader s_directLoader
      Direct class loader.
      private static ClassPath s_loader
      Singleton loader from classpath.
      static int SYNTHETIC_ACCESS_FLAG  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ClassFile​(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 void accumulateInterfaces​(java.lang.String[] intfs, java.util.HashMap map, java.util.ArrayList accs)
      Accumulate interface signatures recursively.
      ClassItem addDefaultConstructor()
      Add default constructor to a class.
      ClassItem addField​(java.lang.String type, java.lang.String name, int access)
      Add field to class without initialization.
      ClassItem addField​(java.lang.String type, java.lang.String name, int access, int init)
      Add field to class with initial int value.
      ClassItem addField​(java.lang.String type, java.lang.String name, int access, java.lang.String init)
      Add field to class with initial String value.
      boolean addInterface​(java.lang.String intf)
      Add interface to class.
      ClassItem addMethod​(Method method)
      Add method to class.
      ClassItem addPrivateField​(java.lang.String type, java.lang.String name)
      Add private field to class without initialization.
      void codeComplete()
      Finalize current modified state of class.
      protected int computeHashCode()
      Computes a hash code based on characteristics of the class.
      void delete()
      Delete class file information.
      boolean deleteField​(java.lang.String name)
      Delete field from class.
      boolean deleteMethod​(java.lang.String name, java.lang.String sig)
      Delete method from class.
      java.lang.String deriveClassName​(java.lang.String prefix, java.lang.String suffix)
      Derive generated class name.
      static boolean equalFieldOrMethods​(FieldOrMethod a, FieldOrMethod b)
      Compare two field or method items to see if they're equal.
      static boolean equalMethods​(Method a, Method b)
      Compare two methods to see if they're equal.
      boolean equals​(java.lang.Object obj)
      Check if objects are equal.
      protected Field getAccessibleField​(java.lang.String name)
      Get internal information for field.
      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.
      private Method getBestAccessibleMethod​(java.lang.String name, int access, Type ret, Type[] args)
      Get information for best matching method.
      ClassItem getBestMethod​(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 ClassFile getClassFile​(java.lang.String name)
      Constructor for preexisting class file from classpath.
      private ClassGen getClassGen()
      Get generator for modifying class.
      static java.lang.ClassLoader getClassLoader()
      Get the classloader used for classes referenced in the binding.
      ConstantPoolGen getConstPoolGen()
      Get constant pool generator for modifying class.
      protected Field getDefinedField​(java.lang.String name)
      Get internal information for field.
      ClassItem getDirectField​(java.lang.String name)
      Get information for field.
      ClassItem getField​(java.lang.String name)
      Get information for field.
      ClassItem[] getFieldItems()
      Get array of fields defined by class.
      java.io.File getFile()
      Get actual file for class.
      ClassItem getInitializerMethod​(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.
      InstructionBuilder getInstructionBuilder()
      Get instruction builder for modifying class.
      java.lang.String[] getInterfaces()
      Get names of all interfaces implemented by class.
      ClassItem getMethod​(java.lang.String name, java.lang.String sig)
      Get information for method without respect to potential trailing arguments or return value.
      ClassItem getMethod​(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.String getName()
      Get fully qualified class name.
      java.lang.String getPackage()
      Get package name.
      JavaClass getRawClass()
      Get raw current class information.
      java.io.File getRoot()
      Get root directory for load path.
      java.lang.String getSignature()
      Get signature for class as type.
      ClassItem getStaticMethod​(java.lang.String name, java.lang.String sig)
      Get information for static method without respect to return value.
      ClassFile getSuperFile()
      Get superclass information.
      java.lang.String getSuperName()
      Get superclass name.
      Type getType()
      Get class as type.
      int getUseCount()
      Get use count for class.
      int hashCode()
      Get hash code.
      int incrementUseCount()
      Increment use count for class.
      private void init​(java.lang.String name, java.lang.String path, java.io.InputStream ins)
      Internal initialization method.
      private void initInterface()
      Retrieve superinterfaces for an interface class.
      boolean isAbstract()
      Check if class is abstract.
      boolean isAccessible​(ClassItem item)
      Check accessible method.
      boolean isArray()
      Check if class is an array.
      private static boolean isAssignmentCompatible​(Type have, Type need)
      Check if one type is assignment compatible with another type.
      boolean isComplete()
      Check if class is in complete state.
      boolean isExtendable()
      Check if binding methods can be added to class.
      boolean isImplements​(java.lang.String sig)
      Check if class implements an interface.
      boolean isInterface()
      Check if class is an interface.
      boolean isModifiable()
      Check if class is modifiable.
      boolean isModified()
      Check if class has been modified.
      private static boolean isSuffixName​(java.lang.String name)
      Check if a method name matches the pattern for a generated unique suffix.
      boolean isSuperclass​(java.lang.String name)
      Check if another class is a superclass of this one.
      static java.lang.Class loadClass​(java.lang.String name)
      Try loading class from classpath.
      java.lang.String makeUniqueMethodName​(java.lang.String name)
      Make method name unique with generated suffix.
      private static boolean matchAccess​(FieldOrMethod item, int access)
      Check for match to specified access level.
      void removeMethod​(Method method)
      Remove method from class.
      void setModified()
      Set class modified flag.
      static void setPaths​(java.lang.String[] paths)
      Set class paths to be searched.
      void setSuperFile​(ClassFile sclas)
      Set superclass information.
      void setUnmodifiable()
      Force class to unmodifiable state.
      ClassItem updateField​(java.lang.String type, java.lang.String name, int access, java.lang.String init)
      Update class field with initial String value.
      void writeFile()
      Write out modified class information.
      void writeFile​(java.io.OutputStream os)
      Write out modified class information.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • JAVA7_MAJOR_VERSION

        private static final int JAVA7_MAJOR_VERSION
        Major version number for Java 7.
        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,
                         JiBXException
        Constructor for preexisting class file. Loads the class data and prepares it for use.
        Parameters:
        name - fully qualified class name
        root - directory root from class loading path list
        file - actual class file
        Throws:
        java.io.IOException - if unable to open file
        JiBXException - 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 name
        sig - corresponding class signature
      • ClassFile

        public ClassFile​(java.lang.String name,
                         java.io.File root,
                         ClassFile sclas,
                         int access,
                         java.lang.String[] impls)
                  throws JiBXException
        Constructor for new class file. Initializes the class data and prepares it for use.
        Parameters:
        name - fully qualified class name
        root - directory root from class loading path list
        sclas - superclass of new class
        access - access flags for class
        impls - 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.IOException
        Constructor 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 file
        JiBXException - 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 file
        JiBXException - 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 JiBXException
        Internal initialization method. This is used to handle common initialization for the constructors.
        Parameters:
        name - fully qualified class name
        path - class file path
        ins - input stream for class file data
        Throws:
        JiBXException - if unable to load class file
      • initInterface

        private void initInterface()
                            throws JiBXException
        Retrieve 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:
        true if an interface, false if not
      • isAbstract

        public boolean isAbstract()
        Check if class is abstract. This only checks existing classes, assuming that no generated classes are abstract.
        Returns:
        true if an abstract class, false if not
      • isArray

        public boolean isArray()
        Check if class is an array. This only checks existing classes, assuming that no generated classes are arrays.
        Returns:
        true if an array class, false if not
      • isModifiable

        public boolean isModifiable()
        Check if class is modifiable.
        Returns:
        true if class is modifiable, false if not
      • isExtendable

        public boolean isExtendable()
        Check if binding methods can be added to class.
        Returns:
        true if methods can be added, false if 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 (null if 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:
        true if added, false if already present
      • accumulateInterfaces

        protected void accumulateInterfaces​(java.lang.String[] intfs,
                                            java.util.HashMap map,
                                            java.util.ArrayList accs)
                                     throws JiBXException
        Accumulate interface signatures recursively.
        Parameters:
        intfs - names of interfaces implemented
        map - map for interfaces already accumulated
        accs - accumulated interface names
        Throws:
        JiBXException - if configuration error
      • getInstanceSigs

        public java.lang.String[] getInstanceSigs()
                                           throws JiBXException
        Get 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 JiBXException
        Check if class implements an interface.
        Parameters:
        sig - signature of interface to be checked
        Returns:
        true if interface is implemented by class, false if 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:
        true if named class is a superclass of this one, false if 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 null if 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 null if 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 null if 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 name
        sig - partial method signature to be matched
        Returns:
        method information, or null if 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 name
        sig - partial method signature to be matched
        Returns:
        method information, or null if 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 name
        sigs - possible signatures for method (including return type)
        Returns:
        method information, or null if 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 checked
        access - required access level for match
        Returns:
        true if access level match, false if 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 checked
        need - type needed
        Returns:
        true if compatible, false if 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 name
        access - access level required for matching methods
        ret - return value type (null if indeterminant)
        args - argument value types (null if indeterminant)
        Returns:
        method information, or null if 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 name
        ret - return value type (null if indeterminant)
        args - argument value types (null if indeterminant)
        Returns:
        method information, or null if 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 null if 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 name
        sig - encoded argument list signature
        Returns:
        method information, or null if 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 methods
        matches - 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:
        true if accessible, false if 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 initial String value. If a field with the same name already exists, it is overwritten.
        Parameters:
        type - fully qualified class name of field type
        name - field name
        access - access flags for field
        init - 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 initial int value. If a field with the same name already exists, it is overwritten.
        Parameters:
        type - fully qualified class name of field type
        name - field name
        access - access flags for field
        init - 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 initial String value. 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 type
        name - field name
        access - access flags for field
        init - 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 type
        name - field name
        access - 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 type
        name - 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:
        true if name matches suffix pattern, false if 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:
        true if field was present, false if not
      • deleteMethod

        public boolean deleteMethod​(java.lang.String name,
                                    java.lang.String sig)
        Delete method from class.
        Parameters:
        name - method name
        sig - method signature
        Returns:
        true if method was present, false if 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:
        true if class is modified, false if not
      • setModified

        public void setModified()
        Set class modified flag.
      • isComplete

        public boolean isComplete()
        Check if class is in complete state.
        Returns:
        true if class is complete, false if 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 modified codeComplete() 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 the codeComplete() method is called.
        Overrides:
        hashCode in class java.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 item
        b - second field or method item
        Returns:
        true if the equal, false if 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 method
        b - second method
        Returns:
        true if the equal, false if 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 the codeComplete() method is called.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj -
        Returns:
        true if equal objects, false if 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.IOException
        Write 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.IOException
        Write 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 prefix
        suffix - 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 null if not found
      • getClassLoader

        public static java.lang.ClassLoader getClassLoader()
        Get the classloader used for classes referenced in the binding.
        Returns:
        classloader