ariba.util.fieldvalue
Class FieldValue

java.lang.Object
  extended by ariba.util.core.ClassExtension
      extended by ariba.util.fieldvalue.FieldValue
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
FieldValue_Object

public abstract class FieldValue
extends ClassExtension

The FieldValue class defines a ClassExtension for JavaBean-like property access on target objects. Static methods getFieldValue(Object, String) and setFieldValue(Object, String, Object) are provided for convenience. Higher performance access can be achieved by caching FieldPath instances for particular key paths. Not only does that avoid per-access accessor lookup, but the field path caches FieldValueSetter and FieldValueGetter instances from its most recent lookup and can reuse them if the next access targets the same class.

The default implementation of FieldValue is FieldValue_Object -- it resolves property access using reflection to get/set using accessor methods or direct field access. (note that, unlike JavaBeans, FieldValue_Object will resolve a get on key "foo" by checking for foo(), getFoo, and the fields named foo and _foo).

Other specialized implementation of FieldValue exist for Maps, XML Nodes, etc.


Field Summary
static int Getter
           
static int Setter
           
 
Fields inherited from class ariba.util.core.ClassExtension
forClass
 
Constructor Summary
FieldValue()
           
 
Method Summary
abstract  FieldValueAccessor createAccessor(java.lang.Object target, java.lang.String fieldName, int type)
          Creates and returns a new FieldValueAccessor (by default, a ReflectionFieldValueAccessor) for the given target and fieldName.
static FieldValue get(java.lang.Class targetClass)
          Retrieve a ClassExtension registered by registerClassExtension(...).
static FieldValue get(java.lang.Object target)
           
abstract  FieldValueAccessor getAccessor(java.lang.Object target, java.lang.String fieldName, int type)
          Maintains a cache of FieldValueAccessor's for the instance by fieldName.
abstract  java.lang.Object getFieldValue(java.lang.Object target, FieldPath fieldPath)
          Recursively calls getFieldValuePrimitive() with the head of the fieldPath list.
static java.lang.Object getFieldValue(java.lang.Object target, java.lang.String fieldPathString)
          Converts fieldPathString into a FieldPath (from a pool of shared FieldPaths) and calls getFieldValue(FieldPath).
abstract  java.lang.Object getFieldValuePrimitive(java.lang.Object target, FieldPath fieldPath)
          Gets the value from the reveiver using the fieldName indicated by fieldPath -- only the first node of the fieldPath is considered if it is a multi-node path.
 void populateFieldInfo(java.lang.Class targetClass, FieldInfo.Collection collection)
          Called by FieldInfo.fieldInfoForClass() to populate FieldInfo.Collection with information on available fields.
static void registerClassExtension(java.lang.Class targetObjectClass, FieldValue fieldValueClassExtension)
          Put a ClassExtension implementation of the FieldValue interface into the cache of categories which is used to dispatch the FieldValue cover methods in this class.
abstract  void setFieldValue(java.lang.Object target, FieldPath fieldPath, java.lang.Object value)
          Recursively calls getFieldValuePrimitive() with the head of the fieldPath list up to the last fieldPath node and then calls setFieldValuePrimitive().
static void setFieldValue(java.lang.Object target, java.lang.String fieldPathString, java.lang.Object value)
          Converts fieldPathString into a FieldPath (from a pool of shared FieldPaths) and calls setFieldValue(FieldPath, Object).
abstract  void setFieldValuePrimitive(java.lang.Object target, FieldPath fieldPath, java.lang.Object value)
          Sets the value on the reveiver using the fieldName indicated by fieldPath -- only the first node of the fieldPath is considered if it is a multi-node path.
 
Methods inherited from class ariba.util.core.ClassExtension
clone, forClass, getRealClass, setForClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Setter

public static final int Setter
See Also:
Constant Field Values

Getter

public static final int Getter
See Also:
Constant Field Values
Constructor Detail

FieldValue

public FieldValue()
Method Detail

registerClassExtension

public static void registerClassExtension(java.lang.Class targetObjectClass,
                                          FieldValue fieldValueClassExtension)
Put a ClassExtension implementation of the FieldValue interface into the cache of categories which is used to dispatch the FieldValue cover methods in this class. Note that the FieldValue_Object will be cloned before caching, so you cannot depend upon getting back the exact same instance later with get(...).

Parameters:
targetObjectClass - the root class for which the classExtension applies
fieldValueClassExtension - the classExtension implementation of the FieldValue interface

get

public static FieldValue get(java.lang.Class targetClass)
Retrieve a ClassExtension registered by registerClassExtension(...). Note that this will clone the ClassExtension objects which are registered so that each subclass will have its own classExtension implementation. See ClassExtensionRegistry for details on this.

Parameters:
targetClass - the class for which a classExtension applies
Returns:
the classExtension which applies for the target

get

public static FieldValue get(java.lang.Object target)

setFieldValue

public static void setFieldValue(java.lang.Object target,
                                 java.lang.String fieldPathString,
                                 java.lang.Object value)
Converts fieldPathString into a FieldPath (from a pool of shared FieldPaths) and calls setFieldValue(FieldPath, Object).

Parameters:
target - see the FieldPath version of this method
fieldPathString - the dotted fieldPath String from which a shared FieldPath instance will be obtained
value - see the FieldPath version of this method

getFieldValue

public static java.lang.Object getFieldValue(java.lang.Object target,
                                             java.lang.String fieldPathString)
Converts fieldPathString into a FieldPath (from a pool of shared FieldPaths) and calls getFieldValue(FieldPath).

Parameters:
target - see the FieldPath version of this method
fieldPathString - the dotted fieldPath String from which a shared FieldPath instance will be obtained
Returns:
see the FieldPath version of this method

createAccessor

public abstract FieldValueAccessor createAccessor(java.lang.Object target,
                                                  java.lang.String fieldName,
                                                  int type)
Creates and returns a new FieldValueAccessor (by default, a ReflectionFieldValueAccessor) for the given target and fieldName. No caching is done by this method. This method is designed to be overridden by subclasses of FieldValue_Object which want to define their own specialized accessors. Note that the target is passed rather than its class so that accessors can be created at a finer granularity than class. Certain meta-data driven classes require this flexibility.

Parameters:
target - the object for which the accessor will be created
fieldName - the name of the field for which the accessor will be created
Returns:
a new FieldValueAccessor (ReflectionFieldValueAccessor by default)

getAccessor

public abstract FieldValueAccessor getAccessor(java.lang.Object target,
                                               java.lang.String fieldName,
                                               int type)
Maintains a cache of FieldValueAccessor's for the instance by fieldName. In general, all instances of a given class will share the same FieldValueAccessor for a given fieldName. However, certain meta-data driven classes may need to introspect upon the instance before returning the proper accessor.

Parameters:
target - the object for which the accessor will be looked up
fieldName - the name of the field for the accessor
Returns:
the cached FieldValueAccessor (ReflectionFieldValueAccessor by default)

setFieldValuePrimitive

public abstract void setFieldValuePrimitive(java.lang.Object target,
                                            FieldPath fieldPath,
                                            java.lang.Object value)
Sets the value on the reveiver using the fieldName indicated by fieldPath -- only the first node of the fieldPath is considered if it is a multi-node path.

Parameters:
target - the object on which the value will be set for the field identiifed by fieldPath
fieldPath - the fieldPath node (which contains a candidate accessor) to be used to set the value on target.
value - the value to set on the target

getFieldValuePrimitive

public abstract java.lang.Object getFieldValuePrimitive(java.lang.Object target,
                                                        FieldPath fieldPath)
Gets the value from the reveiver using the fieldName indicated by fieldPath -- only the first node of the fieldPath is considered if it is a multi-node path.

Parameters:
target - the object from which to get the value of the field identified by fieldPath
fieldPath - the fieldPath node which identifes the field to get.
Returns:
the value obtained from the target using the fieldPath

setFieldValue

public abstract void setFieldValue(java.lang.Object target,
                                   FieldPath fieldPath,
                                   java.lang.Object value)
Recursively calls getFieldValuePrimitive() with the head of the fieldPath list up to the last fieldPath node and then calls setFieldValuePrimitive(). Each time the recursion iterates, the receiver is the value of the previous getFieldValuePrimitive().

Parameters:
target - the object on which to start the recursion for setting the value using the fieldPath
fieldPath - the linked list of fieldPath nodes used to navigate from target to the final object in the chain, upon which the value is set
value - the value which is set on the final object in the chain

getFieldValue

public abstract java.lang.Object getFieldValue(java.lang.Object target,
                                               FieldPath fieldPath)
Recursively calls getFieldValuePrimitive() with the head of the fieldPath list. Each time the recursion iterates, the receiver is the value of the previous getFieldValuePrimitive().

Parameters:
target - the first object from which to start the recursion for getting the value identified by the fieldPath.
fieldPath - the linked list of fieldPath nodes that identifes the value to get
Returns:
the value obtained from the last object in the chain

populateFieldInfo

public void populateFieldInfo(java.lang.Class targetClass,
                              FieldInfo.Collection collection)
Called by FieldInfo.fieldInfoForClass() to populate FieldInfo.Collection with information on available fields. Implementing FieldValue extensions should callback with FieldInfo.Collection.updateFieldInfo() to provide information for all usable fields. Fields should be populated in a first-declaration-first manner -- i.e. super class before class, fields in java declaraion order where possible -- registration order is used to determine the "rank" recorded on the field.

Parameters:
targetClass - class for which info should be provided.
collection - repository to populate


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.