PATH Documentation > WebObjects

Table of Contents

NSKeyValueCoding.ValueAccessor


Inherits from:
Object
Package:
com.webobjects.foundation


Class Description


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

By default, Foundation's implementations of NSKeyValueCoding can't 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:


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

public class KeyValueCodingProtectedAccessor extends NSKeyValueCoding.ValueAccessor {

    public KeyValueCodingProtectedAccessor() {
        super();
    }

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

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

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

    public void setMethodValue(Method method, Object value, Object object) throws
    IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        method.invoke(object, new Object[] {value});
    }
}




Constructors



NSKeyValueCoding.ValueAccessor

public NSKeyValueCoding.ValueAccessor()

The no-arg constructor. Don't use this method; because NSKeyValueCoding.ValueAccessor is an abstract class, you can never create an instance of it.


Static Methods



protectedAccessorForPackageNamed

public static NSKeyValueCoding.ValueAccessor protectedAccessorForPackageNamed( String packageName)

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.

setProtectedAccessorForPackageWithNamed

public static void setProtectedAccessorForPackageNamed( NSKeyValueCoding.ValueAccessor accessor, String packageName)

Sets the value accessor for the package identified by packageName to accessor.


Instance Methods



fieldValue

public abstract Object fieldValue( Object object, reflect.Field field) throws IllegalArgumentException, IllegalAccessException

Returns the value of object's field.

methodValue

public abstract Object methodValue( Object object, reflect.Method method) throws IllegalArgumentException, IllegalAccessException, reflect.InvocationTargetException

Uses method to return object's corresponding property value.

setFieldValue

public abstract void setFieldValue( Object object, reflect.Field field, Object value) throws IllegalArgumentException, IllegalAccessException

Sets object's field value to value.

setMethodValue

public abstract void setMethodValue( Object object, reflect.Method method, Object value) throws IllegalArgumentException, IllegalAccessException, reflect.InvocationTargetException

Uses method to set object's corresponding property to value.

© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents