Package org.apache.commons.jxpath.util
Class ValueUtils
java.lang.Object
org.apache.commons.jxpath.util.ValueUtils
Collection and property access utilities.
- Version:
- $Revision: 670728 $ $Date: 2008-06-23 15:12:44 -0500 (Mon, 23 Jun 2008) $
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Object
Convert value to type.static Object
expandCollection
(Object collection, int size) Grows the collection if necessary to the specified size.static Method
getAccessibleMethod
(Method method) Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method.private static Method
getAccessibleMethodFromInterfaceNest
(Class clazz, String methodName, Class[] parameterTypes) Return an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented interfaces and subinterfaces.static int
getCollectionHint
(Class clazz) Returns 1 if the type is a collection, -1 if it is definitely not and 0 if it may be a collection in some cases.static DynamicPropertyHandler
getDynamicPropertyHandler
(Class clazz) Returns a shared instance of the dynamic property handler class returned bygetDynamicPropertyHandlerClass()
.static int
getIndexedPropertyLength
(Object object, IndexedPropertyDescriptor pd) If there is a regular non-indexed read method for this property, uses this method to obtain the collection and then returns its length.static int
Returns the length of the supplied collection.static Object
If the parameter is a container, opens the container and return the contents.static Object
Returns the index'th element of the supplied collection.static Object
getValue
(Object bean, PropertyDescriptor propertyDescriptor) Returns the value of the bean's property represented by the supplied property descriptor.static Object
getValue
(Object bean, PropertyDescriptor propertyDescriptor, int index) Returns the index'th element of the bean's property represented by the supplied property descriptor.static boolean
isCollection
(Object value) Returns true if the object is an array or a Collection.static Iterator
Returns an iterator for the supplied collection.static Object
Remove the index'th element from the supplied collection.static void
Modifies the index'th element of the supplied collection.static void
setValue
(Object bean, PropertyDescriptor propertyDescriptor, int index, Object value) Modifies the index'th element of the bean's property represented by the supplied property descriptor.static void
setValue
(Object bean, PropertyDescriptor propertyDescriptor, Object value) Modifies the value of the bean's property represented by the supplied property descriptor.
-
Field Details
-
dynamicPropertyHandlerMap
-
UNKNOWN_LENGTH_MAX_COUNT
private static final int UNKNOWN_LENGTH_MAX_COUNT- See Also:
-
-
Constructor Details
-
ValueUtils
public ValueUtils()
-
-
Method Details
-
isCollection
Returns true if the object is an array or a Collection.- Parameters:
value
- to test- Returns:
- boolean
-
getCollectionHint
Returns 1 if the type is a collection, -1 if it is definitely not and 0 if it may be a collection in some cases.- Parameters:
clazz
- to test- Returns:
- int
-
getIndexedPropertyLength
If there is a regular non-indexed read method for this property, uses this method to obtain the collection and then returns its length. Otherwise, attempts to guess the length of the collection by calling the indexed get method repeatedly. The method is supposed to throw an exception if the index is out of bounds.- Parameters:
object
- collectionpd
- IndexedPropertyDescriptor- Returns:
- int
-
getLength
Returns the length of the supplied collection. If the supplied object is not a collection, returns 1. If collection is null, returns 0.- Parameters:
collection
- to check- Returns:
- int
-
iterate
Returns an iterator for the supplied collection. If the argument is null, returns an empty iterator. If the argument is not a collection, returns an iterator that produces just that one object.- Parameters:
collection
- to iterate- Returns:
- Iterator
-
expandCollection
Grows the collection if necessary to the specified size. Returns the new, expanded collection.- Parameters:
collection
- to expandsize
- desired size- Returns:
- collection or array
-
remove
Remove the index'th element from the supplied collection.- Parameters:
collection
- to editindex
- int- Returns:
- the resulting collection
-
getValue
Returns the index'th element of the supplied collection.- Parameters:
collection
- to readindex
- int- Returns:
- collection[index]
-
setValue
Modifies the index'th element of the supplied collection. Converts the value to the required type if necessary.- Parameters:
collection
- to editindex
- to replacevalue
- new value
-
getValue
Returns the value of the bean's property represented by the supplied property descriptor.- Parameters:
bean
- to readpropertyDescriptor
- indicating what to read- Returns:
- Object value
-
setValue
Modifies the value of the bean's property represented by the supplied property descriptor.- Parameters:
bean
- to readpropertyDescriptor
- indicating what to readvalue
- to set
-
convert
Convert value to type.- Parameters:
value
- Objecttype
- destination- Returns:
- conversion result
-
getValue
Returns the index'th element of the bean's property represented by the supplied property descriptor.- Parameters:
bean
- to readpropertyDescriptor
- indicating what to readindex
- int- Returns:
- Object
-
setValue
public static void setValue(Object bean, PropertyDescriptor propertyDescriptor, int index, Object value) Modifies the index'th element of the bean's property represented by the supplied property descriptor. Converts the value to the required type if necessary.- Parameters:
bean
- to editpropertyDescriptor
- indicating what to setindex
- intvalue
- to set
-
getValue
If the parameter is a container, opens the container and return the contents. The method is recursive.- Parameters:
object
- to read- Returns:
- Object
-
getDynamicPropertyHandler
Returns a shared instance of the dynamic property handler class returned bygetDynamicPropertyHandlerClass()
.- Parameters:
clazz
- to handle- Returns:
- DynamicPropertyHandler
-
getAccessibleMethod
Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, returnnull
.- Parameters:
method
- The method that we wish to call- Returns:
- Method
-
getAccessibleMethodFromInterfaceNest
private static Method getAccessibleMethodFromInterfaceNest(Class clazz, String methodName, Class[] parameterTypes) Return an accessible method (that is, one that can be invoked via reflection) that implements the specified method, by scanning through all implemented interfaces and subinterfaces. If no such Method can be found, returnnull
.- Parameters:
clazz
- Parent class for the interfaces to be checkedmethodName
- Method name of the method we wish to callparameterTypes
- The parameter type signatures- Returns:
- Method
-