| java.lang.Object org.jibx.binding.classes.ClassFile
ClassFile | public class ClassFile (Code) | | Class file information. Wraps the actual class file data as well as
associated management information.
author: Dennis M. Sosnoski version: 1.0 |
Method Summary | |
protected void | accumulateInterfaces(String[] intfs, HashMap map, ArrayList accs) Accumulate interface signatures recursively. | public ClassItem | addDefaultConstructor() Add default constructor to a class. | public ClassItem | addField(String type, String name, int access, String init) Add field to class with initial String value. | public ClassItem | addField(String type, String name, int access) Add field to class without initialization. | public boolean | addInterface(String intf) Add interface to class. | public ClassItem | addMethod(Method method) Add method to class. | public ClassItem | addPrivateField(String type, String name) Add private field to class without initialization. | public void | codeComplete() Finalize current modified state of class. | protected int | computeHashCode() Computes a hash code based on characteristics of the class. | public void | delete() Delete class file information. | public boolean | deleteField(String name) Delete field from class. | public String | deriveClassName(String prefix, String suffix) Derive generated class name. | public static boolean | equalFieldOrMethods(FieldOrMethod a, FieldOrMethod b) Compare two field or method items to see if they're equal. | public static boolean | equalMethods(Method a, Method b) Compare two methods to see if they're equal. | public boolean | equals(Object obj) Check if objects are equal. | protected Field | getAccessibleField(String name) Get internal information for field. | protected Method | getAccessibleMethod(String name, String sig) Get internal information for method without respect to potential trailing
arguments or return value. | public ClassItem | getBestMethod(String name, String ret, String[] args) Get information for best matching method. | public ExistingMethod[] | getBindingMethods(String prefix, String[] matches) Get all binding methods currently defined in class. | public ConstantPoolGen | getConstPoolGen() Get constant pool generator for modifying class. | protected Field | getDefinedField(String name) Get internal information for field. | public ClassItem | getDirectField(String name) Get information for field. | public ClassItem | getField(String name) Get information for field. | public ClassItem[] | getFieldItems() Get array of fields defined by class. | public File | getFile() Get actual file for class. | public ClassItem | getInitializerMethod(String sig) Get information for initializer. | public String[] | getInstanceSigs() Get signatures for all types of which instances of this type are
instances. | public InstructionBuilder | getInstructionBuilder() Get instruction builder for modifying class. | public String[] | getInterfaces() Get names of all interfaces implemented by class. | public ClassItem | getMethod(String name, String sig) Get information for method without respect to potential trailing
arguments or return value. | public ClassItem | getMethod(String name, String[] sigs) Get information for method matching one of several possible signatures.
This can only be used with existing classes. | public ClassItem[] | getMethodItems() Get array of methods defined by class. | public String | getName() Get fully qualified class name. | public String | getPackage() Get package name. | public JavaClass | getRawClass() Get raw current class information. | public File | getRoot() Get root directory for load path. | public String | getSignature() Get signature for class as type. | public ClassItem | getStaticMethod(String name, String sig) Get information for static method without respect to return value. | public ClassFile | getSuperFile() Get superclass information. | public String | getSuperName() Get superclass name. | public Type | getType() Get class as type. | public int | getUseCount() Get use count for class. | public int | hashCode() Get hash code. | public int | incrementUseCount() Increment use count for class. | public boolean | isAbstract() Check if class is abstract. | public boolean | isAccessible(ClassItem item) Check accessible method. | public boolean | isArray() Check if class is an array. | public boolean | isComplete() Check if class is in complete state. | public boolean | isImplements(String sig) Check if class implements an interface. | public boolean | isInterface() Check if class is an interface. | public boolean | isModifiable() Check if class is modifiable. | public boolean | isModified() Check if class has been modified. | public boolean | isSuperclass(String name) Check if another class is a superclass of this one. | public static Class | loadClass(String name) Try loading class from classpath. | public String | makeUniqueMethodName(String name) Make method name unique with generated suffix. | public void | removeMethod(Method method) Remove method from class. | public void | setModified() Set class modified flag. | public static void | setPaths(String[] paths) Set class paths to be searched. | public void | setSuperFile(ClassFile sclas) Set superclass information. | public ClassItem | updateField(String type, String name, int access, String init) Update class field with initial String value. | public void | writeFile(OutputStream os) Write out modified class information. | public void | writeFile() Write out modified class information. |
EMPTY_BYTES | final protected static byte[] EMPTY_BYTES(Code) | | |
PACKAGE_ACCESS | final public static int PACKAGE_ACCESS(Code) | | |
PRIVATEFIELD_ACCESS | final protected static int PRIVATEFIELD_ACCESS(Code) | | |
PRIVATE_ACCESS | final public static int PRIVATE_ACCESS(Code) | | |
PROTECTED_ACCESS | final public static int PROTECTED_ACCESS(Code) | | |
PUBLIC_ACCESS | final public static int PUBLIC_ACCESS(Code) | | |
SYNTHETIC_ACCESS_FLAG | final public static int SYNTHETIC_ACCESS_FLAG(Code) | | |
m_instBuilder | protected InstructionBuilder m_instBuilder(Code) | | Instruction factory for modified class (lazy create, only if needed).
|
m_interfaceNames | protected String[] m_interfaceNames(Code) | | Names of all interfaces directly implemented by this class.
|
m_superClass | protected ClassFile m_superClass(Code) | | Super class of this class (set by caller, since it may require
additional information to find the class file).
|
ClassFile | public ClassFile(String name, String path, InputStream ins) throws JiBXException(Code) | | Constructor for class file loaded from a stream. Loads the class data
and prepares it for use.
Parameters: name - fully qualified class name Parameters: path - class file path Parameters: ins - input stream for class file data throws: JiBXException - if unable to load class file |
ClassFile | public ClassFile(String name, File root, File file) throws IOException, JiBXException(Code) | | Constructor for preexisting class file. Loads the class data and
prepares it for use.
Parameters: name - fully qualified class name Parameters: root - directory root from class loading path list Parameters: file - actual class file throws: IOException - if unable to open file throws: JiBXException - if error in reading class file |
ClassFile | public ClassFile(String name) throws IOException, JiBXException(Code) | | Constructor for preexisting class file from classpath. Loads the class
data and prepares it for use.
Parameters: name - fully qualified class name throws: IOException - if unable to open file throws: JiBXException - if error in reading class file |
ClassFile | public ClassFile(String name, String sig)(Code) | | Constructor for synthetic placeholder classfile with no backing class
data.
Parameters: name - fully qualified class name Parameters: sig - corresponding class signature |
ClassFile | public ClassFile(String name, File root, ClassFile sclas, int access, String[] impls) throws JiBXException(Code) | | Constructor for new class file. Initializes the class data and
prepares it for use.
Parameters: name - fully qualified class name Parameters: root - directory root from class loading path list Parameters: sclas - superclass of new class Parameters: access - access flags for class Parameters: impls - array of interfaces implemented by new class throws: JiBXException - on error loading interface information |
accumulateInterfaces | protected void accumulateInterfaces(String[] intfs, HashMap map, ArrayList accs) throws JiBXException(Code) | | Accumulate interface signatures recursively.
Parameters: intfs - names of interfaces implemented Parameters: map - map for interfaces already accumulated Parameters: accs - accumulated interface names throws: JiBXException - if configuration error |
addDefaultConstructor | public ClassItem addDefaultConstructor() throws JiBXException(Code) | | 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.
constructor information throws: JiBXException - if unable to add constructor |
addField | public ClassItem addField(String type, String name, int access, String init) throws JiBXException(Code) | | 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 Parameters: name - field name Parameters: access - access flags for field Parameters: init - initial value for field field information throws: JiBXException - if unable to add field |
addField | public ClassItem addField(String type, String name, int access) throws JiBXException(Code) | | 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 Parameters: name - field name Parameters: access - access flags for field field information throws: JiBXException - if unable to add field |
addInterface | public boolean addInterface(String intf) throws JiBXException(Code) | | Add interface to class. The interface is added to the class if not
already defined.
Parameters: intf - fully qualified interface name true if added, false if already present throws: JiBXException - on configuration error |
addMethod | public ClassItem addMethod(Method method) throws JiBXException(Code) | | Add method to class.
Parameters: method - method to be added added method information throws: JiBXException - on error in adding method |
addPrivateField | public ClassItem addPrivateField(String type, String name) throws JiBXException(Code) | | 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 Parameters: name - field name field information throws: JiBXException - if unable to add field |
codeComplete | public void codeComplete()(Code) | | 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.
|
computeHashCode | protected int computeHashCode()(Code) | | 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
ClassFile.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.
computed hash code value |
delete | public void delete()(Code) | | Delete class file information. Deletes the class file for this class,
if it exists. Does nothing if no class file has been generated.
|
deleteField | public boolean deleteField(String name) throws JiBXException(Code) | | Delete field from class.
Parameters: name - field name true if field was present, false if not throws: JiBXException - if unable to delete field |
deriveClassName | public String deriveClassName(String prefix, String suffix)(Code) | | 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 Parameters: suffix - generated class name suffix derived class name |
equalFieldOrMethods | public static boolean equalFieldOrMethods(FieldOrMethod a, FieldOrMethod b)(Code) | | 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 Parameters: b - second field or method item true if the equal, false if not |
equalMethods | public static boolean equalMethods(Method a, Method b)(Code) | | 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 Parameters: b - second method true if the equal, false if not |
equals | public boolean equals(Object obj)(Code) | | 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
ClassFile.codeComplete method is called.
true if equal objects, false if not |
getAccessibleField | protected Field getAccessibleField(String name)(Code) | | 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 field information, or null if field not found |
getAccessibleMethod | protected Method getAccessibleMethod(String name, String sig)(Code) | | 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 Parameters: sig - partial method signature to be matched method information, or null if method not found |
getBestMethod | public ClassItem getBestMethod(String name, String ret, String[] args)(Code) | | 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 Parameters: ret - return value type (null if indeterminant) Parameters: args - argument value types method information, or null if method not found |
getBindingMethods | public ExistingMethod[] getBindingMethods(String prefix, String[] matches)(Code) | | 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 Parameters: matches - pairs of method name and signature to be matched asexceptions to the prefix matching existing binding methods |
getConstPoolGen | public ConstantPoolGen getConstPoolGen() throws JiBXException(Code) | | Get constant pool generator for modifying class.
constant pool generator for class throws: JiBXException - if class not modifiable |
getDefinedField | protected Field getDefinedField(String name)(Code) | | 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 field information, or null if field not found |
getDirectField | public ClassItem getDirectField(String name)(Code) | | 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 field information, or null if field not found |
getField | public ClassItem getField(String name) throws JiBXException(Code) | | 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 field information throws: JiBXException - if field not found |
getFieldItems | public ClassItem[] getFieldItems()(Code) | | Get array of fields defined by class.
array of fields defined by class |
getFile | public File getFile()(Code) | | Get actual file for class.
file used for class |
getInitializerMethod | public ClassItem getInitializerMethod(String sig)(Code) | | 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 method information, or null if method not found |
getInstanceSigs | public String[] getInstanceSigs() throws JiBXException(Code) | | Get signatures for all types of which instances of this type are
instances.
all signatures suppored by instances throws: JiBXException - if configuration error |
getInterfaces | public String[] getInterfaces()(Code) | | Get names of all interfaces implemented by class.
names of all interfaces implemented directly by class |
getMethod | public ClassItem getMethod(String name, String sig)(Code) | | 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 Parameters: sig - partial method signature to be matched method information, or null if method not found |
getMethod | public ClassItem getMethod(String name, String[] sigs)(Code) | | 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 Parameters: sigs - possible signatures for method (including return type) method information, or null if method not found |
getMethodItems | public ClassItem[] getMethodItems()(Code) | | Get array of methods defined by class.
array of methods defined by class |
getName | public String getName()(Code) | | Get fully qualified class name.
fully qualified name for class |
getPackage | public String getPackage()(Code) | | Get package name.
package name for class |
getRawClass | public JavaClass getRawClass()(Code) | | Get raw current class information.
raw current class information |
getRoot | public File getRoot()(Code) | | Get root directory for load path.
root directory in path used for loading file |
getSignature | public String getSignature()(Code) | | Get signature for class as type.
signature for class used as type |
getStaticMethod | public ClassItem getStaticMethod(String name, String sig)(Code) | | 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 Parameters: sig - encoded argument list signature method information, or null if method not found |
getSuperFile | public ClassFile getSuperFile()(Code) | | Get superclass information.
super class information as loaded (null if nosuperclass - java.lang.Object, interface, or primitive) |
getSuperName | public String getSuperName()(Code) | | Get superclass name.
fully qualified name of superclass |
getType | public Type getType()(Code) | | Get class as type.
class as type |
getUseCount | public int getUseCount()(Code) | | Get use count for class.
use count for this class |
hashCode | public int hashCode()(Code) | | 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
ClassFile.codeComplete method is called.
hash code based on code sequence |
incrementUseCount | public int incrementUseCount()(Code) | | Increment use count for class.
use count (after increment) |
isAbstract | public boolean isAbstract()(Code) | | Check if class is abstract. This only checks existing classes,
assuming that no generated classes are abstract.
true if an abstract class, false if not |
isAccessible | public boolean isAccessible(ClassItem item)(Code) | | Check accessible method. Check if a field or method in another class is
accessible from within this class.
Parameters: item - field or method information true if accessible, false if not |
isArray | public boolean isArray()(Code) | | Check if class is an array. This only checks existing classes,
assuming that no generated classes are arrays.
true if an array class, false if not |
isComplete | public boolean isComplete()(Code) | | Check if class is in complete state.
true if class is complete, false if not |
isImplements | public boolean isImplements(String sig) throws JiBXException(Code) | | Check if class implements an interface.
Parameters: sig - signature of interface to be checked true if interface is implemented by class,false if not throws: JiBXException - if configuration error |
isInterface | public boolean isInterface()(Code) | | Check if class is an interface. This only checks existing classes,
assuming that no generated classes are interfaces.
true if an interface, false if not |
isModifiable | public boolean isModifiable()(Code) | | Check if class is modifiable.
true if class is modifiable, false ifnot |
isModified | public boolean isModified()(Code) | | Check if class has been modified.
true if class is modified, false if not |
isSuperclass | public boolean isSuperclass(String name)(Code) | | Check if another class is a superclass of this one.
Parameters: name - of superclass to be checked true if named class is a superclass of this one,false if not |
loadClass | public static Class loadClass(String name)(Code) | | Try loading class from classpath.
Parameters: name - fully qualified name of class to be loaded loaded class, or null if not found |
makeUniqueMethodName | public String makeUniqueMethodName(String name)(Code) | | 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 name with unique suffix appended |
removeMethod | public void removeMethod(Method method) throws JiBXException(Code) | | Remove method from class.
Parameters: method - method to be removed throws: JiBXException - on error in removing method |
setModified | public void setModified()(Code) | | Set class modified flag.
|
setPaths | public static void setPaths(String[] paths)(Code) | | Set class paths to be searched.
Parameters: paths - ordered set of paths to be searched for class files |
setSuperFile | public void setSuperFile(ClassFile sclas)(Code) | | Set superclass information.
Parameters: sclas - superclass information |
updateField | public ClassItem updateField(String type, String name, int access, String init) throws JiBXException(Code) | | 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 Parameters: name - field name Parameters: access - access flags for field Parameters: init - initial value for field field information throws: JiBXException - if unable to add field |
writeFile | public void writeFile(OutputStream os) throws IOException(Code) | | Write out modified class information. Writes the modified class file to
an output stream.
Parameters: os - output stream for writing modified class throws: IOException - if error writing to file |
writeFile | public void writeFile() throws IOException(Code) | | 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: IOException - if error writing to file |
|
|