| java.lang.Object org.apache.harmony.misc.accessors.ObjectAccessor
ObjectAccessor | public class ObjectAccessor (Code) | | Provides the direct access to classes and objects. This class allows to overcome
the certain limitations of the reflection API, such as setting the constant fields or
allocating objects without calling its constructor. The following groups of operations
are supported:
- getField/MethodID,getStaticField/MethodID - used to get ID for methods and fields.
- getXXX/setXXX - used to read and write non-static fields in objects
(XXX stands for a field type);
- getStaticXXX/setStaticXXX - used to read and write static fields in classes
(XXX stands for a field type);
- invokeStaticXXX - used to call static methods in a class (XXX means return type);
- invokeVirtualXXX - used to call virtual methods for object (XXX means return type);
- invokeNonVirtualXXX - used to call non-virtual methods for
the given class and object (XXX means return type);
- allocateObject, newInstance - provides a fine control over object
construction;
- hasStaticInitializer - informational methods about class;
- monitorEnter/Exit - enter/exit monitor associated with the given object
Fields and methods are identified in the class with help of ID's those actual meaning
is implementation dependent.
Depending on a platform, ID's may represent the real offets in the physical memory,
though it is not always guaranteed. Unlike the
ArrayAccessor class, users should not rely on
any correspondence between ID's and memory address space. However, it is guaranteed that ID's, once
obtained, are valid during the whole lifetime of the given class and can equally be
applied for all its instances.
No security checks are made while reading and writing object's fields, as well as while calling object's methods. In addition to
variables, this class also allows to set the values for constant fields within an object.
For accessing Array objects, please use the
ArrayAccessor class.
See Also: ArrayAccessor |
Method Summary | |
final native public Object | allocateObject(Class c) Allocates new object of the given class without calling its constructor.
Constructor can be called independently with help of
ObjectAccessor.invokeNonVirtualVoid(Class,Object,long,Object[]) method.
Parameters: c - A class those object needs to be allocated. | final native public boolean | getBoolean(Object o, long fieldID) Reads a boolean field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public byte | getByte(Object o, long fieldID) Reads a byte field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public char | getChar(Object o, long fieldID) Reads a char field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public double | getDouble(Object o, long fieldID) Reads a double field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final public long | getFieldID(Class c, String name) Returns the ID for a field with the given name. | final public long | getFieldID(Class c, String name, Class type) Returns the ID for a field with the given name and type. | final native public long | getFieldID(Field f) Returns the ID for the reflected field. | final native public float | getFloat(Object o, long fieldID) Reads a float field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public long | getGlobalReference(Object o) | static ObjectAccessor | getInstance() | final native public int | getInt(Object o, long fieldID) Reads a int field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public long | getLong(Object o, long fieldID) Reads a long field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final public long | getMethodID(Class c, String name, Class[] parameterTypes) Returns the ID for the specified method or constructor.
Use class constants for primitive parameter types. | final public long | getMethodID(Constructor c) Returns the ID for the reflected constructor. | final public long | getMethodID(Method m) Returns the ID for the reflected method. | final native public Object | getObject(Object o, long fieldID) Reads an Object field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public Object | getObjectFromReference(long ref) | final native public short | getShort(Object o, long fieldID) Reads a short field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public boolean | getStaticBoolean(Class c, long fieldID) Reads a boolean field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final native public byte | getStaticByte(Class c, long fieldID) Reads a byte field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final native public char | getStaticChar(Class c, long fieldID) Reads a char field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final native public double | getStaticDouble(Class c, long fieldID) Reads a double field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final public long | getStaticFieldID(Class c, String name) Returns the ID for the static field with the given name. | final public long | getStaticFieldID(Class c, String name, Class type) Returns the ID for the static field with the given name and type. | final public long | getStaticFieldID(Field f) Returns the ID for the reflected static field. | final native public float | getStaticFloat(Class c, long fieldID) Reads a float field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final native public int | getStaticInt(Class c, long fieldID) Reads a int field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final native public long | getStaticLong(Class c, long fieldID) Reads a long field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final public long | getStaticMethodID(Class c, String name, Class[] parameterTypes) Returns the ID for the specified static method.
Use class constants for primitive parameter types. | final native public Object | getStaticObject(Class c, long fieldID) Reads an Object field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final native public short | getStaticShort(Class c, long fieldID) Reads a short field for the given class.
Use the
ObjectAccessor.getStaticFieldID(Class,String) method to obtain the ID for the specific field
within a class.
Parameters: c - class those field needs to be read Parameters: fieldID - field ID. | final native public boolean | hasStaticInitializer(Class c) Determines whether the class c has static initializer. | final native public long | invokeNonVirtualLong(Class c, Object obj, long methodID, Object[] args) Invokes a non-virtual long method with the given ID without security check. | final native public Object | invokeNonVirtualObject(Class c, Object obj, long methodID, Object[] args) Invokes a non-virtual reference-type method with the given ID without security check. | final native public void | invokeNonVirtualVoid(Class c, Object obj, long methodID, Object[] args) Invokes a non-virtual void method or constructor with the given ID without security check. | final native public long | invokeStaticLong(Class c, long methodID, Object[] args) Invokes a static long method with the given ID without security check. | final native public Object | invokeStaticObject(Class c, long methodID, Object[] args) Invokes a static reference-type method with the given ID without security check. | final native public void | invokeStaticVoid(Class c, long methodID, Object[] args) Invokes static void method with the given ID without security check. | final native public long | invokeVirtualLong(Object obj, long methodID, Object[] args) Invokes long method with the given ID without security check. | final native public Object | invokeVirtualObject(Object obj, long methodID, Object[] args) Invokes reference-type method with the given ID without security check. | final native public void | invokeVirtualVoid(Object obj, long methodID, Object[] args) Invokes void method or constructor with the given ID without security check. | native public void | monitorEnter(Object o) calls monitorEnter java bytecode command. | native public void | monitorExit(Object o) calls monitorExit java bytecode command. | final native public Object | newInstance(Class c, long methodID, Object[] args) Allocates new object of class c and invokes its constructor with the given ID
and args without security checks. | final native public Object | newInstance(Class c) Allocates new object of a class c and invokes noarg constructor without security check. | final native public void | releaseGlobalReference(long ref) | final native public void | setBoolean(Object o, long fieldID, boolean value) Writes a boolean field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setByte(Object o, long fieldID, byte value) Writes a byte field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setChar(Object o, long fieldID, char value) Writes a char field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setDouble(Object o, long fieldID, double value) Writes a double field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setFloat(Object o, long fieldID, float value) Writes a float field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setInt(Object o, long fieldID, int value) Writes a int field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setLong(Object o, long fieldID, long value) Writes a long field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setObject(Object o, long fieldID, Object value) Writes an Object field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setShort(Object o, long fieldID, short value) Writes a short field for the given object.
Use the
ObjectAccessor.getFieldID(Field) method to obtain the ID for the specific field
within a class. | final native public void | setStaticBoolean(Class c, long fieldID, boolean value) Writes a boolean field for the given class. | final native public void | setStaticByte(Class c, long fieldID, byte value) Writes a byte field for the given class. | final native public void | setStaticChar(Class c, long fieldID, char value) Writes a char field for the given class. | final native public void | setStaticDouble(Class c, long fieldID, double value) Writes a double field for the given class. | final native public void | setStaticFloat(Class c, long fieldID, float value) Writes a float field for the given class. | final native public void | setStaticInt(Class c, long fieldID, int value) Writes a int field for the given class. | final native public void | setStaticLong(Class c, long fieldID, long value) Writes a long field for the given class. | final native public void | setStaticObject(Class c, long fieldID, Object value) Writes an Object field for the given class. | final native public void | setStaticShort(Class c, long fieldID, short value) Writes a short field for the given class. |
getFieldID | final public long getFieldID(Class c, String name, Class type)(Code) | | Returns the ID for a field with the given name and type.
This may be faster than getting the field using it's name only.
For static fields, use the
ObjectAccessor.getStaticFieldID(Class,String) method.
Parameters: c - class containing field Parameters: name - field name Parameters: type - field type field ID throws: NoSuchFieldError - if the field could not be found |
getFieldID | final native public long getFieldID(Field f)(Code) | | Returns the ID for the reflected field.
Parameters: f - reflected field field ID |
getGlobalReference | final native public long getGlobalReference(Object o)(Code) | | |
getMethodID | final public long getMethodID(Class c, String name, Class[] parameterTypes)(Code) | | Returns the ID for the specified method or constructor.
Use class constants for primitive parameter types. For example,
for byte type use the
java.lang.Byte.TYPE class.
Parameters: c - a class the method belongs to Parameters: name - method name or null in case of constructor Parameters: parameterTypes - array of parameter types. method ID throws: NoSuchMethodError - if the method could not be found See Also: ObjectAccessor.invokeVirtualVoid(Object,long,Object[]) See Also: ObjectAccessor.invokeNonVirtualVoid(Class,Object,long,Object[]) See Also: ObjectAccessor.newInstance(Class,long,Object[]) |
getObjectFromReference | final native public Object getObjectFromReference(long ref)(Code) | | |
getStaticFieldID | final public long getStaticFieldID(Class c, String name)(Code) | | Returns the ID for the static field with the given name.
Parameters: c - class containing static field Parameters: name - field name field ID throws: NoSuchFieldError - if the field could not be found |
getStaticFieldID | final public long getStaticFieldID(Class c, String name, Class type)(Code) | | Returns the ID for the static field with the given name and type.
This may be faster than getting the field using it's name only.
Parameters: c - class containing static field Parameters: name - field name Parameters: type - field type field ID throws: NoSuchFieldError - if the field could not be found |
getStaticFieldID | final public long getStaticFieldID(Field f)(Code) | | Returns the ID for the reflected static field.
Default implementation delegates to the
ObjectAccessor.getFieldID(Field) call.
Parameters: f - reflected field field ID |
getStaticMethodID | final public long getStaticMethodID(Class c, String name, Class[] parameterTypes)(Code) | | Returns the ID for the specified static method.
Use class constants for primitive parameter types. For example,
for byte type use the
java.lang.Byte.TYPE class.
Parameters: c - a class the method belongs to Parameters: name - method name or null in case of constructor Parameters: parameterTypes - array of parameter types. static method ID throws: NoSuchMethodError - if the method could not be found See Also: ObjectAccessor.invokeVirtualVoid(Object,long,Object[]) |
hasStaticInitializer | final native public boolean hasStaticInitializer(Class c)(Code) | | Determines whether the class c has static initializer.
true if class c has static initializer, false otherwise |
invokeNonVirtualVoid | final native public void invokeNonVirtualVoid(Class c, Object obj, long methodID, Object[] args)(Code) | | Invokes a non-virtual void method or constructor with the given ID without security check.
Primitive type arguments should be wrapped with appropriate objects.
For example, byte value should be wrapped with
java.lang.Byte.TYPE .
Use the
ObjectAccessor.getMethodID(Class,String,Class[]) call to obtain the method ID.
Parameters: c - a class where method or constructor is defined Parameters: obj - an object those method or constructor needs to be called Parameters: methodID - method ID Parameters: args - array of arguments See Also: ObjectAccessor.getMethodID(Class,String,Class[]) |
monitorEnter | native public void monitorEnter(Object o)(Code) | | calls monitorEnter java bytecode command. Acquire object o monitor
Parameters: o - object to lock |
monitorExit | native public void monitorExit(Object o)(Code) | | calls monitorExit java bytecode command. To free object o monitor
Parameters: o - object to unlock |
newInstance | final native public Object newInstance(Class c, long methodID, Object[] args)(Code) | | Allocates new object of class c and invokes its constructor with the given ID
and args without security checks.
Primitive type arguments should be wrapped with appropriate objects.
For example, byte value should be wrapped with
java.lang.Byte.TYPE .
Use the
ObjectAccessor.getMethodID(Class,String,Class[]) call to obtain the constructor ID.
Parameters: methodID - method ID Parameters: c - class those instance needs to be created Parameters: args - array of arguments allocated object |
newInstance | final native public Object newInstance(Class c)(Code) | | Allocates new object of a class c and invokes noarg constructor without security check.
Parameters: c - class those object needs to be created allocated object |
releaseGlobalReference | final native public void releaseGlobalReference(long ref)(Code) | | |
|
|