ca.weblite.objc
Class Proxy

java.lang.Object
  extended by ca.weblite.objc.Proxy
All Implemented Interfaces:
Peerable
Direct Known Subclasses:
NSObject

public class Proxy
extends Object
implements Peerable

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:

Author:
shannah
See Also:
JavaNativeAccess On GitHub

Constructor Summary
Proxy()
          Creates a proxy for a Null pointer.
Proxy(Client client)
          Creates a proxy for a Null pointer using the specified Client object.
Proxy(Client client, com.sun.jna.Pointer peer)
          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
 Proxy chain(Message... msgs)
          Deprecated.  
 Proxy chain(com.sun.jna.Pointer selector, Object... args)
          Deprecated.  
 Proxy chain(String selector, Object... args)
          Deprecated.  
 void dispose(boolean sendDeallocMessage)
          Removes the proxy from the proxy cache, and optionally sends a dealloc message to the peer.
static void drainCache()
           
 boolean equals(Object o)
          Compares this object to another Peerable object.
 Object get(String key)
          Wrapper for key-value coding.
 boolean getBoolean(String key)
          Returns the KVC coded value for the specified key as a boolean.
 Client getClient()
          Returns the client that is used by this Proxy object.
 double getDouble(String key)
          Returns the KVC coded value for the specified key as a double.
 int getInt(String key)
          Returns the KVC coded value for the specified key as an int.
 com.sun.jna.Pointer getPeer()
          Returns the Pointer to the native peer object.
 com.sun.jna.Pointer getPointer(String key)
          Returns the KVC coded value for the specified key as a Pointer.
 Proxy getProxy(String key)
          Returns the KVC coded value for the specified key as a Proxy.
 int hashCode()
           
static Proxy load(com.sun.jna.Pointer peer)
          Loads a proxy object for the specified pointer to an objective-c object.
static Object release(Object obj)
          Releases the Proxy object from the Cache.
static Object retain(Object obj)
          Retains the Proxy object in the Cache.
 Object send(Message... msgs)
          Sends a message to the peer.
 Object send(com.sun.jna.Pointer selector, Object... args)
          Sends a message to the peer.
 Object send(String selector, Object... args)
          Sends a message to the peer.
 boolean sendBoolean(com.sun.jna.Pointer selector, Object... args)
          A wrapper for the send() method, that returns a boolean.
 boolean sendBoolean(String selector, Object... args)
          A wrapper for the send() method, that returns a boolean.
 double sendDouble(com.sun.jna.Pointer selector, Object... args)
          A wrapper for the send() method, that returns a double.
 double sendDouble(String selector, Object... args)
          A wrapper for the send() method, that returns a double.
 int sendInt(com.sun.jna.Pointer selector, Object... args)
          A wrapper for the send() method, that returns an int.
 int sendInt(String selector, Object... args)
          A wrapper for the send() method, that returns an int.
 com.sun.jna.Pointer sendPointer(com.sun.jna.Pointer selector, Object... args)
          A wrapper for the send() method, that returns a Pointer.
 com.sun.jna.Pointer sendPointer(String selector, Object... args)
          A wrapper for the send() method, that returns a Pointer.
 Proxy sendProxy(com.sun.jna.Pointer selector, Object... args)
          A wrapper for the send() method, that returns a Pointer.
 Proxy sendProxy(String selector, Object... args)
          A wrapper for the send() method, that returns a Pointer.
 Object sendRaw(Message... msgs)
          Sends a message to the peer without performing any type coercion to the inputs or outputs.
 Object sendRaw(com.sun.jna.Pointer selector, Object... args)
          Sends a message to the peer.
 Object sendRaw(String selector, Object... args)
          Sends a message to the peer without performing any type coercion to the inputs or outputs.
 String sendString(com.sun.jna.Pointer selector, Object... args)
           
 String sendString(String selector, Object... args)
           
 void set(String key, Object value)
          Wrapper for Key-Value coding.
 Proxy setClient(Client client)
          Sets the client that should be used for sending messages to the peer object.
 void setPeer(com.sun.jna.Pointer peer)
          Sets the pointer to the native peer object.
 String toString()
          Outputs the object as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Proxy

public Proxy()
Creates a proxy for a Null pointer.


Proxy

public Proxy(Client client)
Creates a proxy for a Null pointer using the specified Client object.

Parameters:
client -

Proxy

public Proxy(Client client,
             com.sun.jna.Pointer peer)
Creates a proxy for the specified peer Objective-C object, using the specified client to send messages to the peer.

Parameters:
client -
peer -

Proxy

public Proxy(com.sun.jna.Pointer peer)
Creates a proxy for the specified peer Objective-C object.

Parameters:
peer -
Method Detail

retain

public static Object retain(Object obj)
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

public static Object release(Object obj)
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()

load

public static Proxy load(com.sun.jna.Pointer peer)
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

public com.sun.jna.Pointer sendPointer(com.sun.jna.Pointer selector,
                                       Object... args)
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

public com.sun.jna.Pointer sendPointer(String selector,
                                       Object... args)
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

public Proxy sendProxy(String selector,
                       Object... args)
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

public Proxy sendProxy(com.sun.jna.Pointer selector,
                       Object... args)
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

public String sendString(com.sun.jna.Pointer selector,
                         Object... args)

sendString

public String sendString(String selector,
                         Object... args)

sendInt

public int sendInt(com.sun.jna.Pointer selector,
                   Object... args)
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

public int sendInt(String selector,
                   Object... args)
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

public double sendDouble(com.sun.jna.Pointer selector,
                         Object... args)
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

public double sendDouble(String selector,
                         Object... args)
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

public boolean sendBoolean(com.sun.jna.Pointer selector,
                           Object... args)
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

public boolean sendBoolean(String selector,
                           Object... args)
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

public Object send(com.sun.jna.Pointer selector,
                   Object... args)
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

public Object send(String selector,
                   Object... args)
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

public Object send(Message... msgs)
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

public Object sendRaw(com.sun.jna.Pointer selector,
                      Object... args)
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

public Object sendRaw(String selector,
                      Object... args)
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

public Object sendRaw(Message... msgs)
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.

chain

public Proxy chain(com.sun.jna.Pointer selector,
                   Object... args)
Deprecated. 

Parameters:
selector -
args -
Returns:

chain

public Proxy chain(String selector,
                   Object... args)
Deprecated. 

Parameters:
selector -
args -
Returns:

chain

public Proxy chain(Message... msgs)
Deprecated. 

Parameters:
msgs -
Returns:

getClient

public Client getClient()
Returns the client that is used by this Proxy object.

Returns:

setClient

public Proxy setClient(Client client)
Sets the client that should be used for sending messages to the peer object.

Parameters:
client -
Returns:

getPeer

public com.sun.jna.Pointer getPeer()
Returns the Pointer to the native peer object.

Specified by:
getPeer in interface Peerable
Returns:

setPeer

public void setPeer(com.sun.jna.Pointer peer)
Sets the pointer to the native peer object.

Specified by:
setPeer in interface Peerable
Parameters:
peer -

toString

public String toString()
Outputs the object as a string. This is a wrapper around the "description" method of NSObject.

Overrides:
toString in class Object
Returns:

equals

public boolean equals(Object o)
Compares this object to another Peerable object. This effectively says that the objects are equal if their peer objects are equal.

Overrides:
equals in class Object
Parameters:
o -
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class Object

set

public void set(String key,
                Object value)
Wrapper for Key-Value coding. I.e. a wrapper for the setValue:forKey: message of NSObject.

Parameters:
key -
value -

get

public Object get(String key)
Wrapper for key-value coding. I.e a wrapper for the valueForKey: method of NSObject.

Parameters:
key -
Returns:

getInt

public int getInt(String key)
Returns the KVC coded value for the specified key as an int.

Parameters:
key -
Returns:

getBoolean

public boolean getBoolean(String key)
Returns the KVC coded value for the specified key as a boolean.

Parameters:
key -
Returns:

getProxy

public Proxy getProxy(String key)
Returns the KVC coded value for the specified key as a Proxy.

Parameters:
key -
Returns:

getDouble

public double getDouble(String key)
Returns the KVC coded value for the specified key as a double.

Parameters:
key -
Returns:

getPointer

public com.sun.jna.Pointer getPointer(String key)
Returns the KVC coded value for the specified key as a Pointer.

Parameters:
key -
Returns:


Copyright © 2012–2014 Web Lite Solutions Corp.. All rights reserved.