java.lang.Object
ca.weblite.objc.Proxy
- All Implemented Interfaces:
Peerable
- Direct Known Subclasses:
NSObject
A wrapper around a native (Objective-C) object that allows for sending
messages from Java.
Example Wrapping NSMutableArray Object
The following snippet is taken from a unit test, to give you an idea of how to use the Proxy class to wrap an Objective-C object.
The NSRange object is a structure that we define in Java to correspond with the NSRange objective-c structure according to JNA conventions. It's implementation (for your reference) was:
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionProxy()Creates a proxy for a Null pointer.Creates a proxy for a Null pointer using the specified Client object.Creates a proxy for the specified peer Objective-C object, using the specified client to send messages to the peer.Proxy(com.sun.jna.Pointer peer) Creates a proxy for the specified peer Objective-C object. -
Method Summary
Modifier and TypeMethodDescriptionchain.chain.chain.voiddispose(boolean sendDeallocMessage) Removes the proxy from the proxy cache, and optionally sends a dealloc message to the peer.static voiddrainCache.booleanCompares this object to another Peerable object.Wrapper for key-value coding.booleangetBoolean(String key) Returns the KVC coded value for the specified key as a boolean.Returns the client that is used by this Proxy object.doubleReturns the KVC coded value for the specified key as a double.intReturns the KVC coded value for the specified key as an int.com.sun.jna.PointergetPeer()getPeer.com.sun.jna.PointergetPointer(String key) Returns the KVC coded value for the specified key as a Pointer.Returns the KVC coded value for the specified key as a Proxy.inthashCode()static Proxyload(com.sun.jna.Pointer peer) Loads a proxy object for the specified pointer to an objective-c object.static ObjectReleases the Proxy object from the Cache.static ObjectRetains the Proxy object in the Cache.Sends a message to the peer.Sends a message to the peer.Sends a message to the peer.booleansendBoolean(com.sun.jna.Pointer selector, Object... args) A wrapper for the send() method, that returns a boolean.booleansendBoolean(String selector, Object... args) A wrapper for the send() method, that returns a boolean.doublesendDouble(com.sun.jna.Pointer selector, Object... args) A wrapper for the send() method, that returns a double.doublesendDouble(String selector, Object... args) A wrapper for the send() method, that returns a double.intA wrapper for the send() method, that returns an int.intA wrapper for the send() method, that returns an int.com.sun.jna.PointersendPointer(com.sun.jna.Pointer selector, Object... args) A wrapper for the send() method, that returns a Pointer.com.sun.jna.PointersendPointer(String selector, Object... args) A wrapper for the send() method, that returns a Pointer.A wrapper for the send() method, that returns a Pointer.A wrapper for the send() method, that returns a Pointer.Sends a message to the peer without performing any type coercion to the inputs or outputs.Sends a message to the peer.Sends a message to the peer without performing any type coercion to the inputs or outputs.sendString(com.sun.jna.Pointer selector, Object... args) sendString.sendString(String selector, Object... args) sendString.voidWrapper for Key-Value coding.Sets the client that should be used for sending messages to the peer object.voidsetPeer(com.sun.jna.Pointer peer) setPeer.toString()Outputs the object as a string.
-
Constructor Details
-
Proxy
public Proxy()Creates a proxy for a Null pointer. -
Proxy
Creates a proxy for a Null pointer using the specified Client object.- Parameters:
client- aClientobject.
-
Proxy
Creates a proxy for the specified peer Objective-C object, using the specified client to send messages to the peer.- Parameters:
client- aClientobject.peer- aPointerobject.
-
Proxy
public Proxy(com.sun.jna.Pointer peer) Creates a proxy for the specified peer Objective-C object.- Parameters:
peer- aPointerobject.
-
-
Method Details
-
retain
Retains the Proxy object in the Cache. This is not related to the Objective-C message "release". It pertains only to the Java cache of proxy objects.- Parameters:
obj- The object that is being retained. If the object is a Proxy object, then its retainCount will be incremented.- Returns:
- The object that was passed to it.
-
release
Releases the Proxy object from the Cache. This is not related to the Objective-C message "release". It pertains only to the Java cache of proxy objects.- Parameters:
obj- The object that is being released. If the object is a Proxy object, then its retainCount will be decremented, and, if it is zero, will be removed from the proxy cache.- Returns:
- The object that was passed to it.
-
drainCache
public static void drainCache()drainCache.
-
load
Loads a proxy object for the specified pointer to an objective-c object. If a Proxy has previously been created for this pointer, this same proxy object will be loaded from the cache.Note: This will perform a retain() on the Proxy object, so you should release it when you are done with it to remove it from the cache.
- Parameters:
peer- The objective-c peer object.- Returns:
- A proxy that wraps the provided peer object.
-
dispose
public void dispose(boolean sendDeallocMessage) Removes the proxy from the proxy cache, and optionally sends a dealloc message to the peer.- Parameters:
sendDeallocMessage- IF true, then this will also send a dealloc message to the peer. If false, then it will simply remove from the Proxy cache, but leave the Objective-C object intact.
-
sendPointer
A wrapper for the send() method, that returns a Pointer.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a Pointer.
-
sendPointer
A wrapper for the send() method, that returns a Pointer.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a Pointer.
-
sendProxy
A wrapper for the send() method, that returns a Pointer.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a Pointer.
-
sendProxy
A wrapper for the send() method, that returns a Pointer.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a Pointer.
-
sendString
sendString.
-
sendString
sendString.
-
sendInt
A wrapper for the send() method, that returns an int.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as an int.
-
sendInt
A wrapper for the send() method, that returns an int.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as an int.
-
sendDouble
A wrapper for the send() method, that returns a double.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a double.
-
sendDouble
A wrapper for the send() method, that returns a double.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a double.
-
sendBoolean
A wrapper for the send() method, that returns a boolean.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a boolean.
-
sendBoolean
A wrapper for the send() method, that returns a boolean.- Parameters:
selector- The selector to call on the peer.args- Variable argument list.- Returns:
- The result of the message call as a boolean.
-
send
Sends a message to the peer.- Parameters:
selector- The selector to send to.args- Variable argument list.- Returns:
- The result of the message call.
-
send
Sends a message to the peer.- Parameters:
selector- The selector to send to.args- Variable argument list.- Returns:
- The result of the message call.
-
send
Sends a message to the peer.- Parameters:
msgs- aMessageobject.- Returns:
- The result of the message call.
-
sendRaw
Sends a message to the peer.- Parameters:
selector- The selector to send to.args- Variable argument list.- Returns:
- The result of the message call.
-
sendRaw
Sends a message to the peer without performing any type coercion to the inputs or outputs.- Parameters:
selector- The selector to send to.args- Variable argument list.- Returns:
- The result of the message call.
-
sendRaw
Sends a message to the peer without performing any type coercion to the inputs or outputs.- Parameters:
msgs- aMessageobject.- Returns:
- The result of the message call.
-
chain
chain.
-
chain
chain.
-
chain
chain.
-
getClient
Returns the client that is used by this Proxy object.- Returns:
- a
Clientobject.
-
setClient
Sets the client that should be used for sending messages to the peer object. -
getPeer
public com.sun.jna.Pointer getPeer()getPeer.
Returns the Pointer to the native peer object. -
setPeer
public void setPeer(com.sun.jna.Pointer peer) setPeer.
Sets the pointer to the native peer object. -
toString
Outputs the object as a string. This is a wrapper around the "description" method of NSObject. -
equals
Compares this object to another Peerable object. This effectively says that the objects are equal if their peer objects are equal. -
hashCode
public int hashCode() -
set
Wrapper for Key-Value coding. I.e. a wrapper for the setValue:forKey: message of NSObject. -
get
Wrapper for key-value coding. I.e a wrapper for the valueForKey: method of NSObject. -
getInt
Returns the KVC coded value for the specified key as an int.- Parameters:
key- aStringobject.- Returns:
- a int.
-
getBoolean
Returns the KVC coded value for the specified key as a boolean.- Parameters:
key- aStringobject.- Returns:
- a boolean.
-
getProxy
Returns the KVC coded value for the specified key as a Proxy. -
getDouble
Returns the KVC coded value for the specified key as a double.- Parameters:
key- aStringobject.- Returns:
- a double.
-
getPointer
Returns the KVC coded value for the specified key as a Pointer.- Parameters:
key- aStringobject.- Returns:
- a
Pointerobject.
-