|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jibx.binding.classes.ClassFile
public class ClassFile
Class file information. Wraps the actual class file data as well as associated management information.
| Field Summary | |
|---|---|
protected static byte[] |
EMPTY_BYTES
|
static ClassItem[] |
EMPTY_CLASS_ITEMS
|
protected static ExistingMethod[] |
EMPTY_METHOD_ARRAY
|
protected InstructionBuilder |
m_instBuilder
Instruction factory for modified class (lazy create, only if needed). |
protected String[] |
m_interfaceNames
Names of all interfaces directly implemented by this class. |
protected ClassFile |
m_superClass
Super class of this class (set by caller, since it may require additional information to find the class file). |
static int |
PACKAGE_ACCESS
|
static int |
PRIVATE_ACCESS
|
protected static int |
PRIVATEFIELD_ACCESS
|
static int |
PROTECTED_ACCESS
|
static int |
PUBLIC_ACCESS
|
static int |
SYNTHETIC_ACCESS_FLAG
|
| Constructor Summary | |
|---|---|
ClassFile(String name,
File root,
ClassFile sclas,
int access,
String[] impls)
Constructor for new class file. |
|
ClassFile(String name,
File root,
File file)
Constructor for preexisting class file. |
|
ClassFile(String name,
String sig)
Constructor for synthetic placeholder classfile with no backing class data. |
|
| Method Summary | |
|---|---|
protected void |
accumulateInterfaces(String[] intfs,
HashMap map,
ArrayList accs)
Accumulate interface signatures recursively. |
ClassItem |
addDefaultConstructor()
Add default constructor to a class. |
ClassItem |
addField(String type,
String name,
int access)
Add field to class without initialization. |
ClassItem |
addField(String type,
String name,
int access,
int init)
Add field to class with initial int value. |
ClassItem |
addField(String type,
String name,
int access,
String init)
Add field to class with initial String value. |
boolean |
addInterface(String intf)
Add interface to class. |
ClassItem |
addMethod(org.apache.bcel.classfile.Method method)
Add method to class. |
ClassItem |
addPrivateField(String type,
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(String name)
Delete field from class. |
boolean |
deleteMethod(String name,
String sig)
Delete method from class. |
String |
deriveClassName(String prefix,
String suffix)
Derive generated class name. |
static boolean |
equalFieldOrMethods(org.apache.bcel.classfile.FieldOrMethod a,
org.apache.bcel.classfile.FieldOrMethod b)
Compare two field or method items to see if they're equal. |
static boolean |
equalMethods(org.apache.bcel.classfile.Method a,
org.apache.bcel.classfile.Method b)
Compare two methods to see if they're equal. |
boolean |
equals(Object obj)
Check if objects are equal. |
protected org.apache.bcel.classfile.Field |
getAccessibleField(String name)
Get internal information for field. |
protected org.apache.bcel.classfile.Method |
getAccessibleMethod(String name,
String sig)
Get internal information for method without respect to potential trailing arguments or return value. |
ClassItem |
getBestMethod(String name,
String ret,
String[] args)
Get information for best matching method. |
ExistingMethod[] |
getBindingMethods(String prefix,
String[] matches)
Get all binding methods currently defined in class. |
static ClassFile |
getClassFile(String name)
Constructor for preexisting class file from classpath. |
static ClassLoader |
getClassLoader()
Get the classloader used for classes referenced in the binding. |
org.apache.bcel.generic.ConstantPoolGen |
getConstPoolGen()
Get constant pool generator for modifying class. |
protected org.apache.bcel.classfile.Field |
getDefinedField(String name)
Get internal information for field. |
ClassItem |
getDirectField(String name)
Get information for field. |
ClassItem |
getField(String name)
Get information for field. |
ClassItem[] |
getFieldItems()
Get array of fields defined by class. |
File |
getFile()
Get actual file for class. |
ClassItem |
getInitializerMethod(String sig)
Get information for initializer. |
String[] |
getInstanceSigs()
Get signatures for all types of which instances of this type are instances. |
InstructionBuilder |
getInstructionBuilder()
Get instruction builder for modifying class. |
String[] |
getInterfaces()
Get names of all interfaces implemented by class. |
ClassItem |
getMethod(String name,
String sig)
Get information for method without respect to potential trailing arguments or return value. |
ClassItem |
getMethod(String name,
String[] sigs)
Get information for method matching one of several possible signatures. |
ClassItem[] |
getMethodItems()
Get array of methods defined by class. |
String |
getName()
Get fully qualified class name. |
String |
getPackage()
Get package name. |
org.apache.bcel.classfile.JavaClass |
getRawClass()
Get raw current class information. |
File |
getRoot()
Get root directory for load path. |
String |
getSignature()
Get signature for class as type. |
ClassItem |
getStaticMethod(String name,
String sig)
Get information for static method without respect to return value. |
ClassFile |
getSuperFile()
Get superclass information. |
String |
getSuperName()
Get superclass name. |
org.apache.bcel.generic.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. |
boolean |
isAbstract()
Check if class is abstract. |
boolean |
isAccessible(ClassItem item)
Check accessible method. |
boolean |
isArray()
Check if class is an array. |
boolean |
isComplete()
Check if class is in complete state. |
boolean |
isImplements(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. |
boolean |
isSuperclass(String name)
Check if another class is a superclass of this one. |
static Class |
loadClass(String name)
Try loading class from classpath. |
String |
makeUniqueMethodName(String name)
Make method name unique with generated suffix. |
void |
removeMethod(org.apache.bcel.classfile.Method method)
Remove method from class. |
void |
setModified()
Set class modified flag. |
static void |
setPaths(String[] paths)
Set class paths to be searched. |
void |
setSuperFile(ClassFile sclas)
Set superclass information. |
void |
setUnmodifiable()
Force class to unmodifiable state. |
ClassItem |
updateField(String type,
String name,
int access,
String init)
Update class field with initial String value. |
void |
writeFile()
Write out modified class information. |
void |
writeFile(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 |
|---|
public static final int PRIVATE_ACCESS
public static final int PACKAGE_ACCESS
public static final int PROTECTED_ACCESS
public static final int PUBLIC_ACCESS
public static final int SYNTHETIC_ACCESS_FLAG
protected static final int PRIVATEFIELD_ACCESS
protected static final ExistingMethod[] EMPTY_METHOD_ARRAY
protected static final byte[] EMPTY_BYTES
public static final ClassItem[] EMPTY_CLASS_ITEMS
protected ClassFile m_superClass
protected String[] m_interfaceNames
protected InstructionBuilder m_instBuilder
| Constructor Detail |
|---|
public ClassFile(String name,
File root,
File file)
throws IOException,
JiBXException
name - fully qualified class nameroot - directory root from class loading path listfile - actual class file
IOException - if unable to open file
JiBXException - if error in reading class file
public ClassFile(String name,
String sig)
name - fully qualified class namesig - corresponding class signature
public ClassFile(String name,
File root,
ClassFile sclas,
int access,
String[] impls)
throws JiBXException
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)
JiBXException - on error loading interface information| Method Detail |
|---|
public static ClassFile getClassFile(String name)
throws IOException,
JiBXException
name - fully qualified class name
IOException - if error reading file
JiBXException - if error loading superclass or other support filepublic boolean isInterface()
true if an interface, false if notpublic boolean isAbstract()
true if an abstract class, false if notpublic boolean isArray()
true if an array class, false if notpublic boolean isModifiable()
true if class is modifiable, false if
notpublic String getName()
public String getSignature()
public org.apache.bcel.generic.Type getType()
public String getPackage()
public File getRoot()
public File getFile()
public org.apache.bcel.classfile.JavaClass getRawClass()
public String getSuperName()
public void setSuperFile(ClassFile sclas)
sclas - superclass informationpublic ClassFile getSuperFile()
null if no
superclass - java.lang.Object, interface, or primitive)public String[] getInterfaces()
null, empty array if none)public boolean addInterface(String intf)
intf - fully qualified interface name
true if added, false if already present
protected void accumulateInterfaces(String[] intfs,
HashMap map,
ArrayList accs)
throws JiBXException
intfs - names of interfaces implementedmap - map for interfaces already accumulatedaccs - accumulated interface names
JiBXException - if configuration error
public String[] getInstanceSigs()
throws JiBXException
JiBXException - if configuration error
public boolean isImplements(String sig)
throws JiBXException
sig - signature of interface to be checked
true if interface is implemented by class,
false if not
JiBXException - if configuration errorpublic boolean isSuperclass(String name)
name - of superclass to be checked
true if named class is a superclass of this one,
false if notpublic ClassItem[] getFieldItems()
protected org.apache.bcel.classfile.Field getDefinedField(String name)
name - field name
null if field not foundprotected org.apache.bcel.classfile.Field getAccessibleField(String name)
name - field name
null if field not foundpublic ClassItem getDirectField(String name)
name - field name
null if field not found
public ClassItem getField(String name)
throws JiBXException
name - field name
JiBXException - if field not foundpublic ClassItem[] getMethodItems()
protected org.apache.bcel.classfile.Method getAccessibleMethod(String name,
String sig)
name - method namesig - partial method signature to be matched
null if method not found
public ClassItem getMethod(String name,
String sig)
name - method namesig - partial method signature to be matched
null if method not found
public ClassItem getMethod(String name,
String[] sigs)
name - method namesigs - possible signatures for method (including return type)
null if method not found
public ClassItem getBestMethod(String name,
String ret,
String[] args)
name - method nameret - return value type (null if indeterminant)args - argument value types (null if indeterminant)
null if method not foundpublic ClassItem getInitializerMethod(String sig)
sig - encoded argument list signature
null if method not found
public ClassItem getStaticMethod(String name,
String sig)
name - method namesig - encoded argument list signature
null if method not found
public ExistingMethod[] getBindingMethods(String prefix,
String[] matches)
prefix - identifying prefix for binding methodsmatches - pairs of method name and signature to be matched as
exceptions to the prefix matching
public boolean isAccessible(ClassItem item)
item - field or method information
true if accessible, false if notpublic org.apache.bcel.generic.ConstantPoolGen getConstPoolGen()
public InstructionBuilder getInstructionBuilder()
public ClassItem addMethod(org.apache.bcel.classfile.Method method)
method - method to be added
public void removeMethod(org.apache.bcel.classfile.Method method)
method - method to be removed
public ClassItem addField(String type,
String name,
int access,
String init)
String value. If a field
with the same name already exists, it is overwritten.
type - fully qualified class name of field typename - field nameaccess - access flags for fieldinit - initial value for field
public ClassItem addField(String type,
String name,
int access,
int init)
int value. If a field with
the same name already exists, it is overwritten.
type - fully qualified class name of field typename - field nameaccess - access flags for fieldinit - initial value for field
public ClassItem updateField(String type,
String name,
int access,
String init)
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.
type - fully qualified class name of field typename - field nameaccess - access flags for fieldinit - initial value for field
public ClassItem addField(String type,
String name,
int access)
type - fully qualified class name of field typename - field nameaccess - access flags for field
public ClassItem addPrivateField(String type,
String name)
type - fully qualified class name of field typename - field name
public ClassItem addDefaultConstructor()
public String makeUniqueMethodName(String name)
name - base name before suffix is appended
public boolean deleteField(String name)
name - field name
true if field was present, false if not
public boolean deleteMethod(String name,
String sig)
name - method namesig - method signature
true if method was present, false if notpublic int getUseCount()
public int incrementUseCount()
public void setUnmodifiable()
public boolean isModified()
true if class is modified, false if notpublic void setModified()
public boolean isComplete()
true if class is complete, false if notprotected int computeHashCode()
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.
public void codeComplete()
public int hashCode()
codeComplete() method is called.
hashCode in class Object
public static boolean equalFieldOrMethods(org.apache.bcel.classfile.FieldOrMethod a,
org.apache.bcel.classfile.FieldOrMethod b)
a - first field or method itemb - second field or method item
true if the equal, false if not
public static boolean equalMethods(org.apache.bcel.classfile.Method a,
org.apache.bcel.classfile.Method b)
a - first methodb - second method
true if the equal, false if notpublic boolean equals(Object obj)
codeComplete() method is called.
equals in class Objectobj -
true if equal objects, false if notpublic void delete()
public void writeFile(OutputStream os)
throws IOException
os - output stream for writing modified class
IOException - if error writing to file
public void writeFile()
throws IOException
IOException - if error writing to file
public String deriveClassName(String prefix,
String suffix)
prefix - generated class name prefixsuffix - generated class name suffix
public static void setPaths(String[] paths)
paths - ordered set of paths to be searched for class filespublic static Class loadClass(String name)
name - fully qualified name of class to be loaded
null if not foundpublic static ClassLoader getClassLoader()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||