| 
 | WebObjects 5.2 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.webobjects.foundation.NSSelector
An NSSelector object specifies a method signature (a method's name and parameter list). You can apply a selector on any object, and it performs the method that matches it, if there is one.
 NSSelector is very similar to Method.
 However, java.lang.reflect.Method objects specify a particular class's implementation of a method, and you
 can only apply them to objects of that class (or subclass). NSSelectors can be
 used on any object, regardless of class, which has a method name and signature that matches the selector.
 To find the java.lang.reflect.Method object that matches an NSSelector for a particular
 object or class, use methodOnObject or methodOnClass
 
 To create a selector, you can use a single-argument constructor or a two-argument constructor.
 The two-argument constructor
 takes the method's name and an array of the parameter types. Note that
 to obtain a Class object for a type, .class is to be
 appended to the type's name. For example, the Class object for Object
 is Object.class.
 
Class properties:
method: method nameparameters: parameter types
To apply a selector on an object, the overloaded instance methodvoid doIt(String str,int i){...}NSSelector sel = new NSSelector("doIt",new Class [] {String.class,Integer.class});
invoke is used. It performs the method that matches the selector and returns
  the result. If the target object doesn't have a method matching the selector,
  it throws NoSuchMethodException. The most basic form of invoke
  takes the target object and an Object array of the arguments.
  Other forms are convenience methods for selectors with no, one,
  or two arguments. Note that to pass an argument of a
  primitive type to invoke, an object of the corresponding
  wrapper class is used. invoke converts the object back to the primitive
  type when it invokes the method. For example, to pass the float f,
  new Float(f) is used; and to pass the boolean value true, new
  Boolean(true) is used.
  This code sample gives two ways to apply the selector
  sel (defined above) to an object:
To create and apply a selector in one step, the overloaded static method invoke is used. The basic form takes four arguments: the method name, an array of the parameter types, the target object, and an array of the arguments. Other forms are convenience methods for selectors with one or two arguments. This code sample shows two ways to create and apply a selector for the doIt method:MyClass obj1 =new MyClass(),obj2 =new MyClass(); int i =5; sel.invoke(obj1,new Object [] {"hi" ,new Integer(i)}); sel.invoke(obj2,"bye",new Integer(10));
Other methods return whether an object or class has a method that matches a selector (andvoid doIt(String str,int i){...} MyClass obj1 =new MyClass(),obj2 =new MyClass(); int i =5; NSSelector.invoke("doIt",new Class [] {String.class,Integer.class}, obj1,new Object [] {{"hi",new Integer(i)}); NSSelector.invoke("doIt",String.class,Integer.class, obj1,"bye",new Integer(10));
implementedByClass) and returns the method
  name and parameter types for a selector (name and parameterTypes).
Method, 
invoke(Object, Object[]), 
name(), 
parameterTypes(), 
implementedByObject(java.lang.Object), 
implementedByClass(java.lang.Class), 
methodOnObject(java.lang.Object), 
methodOnClass(java.lang.Class), Serialized Form| Constructor Summary | |
| NSSelector(String name)Creates a selector for a method that takes no parameters. | |
| NSSelector(String name,
           Class[] parameterTypes)Creates a new selector for a method that takes arguments. | |
| Method Summary | |
|  boolean | equals(Object otherSelector)Determines whether an object is an NSSelector equal to this NSSelector. | 
|  int | hashCode() | 
|  boolean | implementedByClass(Class targetClass)Indicates whether a class implements the method that this NSSelector specifies. | 
|  boolean | implementedByObject(Object target)Indicates whether the targetobject implements the method that this NSSelector specifies. | 
|  Object | invoke(Object target)A convenience method similar to invoke(Object, Object[]), but with no arguments. | 
|  Object | invoke(Object target,
       Object argument)A convenience method similar to invoke(Object, Object[]), but using one argument. | 
|  Object | invoke(Object target,
       Object[] parameters)Invokes the methodencapsulated by this NSSelector withparameterson thetargetobject. | 
|  Object | invoke(Object target,
       Object argument1,
       Object argument2)A convenience method similar to invoke(Object, Object[]), but using two arguments. | 
| static Object | invoke(String name,
       Class[] parameterTypes,
       Object target,
       Object[] parameters)A convenience method that creates an NSSelector for a method that takes any number of arguments, and immediately applies it to the targetobject. | 
| static Object | invoke(String name,
       Class parameterType1,
       Class parameterType2,
       Object target,
       Object argument1,
       Object argument2)A convenience method that creates an NSSelector for a method that two arguments, and immediately applies it to the targetobject. | 
| static Object | invoke(String name,
       Class parameterType,
       Object target,
       Object argument)A convenience method that creates an NSSelector for a method that one argument, and immediately applies it to the targetobject. | 
|  Method | methodOnClass(Class targetClass)Returns the java.lang.reflect.Methodthat corresponds to this NSSelector on thetargetClass. | 
|  Method | methodOnObject(Object target)Returns the java.lang.reflect.Methodthat corresponds to this NSSelector on thetargetobject. | 
|  String | name() | 
|  Class[] | parameterTypes()Returns a copy of the array of parameter types specified by this NSSelector. | 
|  String | toString() | 
| Methods inherited from class java.lang.Object | 
| clone, finalize, getClass, notify, notifyAll, wait, wait, wait | 
| Constructor Detail | 
public NSSelector(String name)
name - name of the method this NSSelector specifies
public NSSelector(String name,
                  Class[] parameterTypes)
 The parameterTypes array can be created easily:
 Class parameters[] = new Class[] {String.class, Integer.class, Boolean.class}
name - name of the method this NSSelector specifiesparameterTypes - parameter-type list for the method specified by name;
                       null if the method takes no parameters| Method Detail | 
public boolean equals(Object otherSelector)
equals in class ObjectotherSelector - the object to compare this NSSelector againsttrue when otherSelector is an NSSelector
                      with the same method and parameters as this NSSelectorObject.equals(java.lang.Object)public int hashCode()
hashCode in class ObjectObject.hashCode()public boolean implementedByClass(Class targetClass)
targetClass - a java.lang.Class object to searchtrue if targetClass implements method/parametersClasspublic boolean implementedByObject(Object target)
target object implements the method that this NSSelector specifies.target - object to checktrue if target implements method/parametersimplementedByClass(java.lang.Class), 
Class
public Object invoke(Object target,
                     Object[] parameters)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException,
                     NoSuchMethodException
method encapsulated by this NSSelector with parameters on the target object.
 Note that the method may be either a static or instance method.
 
 This method can't handle parameters or return values of primitive types (such as boolean, int, or float).
 If method returns a value of a primitive type, this method returns
 the value in an object of the corresponding wrapper type (such as Boolean,
 Integer, or Float). To pass an argument of a primitive type to method,
 wrap the value in the corresponding wrapper class.
target - object on which to invoke the method corresponding to this selectorparameters - arguments to be used when invoking method on target;
                    null if the method takes no argumentsmethod invoked or null if method is
         voidjava.lang.refelct.NoSuchMethodException - target has no method that matches method/parametersIllegalAccessException - a method in target matches method/parameters,
              but cannot be accessed by targetIllegalArgumentException - this method can't convert an argument to the type specified in  parametersjava.lang.InvocationTargetException - method throws an exception (the exception thrown is wrapped in this exception)methodOnClass(java.lang.Class), 
Method.invoke(java.lang.Object, java.lang.Object[])
public Object invoke(Object target)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException,
                     NoSuchMethodException
invoke(Object, Object[]), but with no arguments.target - object on which to invoke methodmethod or null if method is
         voidjava.lang.refelct.NoSuchMethodException - target has no method that matches method/parametersIllegalAccessException - a method in target matches method/parameters,
              but cannot be accessed by targetIllegalArgumentException - this method can't convert an argument to the type specified in  parametersjava.lang.InvocationTargetException - method throws an exception (the exception thrown is wrapped in this exception)invoke(Object, Object[])
public Object invoke(Object target,
                     Object argument)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException,
                     NoSuchMethodException
invoke(Object, Object[]), but using one argument.target - object on which to invoke method/parameterargument - argument to use when invoking method on targetmethod/parameter or null if method is
                   voidjava.lang.refelct.NoSuchMethodException - target has no method that matches method/parametersIllegalAccessException - a method in target matches method/parameters,
              but cannot be accessed by targetIllegalArgumentException - this method can't convert argument to the type specified in parametersjava.lang.InvocationTargetException - method throws an exception (the exception thrown is wrapped in this exception)invoke(Object, Object[])
public Object invoke(Object target,
                     Object argument1,
                     Object argument2)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException,
                     NoSuchMethodException
invoke(Object, Object[]), but using two arguments.target - object on which to invoke method/parametersargument1 - first argument to be passed to methodargument2 - second argument to be passed to methodmethod/parameters or null if method is
         voidjava.lang.refelct.NoSuchMethodException - target has no method that matches method/parametersIllegalAccessException - a method in target matches method/parameters,
              but cannot be accessed by targetIllegalArgumentException - this method can't convert argument1 or argument2
              to the appropriate type, specified in  parametersjava.lang.InvocationTargetException - method throws an exception (the exception thrown is wrapped in this exception)invoke(Object, Object[])
public static Object invoke(String name,
                            Class[] parameterTypes,
                            Object target,
                            Object[] parameters)
                     throws IllegalAccessException,
                            IllegalArgumentException,
                            InvocationTargetException,
                            NoSuchMethodException
target object.
 Uses the invoke(Object, Object[]) method.name - name of the new NSSelector's methodparameterTypes - parameter type list for the method specified by name;
                        null if the method takes no argumentstarget - object the new NSSelector is applied toparameters - arguments to be used when invoking the method specified by name
                        on target; null if the method takes no argumentsname;
                   null if the method is voidjava.lang.refelct.NoSuchMethodException - target has no method that matches the method specified by
              name/parameterTypesIllegalAccessException - a method in target matches name/parameterTypes,
              but cannot be accessed by targetIllegalArgumentException - this method can't convert an argument in parameters to the corresponding type
              in parameterTypesjava.lang.InvocationTargetException - the method invoked throws an exception (the exception thrown is wrapped in this exception)invoke(Object, Object[])
public static Object invoke(String name,
                            Class parameterType,
                            Object target,
                            Object argument)
                     throws IllegalAccessException,
                            IllegalArgumentException,
                            InvocationTargetException,
                            NoSuchMethodException
target object.name - name of the new NSSelector's methodparameterType - java.lang.Class object for the class of argumenttarget - object the new NSSelector is applied toargument - argument to be used when invoking the method specified by name
                       on targetname or null if the method is
         voidjava.lang.refelct.NoSuchMethodException - target has no method that matches the method specified by
              name/parameterTypeIllegalAccessException - a method in target matches name/parameterType,
              but cannot be accessed by targetIllegalArgumentException - this method can't convert argument to parameterTypejava.lang.InvocationTargetException - the method invoked throws an exception (the exception thrown is wrapped in this exception)invoke(String, Class[], Object, Object[])
public static Object invoke(String name,
                            Class parameterType1,
                            Class parameterType2,
                            Object target,
                            Object argument1,
                            Object argument2)
                     throws IllegalAccessException,
                            IllegalArgumentException,
                            InvocationTargetException,
                            NoSuchMethodException
target object.name - name of the new NSSelector's methodparameterType1 - class of the value in argument1parameterType2 - class of the value in argument2target - object the new NSSelector is applied toargument1 - first argument to use when invoking method on targetargument2 - second argument to usemethod/parameters; null if method is
         voidjava.lang.refelct.NoSuchMethodException - target has no method that matches the method specified by
              name/parameterType1/parameterType2IllegalAccessException - a method in target matches name/parameterType1/parameterType2,
              but cannot be accessed by targetIllegalArgumentException - this method can't convert argument1 to parameterType1 or
              argument2 to parameterType2java.lang.InvocationTargetException - the method invoked throws an exception (the exception thrown is wrapped in this exception)invoke(String, Class[], Object, Object[])
public Method methodOnClass(Class targetClass)
                     throws NoSuchMethodException
java.lang.reflect.Method that corresponds to this NSSelector on the targetClass.targetClass - class to search for method/parameters onmethod/parameters in targetClassjava.lang.refelct.NoSuchMethodException - targetClass does not implement method/parametersMethod, 
Class.getMethod(java.lang.String, java.lang.Class[])
public Method methodOnObject(Object target)
                      throws NoSuchMethodException
java.lang.reflect.Method that corresponds to this NSSelector on the target object.target - object to search for method/parameters onmethod/parameters in targetjava.lang.refelct.NoSuchMethodException - target does not implement method/parametersMethod, 
Class.getMethod(java.lang.String, java.lang.Class[])public String name()
method).public Class[] parameterTypes()
parameters)public String toString()
toString in class Object| 
 | Last updated Fri Feb 21 13:15:00 PST 2003. | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||