Class Proxy

java.lang.Object
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:

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    chain(Message... msgs)
    chain.
    chain(com.sun.jna.Pointer selector, Object... args)
    chain.
    chain(String selector, Object... args)
    chain.
    void
    dispose(boolean sendDeallocMessage)
    Removes the proxy from the proxy cache, and optionally sends a dealloc message to the peer.
    static void
    drainCache.
    boolean
    Compares this object to another Peerable object.
    get(String key)
    Wrapper for key-value coding.
    boolean
    Returns the KVC coded value for the specified key as a boolean.
    Returns the client that is used by this Proxy object.
    double
    Returns the KVC coded value for the specified key as a double.
    int
    Returns the KVC coded value for the specified key as an int.
    com.sun.jna.Pointer
    getPeer.
    com.sun.jna.Pointer
    Returns the KVC coded value for the specified key as a Pointer.
    Returns the KVC coded value for the specified key as a Proxy.
    int
     
    static Proxy
    load(com.sun.jna.Pointer peer)
    Loads a proxy object for the specified pointer to an objective-c object.
    static Object
    Releases the Proxy object from the Cache.
    static Object
    Retains the Proxy object in the Cache.
    send(Message... msgs)
    Sends a message to the peer.
    send(com.sun.jna.Pointer selector, Object... args)
    Sends a message to the peer.
    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.
    sendProxy(com.sun.jna.Pointer selector, Object... args)
    A wrapper for the send() method, that returns a Pointer.
    sendProxy(String selector, Object... args)
    A wrapper for the send() method, that returns a Pointer.
    sendRaw(Message... msgs)
    Sends a message to the peer without performing any type coercion to the inputs or outputs.
    sendRaw(com.sun.jna.Pointer selector, Object... args)
    Sends a message to the peer.
    sendRaw(String selector, Object... args)
    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.
    void
    set(String key, Object value)
    Wrapper for Key-Value coding.
    setClient(Client client)
    Sets the client that should be used for sending messages to the peer object.
    void
    setPeer(com.sun.jna.Pointer peer)
    setPeer.
    Outputs the object as a string.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • 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 - a Client object.
    • 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 - a Client object.
      peer - a Pointer object.
    • Proxy

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

    • 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()

      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.

      Parameters:
      selector - a Pointer object.
      args - a Object object.
      Returns:
      a String object.
    • sendString

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

      sendString.

      Parameters:
      selector - a String object.
      args - a Object object.
      Returns:
      a String object.
    • 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:
      msgs - a Message object.
      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:
      msgs - a Message object.
      Returns:
      The result of the message call.
    • chain

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

      chain.

      Parameters:
      selector - a Pointer object.
      args - a Object object.
      Returns:
      a Proxy object.
    • chain

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

      chain.

      Parameters:
      selector - a String object.
      args - a Object object.
      Returns:
      a Proxy object.
    • chain

      public Proxy chain(Message... msgs)

      chain.

      Parameters:
      msgs - a Message object.
      Returns:
      a Proxy object.
    • getClient

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

      public Proxy setClient(Client client)
      Sets the client that should be used for sending messages to the peer object.
      Parameters:
      client - a Client object.
      Returns:
      a Proxy object.
    • getPeer

      public com.sun.jna.Pointer getPeer()

      getPeer.

      Returns the Pointer to the native peer object.
      Specified by:
      getPeer in interface Peerable
      Returns:
      a Pointer object.
    • setPeer

      public void setPeer(com.sun.jna.Pointer peer)

      setPeer.

      Sets the pointer to the native peer object.
      Specified by:
      setPeer in interface Peerable
      Parameters:
      peer - a Pointer object.
    • 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
    • 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
    • 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 - a String object.
      value - a Object object.
    • get

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

      public int getInt(String key)
      Returns the KVC coded value for the specified key as an int.
      Parameters:
      key - a String object.
      Returns:
      a int.
    • getBoolean

      public boolean getBoolean(String key)
      Returns the KVC coded value for the specified key as a boolean.
      Parameters:
      key - a String object.
      Returns:
      a boolean.
    • getProxy

      public Proxy getProxy(String key)
      Returns the KVC coded value for the specified key as a Proxy.
      Parameters:
      key - a String object.
      Returns:
      a Proxy object.
    • getDouble

      public double getDouble(String key)
      Returns the KVC coded value for the specified key as a double.
      Parameters:
      key - a String object.
      Returns:
      a double.
    • getPointer

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