org.hypergraphdb.type
Class BonesOfBeans

java.lang.Object
  extended by org.hypergraphdb.type.BonesOfBeans

public class BonesOfBeans
extends java.lang.Object

This is a utility class to handle bean introspection. All functions may throw a HGException which will wrap the underlying bean introspection and reflection (for set and get) exceptions.


Constructor Summary
BonesOfBeans()
           
 
Method Summary
static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getAllPropertyDescriptors(java.lang.Class<?> beanClass)
           
static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getAllPropertyDescriptors(java.lang.Object bean)
           
static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getAllPropertyDescriptorsEx(java.lang.Class<?> beanClass)
           
static java.lang.Object getProperty(java.lang.Object bean, java.beans.PropertyDescriptor prop)
          Same as getProperty(Object, String), but use a supplied PropertyDescriptor instead of the property name.
static java.lang.Object getProperty(java.lang.Object bean, java.beans.PropertyDescriptor prop, int index)
          Same as getProperty(Object, String, int), but use a supplied PropertyDescriptor instead of the property name.
static java.lang.Object getProperty(java.lang.Object bean, java.lang.String propname)
          Get the value of a particular bean property.
static java.lang.Object getProperty(java.lang.Object bean, java.lang.String propname, int index)
          Get the value of a particular (indexed) bean property.
static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Object bean, java.lang.String propname)
           
static java.lang.Object makeBean(java.lang.String classname)
          Construct a new instance of a bean.
static java.lang.Class<?> primitiveEquivalentOf(java.lang.Class<?> aClass)
           
static void setProperty(java.lang.Object bean, java.beans.PropertyDescriptor prop, int index, java.lang.Object newvalue)
          Same as setProperty(Object, String, int, Object), but use a supplied PropertyDescriptor instead of the property name.
static void setProperty(java.lang.Object bean, java.beans.PropertyDescriptor prop, java.lang.Object newvalue)
          Same as setProperty(Object, String, Object), but use a supplied PropertyDescriptor instead of the property name.
static void setProperty(java.lang.Object bean, java.lang.String propname, int index, java.lang.Object newvalue)
          Assign a new value to a specified bean property.
static void setProperty(java.lang.Object bean, java.lang.String propname, java.lang.Object newvalue)
          Assign a new value to a specified bean property.
static java.lang.Class<?> wrapperEquivalentOf(java.lang.Class<?> aClass)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BonesOfBeans

public BonesOfBeans()
Method Detail

getAllPropertyDescriptors

public static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getAllPropertyDescriptors(java.lang.Class<?> beanClass)
Parameters:
beanClass - The bean class whose property descriptors are desired. Cannot be null.
Returns:
a Map of all property descriptors in the bean. The map elements are keyed by property name.

getAllPropertyDescriptorsEx

public static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getAllPropertyDescriptorsEx(java.lang.Class<?> beanClass)

getAllPropertyDescriptors

public static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> getAllPropertyDescriptors(java.lang.Object bean)
Parameters:
bean - The bean whose property descriptors are desired. Cannot be null
Returns:
a Map of all property descriptors in the bean. The map elements are keyed by property name.

getPropertyDescriptor

public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Object bean,
                                                                  java.lang.String propname)
Parameters:
bean - Any object conforming to the Java Beans Specification
propname - The name a bean property.
Returns:
The 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.

getProperty

public static java.lang.Object getProperty(java.lang.Object bean,
                                           java.beans.PropertyDescriptor prop,
                                           int index)
Same as getProperty(Object, String, int), but use a supplied PropertyDescriptor instead of the property name.


getProperty

public static java.lang.Object getProperty(java.lang.Object bean,
                                           java.beans.PropertyDescriptor prop)
Same as getProperty(Object, String), but use a supplied PropertyDescriptor instead of the property name.


getProperty

public static java.lang.Object getProperty(java.lang.Object bean,
                                           java.lang.String propname,
                                           int index)
Get the value of a particular (indexed) bean property.

Parameters:
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.
Returns:
The value of the property at the specified index.
Throws:
HGException - if the property cannot be found in the bean or if index >= 0 and the property is not an indexed property.

getProperty

public static java.lang.Object getProperty(java.lang.Object bean,
                                           java.lang.String propname)
Get the value of a particular bean property.

Parameters:
bean - An object conforming to the Java Beans Specification.
propname - The name of the desired bean property.
Returns:
The value of the specified property.
Throws:
HGException - if the property cannot be found in the bean or if index >= 0 and the property is not an indexed property.

setProperty

public static void setProperty(java.lang.Object bean,
                               java.beans.PropertyDescriptor prop,
                               int index,
                               java.lang.Object newvalue)
Same as setProperty(Object, String, int, Object), but use a supplied PropertyDescriptor instead of the property name.


setProperty

public static void setProperty(java.lang.Object bean,
                               java.beans.PropertyDescriptor prop,
                               java.lang.Object newvalue)
Same as setProperty(Object, String, Object), but use a supplied PropertyDescriptor instead of the property name.


setProperty

public static void setProperty(java.lang.Object bean,
                               java.lang.String propname,
                               int index,
                               java.lang.Object newvalue)
Assign a new value to a specified bean property.

Parameters:
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.
Throws:
HGException - if the property cannot be found in the bean or if index >= 0 and the property is not an indexed property.

setProperty

public static void setProperty(java.lang.Object bean,
                               java.lang.String propname,
                               java.lang.Object newvalue)
Assign a new value to a specified bean property.

Parameters:
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.
Throws:
HGException - if the property cannot be found in the bean or if index >= 0 and the property is not an indexed property.

makeBean

public static java.lang.Object makeBean(java.lang.String classname)
Construct a new instance of a bean.

Parameters:
classname - The fully qualified class name of the bean to construct.
Returns:
The newly constructed bean.
Throws:
HGException - is there's any error during the construction process, such as ClassNotFoundException etc.

primitiveEquivalentOf

public static java.lang.Class<?> primitiveEquivalentOf(java.lang.Class<?> aClass)
Parameters:
aClass - a Class
Returns:
the class's primitive equivalent, if aClass is a primitive wrapper. If aClass is primitive, returns aClass. Otherwise, returns null.

wrapperEquivalentOf

public static java.lang.Class<?> wrapperEquivalentOf(java.lang.Class<?> aClass)