ca.weblite.objc
Class NSObject

java.lang.Object
  extended by ca.weblite.objc.Proxy
      extended by ca.weblite.objc.NSObject
All Implemented Interfaces:
Peerable, PeerableRecipient, Recipient

public class NSObject
extends Proxy
implements PeerableRecipient

The base class for objects that can interact with the Objective-C runtime. NSObjects are connected to both an Objective-C peer object, and an Objective-C parent object. The peer is a reflection of the object in Objective-C. It is a WLProxy object that will simply forward messages from Objective-C to Java.

The parent object is used as a sort of superclass so that messages that aren't explicitly handled by the Java class can be handled by the superclass.

Simple Example

The following example shows a subclass of NSObject that is used as a delegate for an NSOpenPanel. Notice, that, by using the @Msg annotation, the start() method is effectively called via Objective-C. Similarly, the panelSelectionDidChange() method is called by the NSOpenPanel class to respond to events when the user clicks on a different item in the open dialog.

If you run this application, it will open an NSOpenPanel modal dialog and allow you to select a file. If you run this program and select a single file, the output will look something like:

Author:
shannah
See Also:
NSOpenPanelSample

Field Summary
 com.sun.jna.Pointer parent
          Pointer to the parent objective-c object of this object.
 
Constructor Summary
NSObject()
          Creates null proxy (i.e.
NSObject(Client c)
          Creates a null proxy using the specified client as the default client with which to send messages to the objective-c runtime.
NSObject(Client c, com.sun.jna.Pointer peer)
          Creates a proxy for the specified objective-c object.
NSObject(com.sun.jna.Pointer peer)
          Creates an NSObject to wrap (i.e.
NSObject(String className)
           
 
Method Summary
 NSObject chain(Message... msgs)
          Deprecated.  
 NSObject chain(com.sun.jna.Pointer selector, Object... args)
          Deprecated.  
 NSObject chain(String selector, Object... args)
          Deprecated.  
 NSObject dealloc()
          Deprecated.  
 void forwardInvocation(long linvocation)
          Handles a method invocation.
 void forwardInvocation(com.sun.jna.Pointer invocation)
          Handles a method invocation.
 void forwardInvocationToParent(long linvocation)
          Forwards an NSInvocation to the parent object to be handled.
 void forwardInvocationToParent(com.sun.jna.Pointer invocation)
          Forwards an NSInvocation to the parent object to be handled.
protected static Map<String,Method> getMethodMap(Class cls)
          Returns the method map for a particular class.
 NSObject init(com.sun.jna.Pointer parent)
          Initializes this object and registers it with the Objective-C runtime.
 NSObject init(String cls)
          Initializes this object and registers it with the Objective-C runtime.
 Method methodForSelector(String selector)
          Returns the java method that responds to a specific selector for the current object.
 long methodSignatureForSelector(long lselector)
          Returns the NSMethodSignature (Objective-C) object pointer for the specified selector.
 com.sun.jna.Pointer methodSignatureForSelector(com.sun.jna.Pointer selector)
          Returns the NSMethodSignature (Objective-C) object pointer for the specified selector.
 boolean respondsToSelector(long lselector)
          Checks whether this object responds to the given selector.
 boolean respondsToSelector(com.sun.jna.Pointer selector)
          Checks whether this object responds to the given selector.
 
Methods inherited from class ca.weblite.objc.Proxy
dispose, drainCache, equals, get, getBoolean, getClient, getDouble, getInt, getPeer, getPointer, getProxy, hashCode, load, release, retain, send, send, send, sendBoolean, sendBoolean, sendDouble, sendDouble, sendInt, sendInt, sendPointer, sendPointer, sendProxy, sendProxy, sendRaw, sendRaw, sendRaw, sendString, sendString, set, setClient, setPeer, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ca.weblite.objc.Peerable
getPeer, setPeer
 

Field Detail

parent

public com.sun.jna.Pointer parent
Pointer to the parent objective-c object of this object.

Constructor Detail

NSObject

public NSObject(String className)

NSObject

public NSObject()
Creates null proxy (i.e. a proxy around a null pointer). In order to make this class functional and register it with the objective-c runtime, you still need to call one of the init() method variants.


NSObject

public NSObject(com.sun.jna.Pointer peer)
Creates an NSObject to wrap (i.e. send messages to) the specified Objective-C object. This doesn't actually register an object yet with the Objective-C runtime. You must still call init() to do this.

Parameters:
peer -

NSObject

public NSObject(Client c)
Creates a null proxy using the specified client as the default client with which to send messages to the objective-c runtime.

Parameters:
c - The client that should be used to send messages in this object.

NSObject

public NSObject(Client c,
                com.sun.jna.Pointer peer)
Creates a proxy for the specified objective-c object.

Parameters:
c - The client that should be used for sending messages via this proxy.
peer - The peer object.
Method Detail

getMethodMap

protected static Map<String,Method> getMethodMap(Class cls)
Returns the method map for a particular class. The Map that is returned maps string selectors to Method objects.

Parameters:
cls - The class whose map we wish to obtain
Returns:
The map that maps string selectors

init

public NSObject init(com.sun.jna.Pointer parent)
Initializes this object and registers it with the Objective-C runtime.

Parameters:
parent - A pointer to a parent object that is used as a sort of super class. I.e. messages that this object doesn't handle will be passed to this parent object transparently in the background. It acts 100% as a superclass would.
Returns:
Self for chaining.

init

public NSObject init(String cls)
Initializes this object and registers it with the Objective-C runtime.

Parameters:
parent - A pointer to a parent object that is used as a sort of super class. I.e. messages that this object doesn't handle will be passed to this parent object transparently in the background. It acts 100% as a superclass would.
cls - The name of the class to use as the super class for this object.
Returns:
Self for chaining.

methodForSelector

public Method methodForSelector(String selector)
Returns the java method that responds to a specific selector for the current object.

Parameters:
selector - The
Returns:
The method object that handles the specified selector (or null if none is specified).
See Also:
RuntimeUtils.sel()

methodSignatureForSelector

public com.sun.jna.Pointer methodSignatureForSelector(com.sun.jna.Pointer selector)
Returns the NSMethodSignature (Objective-C) object pointer for the specified selector. If there is a Java method registered with this selector, then it will return its signature. Otherwise it will return the method signature of the parent object.

Parameters:
selector -
Returns:
Pointer to an NSMethodSignature object.
See Also:
NSMethodSignature Class Reference

methodSignatureForSelector

public long methodSignatureForSelector(long lselector)
Returns the NSMethodSignature (Objective-C) object pointer for the specified selector. If there is a Java method registered with this selector, then it will return its signature. Otherwise it will return the method signature of the parent object.

Specified by:
methodSignatureForSelector in interface Recipient
Parameters:
selector -
Returns:
Pointer to an NSMethodSignature object.
See Also:
NSMethodSignature Class Reference

forwardInvocationToParent

public void forwardInvocationToParent(com.sun.jna.Pointer invocation)
Forwards an NSInvocation to the parent object to be handled. The parent will handle the invocation (if it contains an appropriate selector), but the peer will still be treated as the "Self" of the message. I.e. this acts exactly like calling super() in an OO language.

Parameters:
invocation - Pointer to the objective-c NSInvocation object.
See Also:
NSInvocation Class Reference

forwardInvocationToParent

public void forwardInvocationToParent(long linvocation)
Forwards an NSInvocation to the parent object to be handled. The parent will handle the invocation (if it contains an appropriate selector), but the peer will still be treated as the "Self" of the message. I.e. this acts exactly like calling super() in an OO language.

Parameters:
invocation - Pointer to the objective-c NSInvocation object.
See Also:
NSInvocation Class Reference

forwardInvocation

public void forwardInvocation(com.sun.jna.Pointer invocation)
Handles a method invocation. This will first check to see if there is a matching Java method in this class (method requires the @Msg annotation), and call that method if it is available. Otherwise it will obtain the method implementation from the parent class and execute it. The return value is added to the NSInvocation object. This method is used by the Native WLProxy to pipe all messages to this object's peer through Java so that it has a chance to process it.

Parameters:
invocation - NSInvocation Objective-C object that is to be invoked.
See Also:
NSInvocation Class Reference, NSProxy forwardInvocation Documentation

forwardInvocation

public void forwardInvocation(long linvocation)
Handles a method invocation. This will first check to see if there is a matching Java method in this class (method requires the @Msg annotation), and call that method if it is available. Otherwise it will obtain the method implementation from the parent class and execute it. The return value is added to the NSInvocation object. This method is used by the Native WLProxy to pipe all messages to this object's peer through Java so that it has a chance to process it.

Specified by:
forwardInvocation in interface Recipient
Parameters:
invocation - NSInvocation Objective-C object that is to be invoked.
See Also:
NSInvocation Class Reference, NSProxy forwardInvocation Documentation

respondsToSelector

public boolean respondsToSelector(com.sun.jna.Pointer selector)
Checks whether this object responds to the given selector. This is used by the WLProxy (Objective-C peer object) to route requests for its NSProxy respondsToSelector: message. This will check to see if there is a registered java method in the class that responds to the selector (based on the @Msg annotation). Then it will check the parent object to see if it responds to the selector.

Parameters:
selector - Pointer to the selector to check.
Returns:
True if either the java class or the parent Objective-c object responds to the specified selector.
See Also:
RuntimeUtils.sel(), Objective-C selectors reference

respondsToSelector

public boolean respondsToSelector(long lselector)
Checks whether this object responds to the given selector. This is used by the WLProxy (Objective-C peer object) to route requests for its NSProxy respondsToSelector: message. This will check to see if there is a registered java method in the class that responds to the selector (based on the @Msg annotation). Then it will check the parent object to see if it responds to the selector.

Specified by:
respondsToSelector in interface Recipient
Parameters:
selector - Pointer to the selector to check.
Returns:
True if either the java class or the parent Objective-c object responds to the specified selector.
See Also:
RuntimeUtils.sel(), Objective-C selectors reference

chain

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

Overrides:
chain in class Proxy
Parameters:
selector -
args -
Returns:

chain

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

Overrides:
chain in class Proxy
Parameters:
selector -
args -
Returns:

chain

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

Overrides:
chain in class Proxy
Parameters:
msgs -
Returns:

dealloc

public NSObject dealloc()
Deprecated. 

Returns:


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