|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.sape.carbon.core.util.reflection.BeanUtil
This class implements the ability to get and set properties on a
bean. This included the concept of embedded properties that may
be referenced like Bean.property.property.property
.
Field Summary | |
private static Object[] |
NO_ARGUMENTS_ARRAY
an empty object array used for null parameter method reflection |
private static Class[] |
NO_PARAMETERS_ARRAY
An empty class array used for null parameter method reflection |
private static String |
PROPERTY_SEPARATOR
String used to separate multiple properties inside of embedded beans. |
Constructor Summary | |
private |
BeanUtil()
The constructor is private so that new cannot be used. |
Method Summary | |
static Object |
getObjectAttribute(Object bean,
String propertyNames)
Gets the specified attribute from the specified object. |
private static PropertyDescriptor |
getPropertyDescriptor(String propertyName,
Class beanClass)
Retreives a property descriptor object for a given property. |
static void |
setObjectAttribute(Object bean,
String propertyNames,
Object value)
Sets the specified attribute on the specified object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final String PROPERTY_SEPARATOR
private static Class[] NO_PARAMETERS_ARRAY
private static Object[] NO_ARGUMENTS_ARRAY
Constructor Detail |
private BeanUtil()
Method Detail |
private static final PropertyDescriptor getPropertyDescriptor(String propertyName, Class beanClass)
Uses the classes in java.beans
to get back
a descriptor for a property. Read-only and write-only
properties will have a slower return time.
propertyName
- The programmatic name of the propertybeanClass
- The Class object for the target bean.
For example sun.beans.OurButton.class.
PropertyNotFoundException
- indicates that the property
could not be found on the bean class.public static Object getObjectAttribute(Object bean, String propertyNames) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
Gets the specified attribute from the specified object. For example,
getObjectAttribute(o, "address.line1")
will return
the result of calling o.getAddress().getLine1()
.
The attribute specified may contain as many levels as you like. If at any time a null reference is acquired by calling one of the successive getter methods, then the return value from this method is also null.
When reading from a boolean property the underlying bean introspector first looks for an is<Property> read method, not finding one it will still look for a get<Property> read method. Not finding either, the property is considered write-only.
bean
- the bean to set the property onpropertyNames
- the name of the propertie(s) to retrieve. If this is
null or the empty string, then bean
will be returned.
PropertyNotFoundException
- indicates the the given property
could not be found on the bean
NoSuchMethodException
- Not thrown
InvocationTargetException
- if a specified getter method throws an
exception.
IllegalAccessException
- if a getter method is
not public or property is write-only.public static void setObjectAttribute(Object bean, String propertyNames, Object value) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException
Sets the specified attribute on the specified object. For example,
getObjectAttribute(o, "address.line1", value)
will call
o.getAddress().setLine1(value)
.
The attribute specified may contain as many levels as you like. If at
any time a null reference is acquired by calling one of the successive
getter methods, then a NullPointerException
is thrown.
bean
- the bean to call the getters onpropertyNames
- the name of the attribute(s) to set. If this is
null or the empty string, then an exception is thrown.value
- the value of the object to set on the bean property
PropertyNotFoundException
- indicates the the given property
could not be found on the bean
IllegalArgumentException
- if the supplied parameter is not of
a valid type
NoSuchMethodException
- never
IllegalAccessException
- if a getter or setter method is
not public or property is read-only.
InvocationTargetException
- if a specified getter method throws an
exception.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |