WebObjects 5.4.2

com.webobjects.foundation
Class NSKeyValueCoding.ValueAccessor

java.lang.Object
  extended by com.webobjects.foundation.NSKeyValueCoding.ValueAccessor
Enclosing interface:
NSKeyValueCoding

public abstract static class NSKeyValueCoding.ValueAccessor
extends Object

NSKeyValueCoding.ValueAccessor is an abstract class that establishes a mechanism by which NSKeyValueCoding can operate on object's package access instance variables.

By default, Foundation's implementations of NSKeyValueCoding cannot access package access instance variables. If you have package access instance variables in your NSKeyValueCoding objects, you can make them available to key-value coding in one of the three ways:

The best solution is to implement accessor methods or to make the instance variables public. However, if you have a lot of classes with a lot of package access instance variables, you can use the short-term solution that NSKeyValueCoding.ValueAccessor provides until you make the necessary changes to your code.

To use NSKeyValueCoding.ValueAccessor's mechanism, simply create a class in your package as follows:

           <blockquote>

           package yourPackage;
           import java.lang.reflect.*;
           import com.webobjects.foundation.*;

           public class KeyValueCodingProtectedAccessor extends
                                                   NSKeyValueCoding.ValueAccessor {

             public KeyValueCodingProtectedAccessor() {
               super();
             }

             public Object fieldValue(Object object, Field field) throws
                              IllegalArgumentException, IllegalAccessException {
               return field.get(object);
             }

             public void setFieldValue(Object object, Field field, Object value) throws
                              IllegalArgumentException, IllegalAccessException {
               field.set(object, value);
             }

             public Object methodValue(Object object, Method method) throws
                   IllegalArgumentException, IllegalAccessException,
                                                        java.lang.reflect.InvocationTargetException {
               return method.invoke(object);
             }

             public void setMethodValue(Object object, Method method, Object value) throws
                   IllegalArgumentException, IllegalAccessException,
                                                           java.lang.reflect.InvocationTargetException {
               method.invoke(object, new Object[] {value});
             }
           }
           </blockquote>
 

See Also:
NSKeyValueCoding

Constructor Summary
NSKeyValueCoding.ValueAccessor()
          empty constructor is required for subclasses implementing the ValueAccessor interface
 
Method Summary
abstract  Object fieldValue(Object object, Field field)
           
abstract  Object methodValue(Object object, Method method)
          Uses method to return object's corresponding property value.
static NSKeyValueCoding.ValueAccessor protectedAccessorForPackageNamed(String packageName)
           
static void removeProtectedAccessorForPackageNamed(String packageName)
          Removes (unregisters) the value accessor for the package identified by packageName.
abstract  void setFieldValue(Object object, Field field, Object value)
          Sets object's field value to value.
abstract  void setMethodValue(Object object, Method method, Object value)
          Uses method to set object's corresponding property to value.
static void setProtectedAccessorForPackageNamed(NSKeyValueCoding.ValueAccessor valueAccessor, String packageName)
          Sets the value accessor for the package identified by packageName to valueAccessor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NSKeyValueCoding.ValueAccessor

public NSKeyValueCoding.ValueAccessor()
empty constructor is required for subclasses implementing the ValueAccessor interface

Method Detail

setProtectedAccessorForPackageNamed

public static void setProtectedAccessorForPackageNamed(NSKeyValueCoding.ValueAccessor valueAccessor,
                                                       String packageName)
Sets the value accessor for the package identified by packageName to valueAccessor.

Parameters:
valueAccessor - the value accessor for the package identified by packageName
packageName - the value accessor for the package is identified by this

protectedAccessorForPackageNamed

public static NSKeyValueCoding.ValueAccessor protectedAccessorForPackageNamed(String packageName)
Parameters:
packageName - the package identified to be operated on
Returns:
the value accessor for the package identified by packageName

removeProtectedAccessorForPackageNamed

public static void removeProtectedAccessorForPackageNamed(String packageName)
Removes (unregisters) the value accessor for the package identified by packageName.

Parameters:
packageName - the package identified to be operated on

fieldValue

public abstract Object fieldValue(Object object,
                                  Field field)
                           throws IllegalArgumentException,
                                  IllegalAccessException
Parameters:
object - the object whose package access instance variables are to be operated on
field - the value of object's field
Returns:
object's field
Throws:
IllegalArgumentException
IllegalAccessException

setFieldValue

public abstract void setFieldValue(Object object,
                                   Field field,
                                   Object value)
                            throws IllegalArgumentException,
                                   IllegalAccessException
Sets object's field value to value.

Parameters:
object - the object whose package access instance variables are to be operated on
field - object's property whose value is to be set
value - object's property identified by field is set to this
Throws:
IllegalArgumentException
IllegalAccessException

methodValue

public abstract Object methodValue(Object object,
                                   Method method)
                            throws IllegalArgumentException,
                                   IllegalAccessException,
                                   InvocationTargetException
Uses method to return object's corresponding property value.

Parameters:
object - the object whose package access instance variables are to be operated on
method - instance variables of the object
Returns:
object's corresponding property value
Throws:
IllegalArgumentException
IllegalAccessException
InvocationTargetException

setMethodValue

public abstract void setMethodValue(Object object,
                                    Method method,
                                    Object value)
                             throws IllegalArgumentException,
                                    IllegalAccessException,
                                    InvocationTargetException
Uses method to set object's corresponding property to value.

Parameters:
object - the object whose package access instance variables are to be operated on
method - instance variables of the object
value - object's field identified by field is set to this
Throws:
IllegalArgumentException
IllegalAccessException
InvocationTargetException

Last updated June 2008

Copyright © 2000-2008 Apple Inc.