public final class JCObject extends JCHandler implements Iterable<JCObject>, Cloneable
JCObject holds a native reference to a live CLR object and exposes
methods to invoke instance and type-level members, get and set properties and fields,
and register or unregister CLR event handlers. All member accesses cross the JNI
boundary and are executed within the CLR context.
Return values from member invocations follow a fixed mapping rule: CLR primitive
types (bool, int, float, String, etc.) are returned
as their Java equivalents, while all other CLR types are returned as a new
JCObject.
JCObject instances must not be constructed directly. Use
JCOBridge.NewObject(java.lang.String, java.lang.Object...) or JCType.NewObject(java.lang.Object...) to obtain valid instances.
JCObject implements Iterable so that CLR collections and enumerables
can be iterated with a standard Java for-each loop.
See also: JCOReflector for usage examples.
| Modifier and Type | Method and Description |
|---|---|
Object |
clone()
Creates and returns a deep copy of this CLR object by invoking the CLR
Clone
method on the underlying object. |
boolean |
equals(Object obj)
Tests equality with another object by delegating to the CLR
Equals method
on the underlying CLR object. |
Object |
Get(String propertyName)
Retrieves an instance property value from the underlying CLR object.
|
Object |
GetField(String field)
Retrieves an instance field value from the underlying CLR object.
|
Object |
GetOnType(String propertyName)
Retrieves a static or type-level property value from the CLR type of the underlying object.
|
int |
hashCode()
Returns the hash code of the underlying CLR object by delegating to the CLR
GetHashCode method. |
Object |
Invoke(String method,
Object... params)
Invokes an instance method on the underlying CLR object with optional arguments.
|
Object |
InvokeOnType(String method,
Object... params)
Invokes a static or type-level method on the CLR type of the underlying object,
rather than on the object instance itself.
|
Iterator<JCObject> |
iterator()
Returns an iterator over the elements of the underlying CLR collection or enumerable.
|
void |
RegisterEventListener(String eventName,
IJCEventEmit eventHandler)
Registers a value-returning CLR event handler on this object.
|
void |
RegisterEventListener(String eventName,
IJCVoidEventEmit eventHandler)
Registers a void-return CLR event handler on this object.
|
JCObject |
Set(String propertyName,
Object value)
Sets an instance property on the underlying CLR object.
|
JCObject |
SetField(String field,
Object value)
Sets an instance field on the underlying CLR object.
|
String |
toString()
Returns the string representation of the underlying CLR object by delegating to
the CLR
ToString method. |
void |
UnregisterEventListener(String eventName,
IJCEventEmit eventHandler)
Unregisters a value-returning CLR event handler from this object.
|
void |
UnregisterEventListener(String eventName,
IJCVoidEventEmit eventHandler)
Unregisters a void-return CLR event handler from this object.
|
getReferenceforEach, spliteratorpublic Object clone() throws CloneNotSupportedException
Clone
method on the underlying object. The CLR type must implement ICloneable.clone in class ObjectJCObject wrapping the cloned CLR object.CloneNotSupportedException - if the CLR type does not support cloning or
if the native call fails.public boolean equals(Object obj)
Equals method
on the underlying CLR object. Returns false if the native call fails.public int hashCode()
GetHashCode method.public String toString()
ToString method.public Iterator<JCObject> iterator()
IEnumerable. Returns null if the native
iterator cannot be created.public Object Invoke(String method, Object... params) throws JCNativeException
The method is resolved by name on the CLR type of the object. If overloads exist,
the bridge selects the best match based on the argument types. Return values follow
the standard mapping: CLR primitives become Java primitives or String;
all other types are returned as JCObject.
method - the name of the CLR instance method to invoke.params - optional arguments to pass to the method.JCObject.JCNativeException - if the method cannot be found, the invocation fails,
or a CLR exception is thrown.public Object Get(String propertyName) throws JCNativeException
propertyName - the name of the CLR property to read.JCObject.JCNativeException - if the property cannot be found or the read fails.public Object GetField(String field) throws JCNativeException
field - the name of the CLR field to read.JCObject.JCNativeException - if the field cannot be found or the read fails.public JCObject Set(String propertyName, Object value) throws JCNativeException
propertyName - the name of the CLR property to write.value - the value to assign.JCObject instance, for call chaining.JCNativeException - if the property cannot be found or the write fails.public JCObject SetField(String field, Object value) throws JCNativeException
field - the name of the CLR field to write.value - the value to assign.JCObject instance, for call chaining.JCNativeException - if the field cannot be found or the write fails.public Object InvokeOnType(String method, Object... params) throws JCNativeException
method - the name of the CLR type-level method to invoke.params - optional arguments to pass to the method.JCObject.JCNativeException - if the method cannot be found, the invocation fails,
or a CLR exception is thrown.public Object GetOnType(String propertyName) throws JCNativeException
propertyName - the name of the CLR type-level property to read.JCObject.JCNativeException - if the property cannot be found or the read fails.public void RegisterEventListener(String eventName, IJCVoidEventEmit eventHandler) throws JCNativeException, JCException
The handler instance is stored in voidEventMap to prevent premature GC
collection while registered. Throws JCException if a handler is already
registered for the same event name.
eventName - the CLR event name to subscribe to.eventHandler - the IJCVoidEventEmit handler to invoke when the event fires.JCNativeException - if the native registration fails.JCException - if a handler for eventName is already registered.public void RegisterEventListener(String eventName, IJCEventEmit eventHandler) throws JCNativeException, JCException
The handler instance is stored in eventMap to prevent premature GC
collection while registered. Throws JCException if a handler is already
registered for the same event name.
eventName - the CLR event name to subscribe to.eventHandler - the IJCEventEmit handler to invoke when the event fires.JCNativeException - if the native registration fails.JCException - if a handler for eventName is already registered.public void UnregisterEventListener(String eventName, IJCVoidEventEmit eventHandler) throws JCNativeException, JCException
The handler is removed from voidEventMap, allowing it to be collected
by the GC. Throws JCException if no handler is registered for the event name.
eventName - the CLR event name to unsubscribe from.eventHandler - the IJCVoidEventEmit handler to remove.JCNativeException - if the native unregistration fails.JCException - if no handler for eventName is registered.public void UnregisterEventListener(String eventName, IJCEventEmit eventHandler) throws JCNativeException, JCException
The handler is removed from eventMap, allowing it to be collected
by the GC. Throws JCException if no handler is registered for the event name.
eventName - the CLR event name to unsubscribe from.eventHandler - the IJCEventEmit handler to remove.JCNativeException - if the native unregistration fails.JCException - if no handler for eventName is registered.