public class BonesOfBeans extends Object
HGException
which will wrap the underlying bean introspection
and reflection (for set and get) exceptions.Constructor and Description |
---|
BonesOfBeans() |
Modifier and Type | Method and Description |
---|---|
static Map<String,PropertyDescriptor> |
getAllPropertyDescriptors(Class<?> beanClass) |
static Map<String,PropertyDescriptor> |
getAllPropertyDescriptors(Object bean) |
static Map<String,PropertyDescriptor> |
getAllPropertyDescriptorsEx(Class<?> beanClass) |
static Map<String,Object> |
getPropertiesAsMap(Object bean)
Return a Java Map of all read-write properties of the specified Java bean.
|
static Object |
getProperty(Object bean,
PropertyDescriptor prop)
Same as
getProperty(Object, String) , but use a supplied
PropertyDescriptor instead of the property name. |
static Object |
getProperty(Object bean,
PropertyDescriptor prop,
int index)
Same as
getProperty(Object, String, int) , but use a supplied
PropertyDescriptor instead of the property name. |
static Object |
getProperty(Object bean,
String propname)
Get the value of a particular bean property.
|
static Object |
getProperty(Object bean,
String propname,
int index)
Get the value of a particular (indexed) bean property.
|
static PropertyDescriptor |
getPropertyDescriptor(Class<?> clazz,
String propname) |
static PropertyDescriptor |
getPropertyDescriptor(Object bean,
String propname) |
static Object |
makeBean(String classname)
Construct a new instance of a bean.
|
static Class<?> |
primitiveEquivalentOf(Class<?> aClass) |
static void |
setPropertiesFromMap(Object bean,
Map<String,Object> properties) |
static void |
setProperty(Object bean,
PropertyDescriptor prop,
int index,
Object newvalue)
Same as
setProperty(Object, String, int, Object) , but use a
supplied PropertyDescriptor instead of the property name. |
static void |
setProperty(Object bean,
PropertyDescriptor prop,
Object newvalue)
Same as
setProperty(Object, String, Object) , but use a
supplied PropertyDescriptor instead of the property name. |
static void |
setProperty(Object bean,
String propname,
int index,
Object newvalue)
Assign a new value to a specified bean property.
|
static void |
setProperty(Object bean,
String propname,
Object newvalue)
Assign a new value to a specified bean property.
|
static Class<?> |
wrapperEquivalentOf(Class<?> aClass) |
public static Map<String,PropertyDescriptor> getAllPropertyDescriptors(Class<?> beanClass)
beanClass
- The bean class whose property descriptors are desired. Cannot
be null
.Map
of all property descriptors in the bean. The
map elements are keyed by property name.public static Map<String,PropertyDescriptor> getAllPropertyDescriptorsEx(Class<?> beanClass)
public static Map<String,PropertyDescriptor> getAllPropertyDescriptors(Object bean)
bean
- The bean whose property descriptors are desired. Cannot be
null
Map
of all property descriptors in the bean. The
map elements are keyed by property name.public static PropertyDescriptor getPropertyDescriptor(Object bean, String propname)
bean
- Any object conforming to the Java Beans Specificationpropname
- The name a bean property.PropertyDescriptor
for that property as returned
from the BeanInfo
associated with that bean. If
there is no property with that name in the bean,
null
is returned.public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propname)
public static Object getProperty(Object bean, PropertyDescriptor prop, int index)
getProperty(Object, String, int)
, but use a supplied
PropertyDescriptor
instead of the property name.public static Map<String,Object> getPropertiesAsMap(Object bean)
Return a Java Map of all read-write properties of the specified Java bean.
public static void setPropertiesFromMap(Object bean, Map<String,Object> properties)
public static Object getProperty(Object bean, PropertyDescriptor prop)
getProperty(Object, String)
, but use a supplied
PropertyDescriptor
instead of the property name.public static Object getProperty(Object bean, String propname, int index)
bean
- An object conforming to the Java Beans Specification.propname
- The name of the desired bean property.index
- The integer
index within the property. If the
value is negative, the property itself is returned. That is,
for example, if the property is String [] values
and if index
is < 0, values
will be
returned, otherwise values[index]
will be
returned.HGException
- if the property cannot be found in the bean or if
index >= 0
and the property is not an indexed
property.public static Object getProperty(Object bean, String propname)
bean
- An object conforming to the Java Beans Specification.propname
- The name of the desired bean property.HGException
- if the property cannot be found in the bean or if
index >= 0
and the property is not an indexed
property.public static void setProperty(Object bean, PropertyDescriptor prop, int index, Object newvalue)
setProperty(Object, String, int, Object)
, but use a
supplied PropertyDescriptor
instead of the property name.public static void setProperty(Object bean, PropertyDescriptor prop, Object newvalue)
setProperty(Object, String, Object)
, but use a
supplied PropertyDescriptor
instead of the property name.public static void setProperty(Object bean, String propname, int index, Object newvalue)
bean
- An object conforming to the Java Beans Specification.propname
- The name of the desired bean property.index
- The integer
index within the property. If the
value is negative, the property itself will be modified. That
is, for example, if the property is
String [] values
and if index
is <
0, values
will be modified, otherwise
values[index]
will be modified.newvalue
- The value to assign to the specified property.HGException
- if the property cannot be found in the bean or if
index >= 0
and the property is not an indexed
property.public static void setProperty(Object bean, String propname, Object newvalue)
bean
- An object conforming to the Java Beans Specification.propname
- The name of the desired bean property.newvalue
- The value to assign to the specified property.HGException
- if the property cannot be found in the bean or if
index >= 0
and the property is not an indexed
property.public static Object makeBean(String classname)
classname
- The fully qualified class name of the bean to construct.HGException
- is there's any error during the construction process, such as
ClassNotFoundException etc.public static Class<?> primitiveEquivalentOf(Class<?> aClass)
aClass
- a ClassCopyright © 2015. All rights reserved.