net.wotonomy.foundation
Class NSSelector

java.lang.Object
  extended by net.wotonomy.foundation.NSSelector
All Implemented Interfaces:
java.io.Serializable, java.util.Comparator

public class NSSelector
extends java.lang.Object
implements java.util.Comparator, java.io.Serializable

A pure java implementation of NSSelector.

Version:
$Revision: 892 $
Author:
michael@mpowers.net, $Author: cgruber $
See Also:
Serialized Form

Field Summary
protected static java.lang.Class[] EMPTY_CLASS_ARRAY
          Saves creating a new class array for parameterless method invocation.
protected static java.lang.Object[] EMPTY_OBJECT_ARRAY
          Saves creating a new object array for parameterless method invocation.
protected  NSMutableDictionary methodMap
           
protected  java.lang.String methodName
           
protected static java.lang.String NOT_FOUND
          A marker to indicate object not found.
protected  java.lang.Class[] parameterTypes
           
 
Constructor Summary
protected NSSelector()
          Constructor for custom subclasses that implement specific operators and that do not use dynamic method invocation.
  NSSelector(java.lang.String aMethodName)
          Constructor specifying a method name with no parameters.
  NSSelector(java.lang.String aMethodName, java.lang.Class[] aParameterTypeArray)
          Constructor specifying a method name and an array of parameter types.
  NSSelector(java.lang.String aMethodName, java.util.Comparator aComparator)
          Constructor specifying a method name and a comparator.
 
Method Summary
 java.util.Comparator comparator()
          Returns the Comparator used for this selector.
 int compare(java.lang.Object o1, java.lang.Object o2)
           
 boolean equals(java.lang.Object obj)
           
 boolean implementedByClass(java.lang.Class aClass)
          Returns whether the class implements the method for this selector.
 boolean implementedByObject(java.lang.Object anObject)
          Returns whether the object's class implements the method for this selector.
 java.lang.Object invoke(java.lang.Object anObject)
          Invokes this selector's method on the specified object with no parameters.
 java.lang.Object invoke(java.lang.Object anObject, java.lang.Object aParameter)
          Invokes this selector's method on the specified object with the specified parameter.
 java.lang.Object invoke(java.lang.Object anObject, java.lang.Object[] parameters)
          Invokes this selector's method on the specified object using the specified parameters.
 java.lang.Object invoke(java.lang.Object anObject, java.lang.Object p1, java.lang.Object p2)
          Invokes this selector's method on the specified object using the specified two parameters.
static java.lang.Object invoke(java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object anObject, java.lang.Object aParameter)
          Invokes the method with the specified signature on the specified object using the specified parameter.
static java.lang.Object invoke(java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object anObject, java.lang.Object[] parameters)
          Invokes the method with the specified signature on the specified object using the specified parameters.
static java.lang.Object invoke(java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object anObject, java.lang.Object p1, java.lang.Object p2)
          Invokes the method with the specified signature on the specified object using the specified two parameters.
static java.lang.Object invoke(java.lang.String methodName, java.lang.Object anObject)
          Invokes the method with the specified signature on the specified object with no parameters.
 java.lang.reflect.Method methodOnClass(java.lang.Class aClass)
          Returns the appropriate method for the specified class.
 java.lang.reflect.Method methodOnObject(java.lang.Object anObject)
          Convenience to get a method for an object.
 java.lang.String name()
          Returns the name of the method.
 java.lang.Class[] parameterTypes()
          Returns the array of parameter types.
 java.lang.String toString()
          A String description of this selector.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

methodMap

protected NSMutableDictionary methodMap

methodName

protected java.lang.String methodName

parameterTypes

protected java.lang.Class[] parameterTypes

NOT_FOUND

protected static final java.lang.String NOT_FOUND
A marker to indicate object not found.

See Also:
Constant Field Values

EMPTY_CLASS_ARRAY

protected static final java.lang.Class[] EMPTY_CLASS_ARRAY
Saves creating a new class array for parameterless method invocation.


EMPTY_OBJECT_ARRAY

protected static final java.lang.Object[] EMPTY_OBJECT_ARRAY
Saves creating a new object array for parameterless method invocation.

Constructor Detail

NSSelector

public NSSelector(java.lang.String aMethodName,
                  java.lang.Class[] aParameterTypeArray)
Constructor specifying a method name and an array of parameter types.


NSSelector

public NSSelector(java.lang.String aMethodName)
Constructor specifying a method name with no parameters.


NSSelector

protected NSSelector()
Constructor for custom subclasses that implement specific operators and that do not use dynamic method invocation.


NSSelector

public NSSelector(java.lang.String aMethodName,
                  java.util.Comparator aComparator)
Constructor specifying a method name and a comparator. This is not in the spec.

Method Detail

name

public java.lang.String name()
Returns the name of the method.


parameterTypes

public java.lang.Class[] parameterTypes()
Returns the array of parameter types.


toString

public java.lang.String toString()
A String description of this selector.

Overrides:
toString in class java.lang.Object

methodOnClass

public java.lang.reflect.Method methodOnClass(java.lang.Class aClass)
                                       throws java.lang.NoSuchMethodException
Returns the appropriate method for the specified class.

Throws:
java.lang.NoSuchMethodException

methodOnObject

public java.lang.reflect.Method methodOnObject(java.lang.Object anObject)
                                        throws java.lang.NoSuchMethodException
Convenience to get a method for an object.

Throws:
java.lang.NoSuchMethodException

implementedByClass

public boolean implementedByClass(java.lang.Class aClass)
Returns whether the class implements the method for this selector.


implementedByObject

public boolean implementedByObject(java.lang.Object anObject)
Returns whether the object's class implements the method for this selector.


invoke

public java.lang.Object invoke(java.lang.Object anObject,
                               java.lang.Object[] parameters)
                        throws java.lang.IllegalAccessException,
                               java.lang.IllegalArgumentException,
                               java.lang.reflect.InvocationTargetException,
                               java.lang.NoSuchMethodException
Invokes this selector's method on the specified object using the specified parameters.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invoke

public java.lang.Object invoke(java.lang.Object anObject)
                        throws java.lang.IllegalAccessException,
                               java.lang.IllegalArgumentException,
                               java.lang.reflect.InvocationTargetException,
                               java.lang.NoSuchMethodException
Invokes this selector's method on the specified object with no parameters.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invoke

public java.lang.Object invoke(java.lang.Object anObject,
                               java.lang.Object aParameter)
                        throws java.lang.IllegalAccessException,
                               java.lang.IllegalArgumentException,
                               java.lang.reflect.InvocationTargetException,
                               java.lang.NoSuchMethodException
Invokes this selector's method on the specified object with the specified parameter.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invoke

public java.lang.Object invoke(java.lang.Object anObject,
                               java.lang.Object p1,
                               java.lang.Object p2)
                        throws java.lang.IllegalAccessException,
                               java.lang.IllegalArgumentException,
                               java.lang.reflect.InvocationTargetException,
                               java.lang.NoSuchMethodException
Invokes this selector's method on the specified object using the specified two parameters.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invoke

public static java.lang.Object invoke(java.lang.String methodName,
                                      java.lang.Class[] parameterTypes,
                                      java.lang.Object anObject,
                                      java.lang.Object[] parameters)
                               throws java.lang.IllegalAccessException,
                                      java.lang.IllegalArgumentException,
                                      java.lang.reflect.InvocationTargetException,
                                      java.lang.NoSuchMethodException
Invokes the method with the specified signature on the specified object using the specified parameters.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invoke

public static java.lang.Object invoke(java.lang.String methodName,
                                      java.lang.Object anObject)
                               throws java.lang.IllegalAccessException,
                                      java.lang.IllegalArgumentException,
                                      java.lang.reflect.InvocationTargetException,
                                      java.lang.NoSuchMethodException
Invokes the method with the specified signature on the specified object with no parameters.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invoke

public static java.lang.Object invoke(java.lang.String methodName,
                                      java.lang.Class[] parameterTypes,
                                      java.lang.Object anObject,
                                      java.lang.Object aParameter)
                               throws java.lang.IllegalAccessException,
                                      java.lang.IllegalArgumentException,
                                      java.lang.reflect.InvocationTargetException,
                                      java.lang.NoSuchMethodException
Invokes the method with the specified signature on the specified object using the specified parameter.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invoke

public static java.lang.Object invoke(java.lang.String methodName,
                                      java.lang.Class[] parameterTypes,
                                      java.lang.Object anObject,
                                      java.lang.Object p1,
                                      java.lang.Object p2)
                               throws java.lang.IllegalAccessException,
                                      java.lang.IllegalArgumentException,
                                      java.lang.reflect.InvocationTargetException,
                                      java.lang.NoSuchMethodException
Invokes the method with the specified signature on the specified object using the specified two parameters.

Throws:
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

comparator

public java.util.Comparator comparator()
Returns the Comparator used for this selector. This is not in the spec.


compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Specified by:
compare in interface java.util.Comparator

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class java.lang.Object


Copyright © 2006 null. All Rights Reserved.