|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.kuali.rice.krad.uif.util.ObjectPropertyUtils
public final class ObjectPropertyUtils
Utility methods to get/set property values and working with objects.
Method Summary | ||
---|---|---|
static void |
copyPropertiesToObject(Map<String,String> properties,
Object object)
Copy properties from a string map to an object. |
|
static Type |
findGenericType(Class<?> sourceClass,
Class<?> targetClass)
Locate the generic type declaration for a given target class in the generic type hierarchy of the source class. |
|
static List<Field> |
getAllFields(List<Field> fields,
Class<?> type,
Class<?> stopAt)
Returns an List of Field objects reflecting all the fields
declared by the class or interface represented by this
Class object. |
|
static Type |
getComponentType(Type type)
Get the best known component type for a generic type. |
|
static PropertyDescriptor |
getPropertyDescriptor(Class<?> beanClass,
String propertyName)
Get a property descriptor from a class by property name. |
|
static Map<String,PropertyDescriptor> |
getPropertyDescriptors(Class<?> beanClass)
Get a mapping of property descriptors by property name for a bean class. |
|
static Class<?> |
getPropertyType(Class<?> beanClass,
String propertyPath)
Get the type of a bean property. |
|
static Class<?> |
getPropertyType(Object object,
String propertyPath)
Get the type of a bean property. |
|
static
|
getPropertyValue(Object object,
String propertyPath)
Look up a property value. |
|
static Set<String> |
getReadablePropertyNames(Class<?> beanClass)
Gets the names of all readable properties for the bean class. |
|
static Set<String> |
getReadablePropertyNamesByAnnotationType(Class<?> beanClass,
Class<? extends Annotation> annotationType)
Gets the property names by annotation type, based on the read methods. |
|
static Set<String> |
getReadablePropertyNamesByAnnotationType(Object bean,
Class<? extends Annotation> annotationType)
Gets the property names by annotation type, based on the read methods. |
|
static Set<String> |
getReadablePropertyNamesByCollectionType(Class<?> beanClass,
Class<?> collectionType)
Gets the property names by collection type, based on the read methods. |
|
static Set<String> |
getReadablePropertyNamesByCollectionType(Object bean,
Class<?> collectionType)
Gets the property names by collection type, based on the read methods. |
|
static Set<String> |
getReadablePropertyNamesByType(Class<?> beanClass,
Class<?> propertyType)
Gets the property names by property type, based on the read methods. |
|
static Set<String> |
getReadablePropertyNamesByType(Object bean,
Class<?> propertyType)
Gets the property names by property type, based on the read methods. |
|
static Method |
getReadMethod(Class<?> beanClass,
String propertyName)
Get the read method for a specific property on a bean class. |
|
static Class<?> |
getUpperBound(Type valueType)
Get the upper bound of a generic type. |
|
static Set<String> |
getWritablePropertyNames(Object bean)
Gets the property names for the given object that are writable |
|
static Method |
getWriteMethod(Class<?> beanClass,
String propertyName)
Get the read method for a specific property on a bean class. |
|
static void |
initializeProperty(Object object,
String propertyPath)
Initialize a property value. |
|
static boolean |
isReadableProperty(Object object,
String propertyPath)
Determine if a property is readable. |
|
static boolean |
isWritableProperty(Object object,
String propertyPath)
Determine if a property is writable. |
|
static void |
setPropertyValue(Object object,
String propertyPath,
Object propertyValue)
Modify a property value. |
|
static void |
setPropertyValue(Object object,
String propertyPath,
Object propertyValue,
boolean ignoreUnknown)
Modify a property value. |
|
static String[] |
splitPropertyPath(String path)
Splits the given property path into a string of property names that make up the path. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Map<String,PropertyDescriptor> getPropertyDescriptors(Class<?> beanClass)
beanClass
- The bean class.
public static PropertyDescriptor getPropertyDescriptor(Class<?> beanClass, String propertyName)
beanClass
- The bean class.propertyName
- The bean property name.
public static Set<String> getReadablePropertyNames(Class<?> beanClass)
beanClass
- The bean class.
public static Method getReadMethod(Class<?> beanClass, String propertyName)
beanClass
- The bean class.propertyName
- The property name.
public static Method getWriteMethod(Class<?> beanClass, String propertyName)
beanClass
- The bean class.propertyName
- The property name.
public static void copyPropertiesToObject(Map<String,String> properties, Object object)
properties
- The string map. The keys of this map must be valid property path
expressions in the context of the target object. The values are the string
representations of the target bean properties.object
- The target object, to copy the property values to.ObjectPathExpressionParser
public static Class<?> getPropertyType(Class<?> beanClass, String propertyPath)
Note that this method does not instantiate the bean class before performing introspection, so
will not dynamic initialization behavior into account. When dynamic initialization is needed
to accurate inspect the inferred property type, use getPropertyType(Object, String)
instead of this method. This method is, however, intended for use on the implementation
class; to avoid instantiation simply to infer the property type, consider overriding the
return type on the property read method.
beanClass
- The bean class.propertyPath
- A valid property path expression in the context of the bean class.
ObjectPathExpressionParser
public static Class<?> getPropertyType(Object object, String propertyPath)
object
- The bean instance. Use getPropertyType(Class, String)
to look up
property types when an instance is not available.propertyPath
- A valid property path expression in the context of the bean.
ObjectPathExpressionParser
public static Set<String> getReadablePropertyNamesByType(Object bean, Class<?> propertyType)
bean
- The bean.propertyType
- The return type of the read method on the property.
public static Set<String> getReadablePropertyNamesByType(Class<?> beanClass, Class<?> propertyType)
beanClass
- The bean class.propertyType
- The return type of the read method on the property.
public static Set<String> getReadablePropertyNamesByAnnotationType(Object bean, Class<? extends Annotation> annotationType)
bean
- The bean.annotationType
- The type of an annotation on the return type.
public static Set<String> getReadablePropertyNamesByAnnotationType(Class<?> beanClass, Class<? extends Annotation> annotationType)
beanClass
- The bean class.annotationType
- The type of an annotation on the return type.
public static Set<String> getReadablePropertyNamesByCollectionType(Object bean, Class<?> collectionType)
bean
- The bean.collectionType
- The type of elements in a collection or array.
public static Set<String> getWritablePropertyNames(Object bean)
bean
- object to get writable property names for
public static Set<String> getReadablePropertyNamesByCollectionType(Class<?> beanClass, Class<?> collectionType)
beanClass
- The bean class.collectionType
- The type of elements in a collection or array.
public static <T> T getPropertyValue(Object object, String propertyPath)
T
- property typeobject
- The bean instance to look up a property value for.propertyPath
- A valid property path expression in the context of the bean.
ObjectPathExpressionParser
public static void initializeProperty(Object object, String propertyPath)
Upon returning from this method, the property referred to by the provided bean and property path will have been initialized with a default instance of the indicated property type.
object
- The bean instance to initialize a property value for.propertyPath
- A valid property path expression in the context of the bean.getPropertyType(Object, String)
,
setPropertyValue(Object, String, Object)
,
ObjectPathExpressionParser
public static void setPropertyValue(Object object, String propertyPath, Object propertyValue)
Upon returning from this method, the property referred to by the provided bean and property
path will have been populated with property value provided. If the propertyValue does not
match the type of the indicated property, then type conversion will be attempted using
PropertyEditorManager
.
object
- The bean instance to initialize a property value for.propertyPath
- A valid property path expression in the context of the bean.propertyValue
- The value to populate value in the property referred to by the provided
bean and property path.
RuntimeException
- If the property path is not valid in the context of the bean
provided.ObjectPathExpressionParser
public static void setPropertyValue(Object object, String propertyPath, Object propertyValue, boolean ignoreUnknown)
Upon returning from this method, the property referred to by the provided bean and property
path will have been populated with property value provided. If the propertyValue does not
match the type of the indicated property, then type conversion will be attempted using
PropertyEditorManager
.
object
- The bean instance to initialize a property value for.propertyPath
- A property path expression in the context of the bean.propertyValue
- The value to populate value in the property referred to by the provided
bean and property path.ignoreUnknown
- True if invalid property values should be ignored, false to throw a
RuntimeException if the property reference is invalid.ObjectPathExpressionParser
public static boolean isReadableProperty(Object object, String propertyPath)
object
- The bean instance to initialize a property value for.propertyPath
- A property path expression in the context of the bean.
public static boolean isWritableProperty(Object object, String propertyPath)
object
- The bean instance to initialize a property value for.propertyPath
- A property path expression in the context of the bean.
public static List<Field> getAllFields(List<Field> fields, Class<?> type, Class<?> stopAt)
Field
objects reflecting all the fields
declared by the class or interface represented by this
Class
object. This includes public, protected, default
(package) access, and private fields, and includes inherited fields.
fields
- A list of Field
objects which gets returned.type
- Type of class or interface for which fields are returned.stopAt
- The Superclass upto which the inherited fields are to be included
public static Type getComponentType(Type type)
When the type is not parameterized or has no explicitly defined parameters, Object
is
returned.
When the type has multiple parameters, the right-most parameter is considered the component type. This facilitates identifying the value type of a Map.
type
- The generic collection or map type.
public static Class<?> getUpperBound(Type valueType)
When the type is a class, the class is returned.
When the type is a wildcard, and the upper bound is a class, the upper bound of the wildcard is returned.
If the type has not been explicitly defined at compile time, Object
is returned.
valueType
- The generic collection or map type.
public static Type findGenericType(Class<?> sourceClass, Class<?> targetClass)
sourceClass
- The class representing the generic type hierarchy to scan.targetClass
- The class representing the generic type declaration to locate within the
source class' hierarchy.
public static String[] splitPropertyPath(String path)
path
- property path to split
SplitPropertyPathEntry#parse(String, Object, String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |