Class ObjectIndexedPropertyDescriptor
- java.lang.Object
-
- java.beans.FeatureDescriptor
-
- java.beans.PropertyDescriptor
-
- org.apache.commons.ognl.ObjectIndexedPropertyDescriptor
-
public class ObjectIndexedPropertyDescriptor extends PropertyDescriptor
PropertyDescriptor subclass that describes an indexed set of read/write methods to get a property. Unlike IndexedPropertyDescriptor this allows the "key" to be an arbitrary object rather than just an int. Consequently it does not have a "readMethod" or "writeMethod" because it only expects a pattern like:
public void setProperty(KeyType, ValueType); public ValueType getProperty(KeyType);
and does not require the methods that access it as an array. OGNL can get away with this without losing functionality because if the object does expose the properties they are most probably in a Map and that case is handled by the normal OGNL property accessors.
For example, if an object were to have methods that accessed and "attributes" property it would be natural to index them by String rather than by integer and expose the attributes as a map with a different property name:
public void setAttribute( String name, Object value ); public Object getAttribute( String name ); public Map getAttributes();
Note that the index get/set is called get/set
Attribute
whereas the collection getter is calledAttributes
. This case is handled unambiguously by the OGNL property accessors because the set/getAttribute
methods are detected by this object and the "attributes" case is handled by theMapPropertyAccessor
. Therefore OGNL expressions calling this code would be handled in the following way:OGNL Expression Handling attribute["name"]
Handled by an index getter, like getAttribute(String)
.attribute["name"] = value
Handled by an index setter, like setAttribute(String, Object)
.attributes["name"]
Handled by MapPropertyAccessor
via aMap.get()
. This will not go through the index get accessor.attributes["name"] = value
Handled by MapPropertyAccessor
via aMap.put()
. This will not go through the index set accessor.
-
-
Constructor Summary
Constructors Constructor Description ObjectIndexedPropertyDescriptor(String propertyName, Class<?> propertyType, Method indexedReadMethod, Method indexedWriteMethod)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Method
getIndexedReadMethod()
Method
getIndexedWriteMethod()
Class<?>
getPropertyType()
int
hashCode()
-
Methods inherited from class java.beans.PropertyDescriptor
createPropertyEditor, getPropertyEditorClass, getReadMethod, getWriteMethod, isBound, isConstrained, setBound, setConstrained, setPropertyEditorClass, setReadMethod, setWriteMethod
-
Methods inherited from class java.beans.FeatureDescriptor
attributeNames, getDisplayName, getName, getShortDescription, getValue, isExpert, isHidden, isPreferred, setDisplayName, setExpert, setHidden, setName, setPreferred, setShortDescription, setValue, toString
-
-
-
-
Constructor Detail
-
ObjectIndexedPropertyDescriptor
public ObjectIndexedPropertyDescriptor(String propertyName, Class<?> propertyType, Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException
- Throws:
IntrospectionException
-
-
Method Detail
-
getIndexedReadMethod
public Method getIndexedReadMethod()
-
getIndexedWriteMethod
public Method getIndexedWriteMethod()
-
getPropertyType
public Class<?> getPropertyType()
- Overrides:
getPropertyType
in classPropertyDescriptor
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classPropertyDescriptor
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classPropertyDescriptor
-
-