PATH |
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:
- Implement public setKey and key accessor methods for those instance variables that set and return the instance variables' values.
- Make the instance variables public.
- Add a subclass of NSKeyValueCoding.ValueAccessor named KeyValueCodingProtectedAccessor to your package. This class provides a mechanism to manipulate package access instance variables.
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()
Static Methods
protectedAccessorForPackageNamed
public static NSKeyValueCoding.ValueAccessor protectedAccessorForPackageNamed( String packageName)
removeProtectedAccessorForPackageNamed
public static void removeProtectedAccessorForPackageNamed( String packageName)
setProtectedAccessorForPackageWithNamed
public static void setProtectedAccessorForPackageNamed( NSKeyValueCoding.ValueAccessor accessor, String packageName)
Instance Methods
fieldValue
public abstract Object fieldValue( Object object, reflect.Field field) throws IllegalArgumentException, IllegalAccessException
methodValue
public abstract Object methodValue( Object object, reflect.Method method) throws IllegalArgumentException, IllegalAccessException, reflect.InvocationTargetException
setFieldValue
public abstract void setFieldValue( Object object, reflect.Field field, Object value) throws IllegalArgumentException, IllegalAccessException
setMethodValue
public abstract void setMethodValue( Object object, reflect.Method method, Object value) throws IllegalArgumentException, IllegalAccessException, reflect.InvocationTargetException
© 2001 Apple Computer, Inc. (Last Published April 17, 2001)