public final class PropertyUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static PropertyDescriptor |
getPropertyDescriptor(Class<?> domainType,
String expression)
Given a property expression which contains CamelCase words will try to look up the property path
leading up to the appropriate nested property.
|
static String |
getPropertyName(Method getter)
Given a getter method finds out the property name for the getter
|
static Object |
getPropertyValue(Object context,
String property)
Given a property path will find out the proper way of accessing that property and
return the value given the current context.
|
static Class<?> |
getTypeOf(Class<?> type)
Returns the object type for the provided type.
|
static Object |
setPropertyValue(Object context,
String property,
Object value)
Sets the value of the given property to the provided value.
|
public static Object getPropertyValue(Object context, String property)
Given a property path will find out the proper way of accessing that property and return the value given the current context. The property path can use the "dot notation" to indicate nested properties (so that "x.y.z" would mean context.getX().getY().getZ()).
Properties can be accessed via getter methods or fields, with getter methods taking precedence. If a property doesn't exist at any given point, an error will be raised. If any property is set to null, the chain evaluation will stop and null will be returned. This means that if we are requesting access to the valid nested property x.y.z, and y is null, instead of failing with an error, the reader will return null.
context - the object to evaluate the property path againstproperty - the property path as outlined abovepublic static Object setPropertyValue(Object context, String property, Object value)
getPropertyValue(Object, String), with the exception that if any
of the parent properties in the nested path leading to the very last property (the one being modified)
is null an exception is thrown.context - the context against which the property path will be evaluatedproperty - the property pathvalue - the value to set for the propertypublic static PropertyDescriptor getPropertyDescriptor(Class<?> domainType, String expression)
Given a property expression which contains CamelCase words will try to look up the property path leading up to the appropriate nested property. Property names will be matched eagerly, so that expression XxYy will match property XxYy if it exists, rather than Xx first.
If you wan to force the parser to avoid eager evaluation, you can insert an underscore (_) character in place of the nested property separator. Thus, Xx_Yy will force the parser to consider Xx and only that property will satisfy the parser.
domainType - the domain type that will be used to evaluate the property expressionexpression - the property expression as explained abovegetPropertyValue(Object, String))
to let us read from and write to the described property.public static Class<?> getTypeOf(Class<?> type)
type - the type to find out the object type forCopyright © 2014–2016. All rights reserved.