DESY ACOP Beans Home

com.cosylab.introspection
Class BeanIntrospector

java.lang.Object
  extended by com.cosylab.introspection.BeanIntrospector

public class BeanIntrospector
extends java.lang.Object

The BeanIntrospector class helps read and write property values from a Java Bean and provides methods for easier manipulation of PropertyDescriptor arrays.

Version:
$id$
Author:
Miha Kadunc

Constructor Summary
BeanIntrospector()
           
 
Method Summary
static java.beans.FeatureDescriptor getDescriptor(java.beans.FeatureDescriptor[] descriptors, java.lang.reflect.Member m)
          Retrieves the FeatureDescriptor for a member from an array of FeatureDescriptors.
static java.beans.FeatureDescriptor getDescriptorByName(java.beans.FeatureDescriptor[] descriptors, java.lang.String featureName)
          Retrieves the FeatureDescriptor for a member from an array of FeatureDescriptors given the feature's name.
static java.beans.PropertyDescriptor[] getInterfacePropertyDescriptors(java.lang.Class theClass, java.lang.Class superInterface)
          Returns descriptors of the properties declared in interfaces that the current class implements, following the interface hierarchy to the superInterface specified.
static java.util.Map getProperties(java.lang.Object target)
          Returns a Name-Value map of all the properties on a given object
static java.util.Map getProperties(java.beans.PropertyDescriptor[] properties, java.lang.Object target)
          Returns a Name-Value map of properties described by the array of type PropertyDescriptors; Values are retrieved from the target object.
static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class beanClass, java.lang.String propertyName)
          Returns descriptor for the property with specified property name of bean with beanClass
static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Class theClass)
          Returns all the property descriptors of theClass.
static java.lang.String getPropertyDisplayString(java.lang.String propertyName)
          DOCUMENT ME!
static java.lang.String getPropertyDisplayString(java.lang.String propertyName, boolean titleCase)
          DOCUMENT ME!
static java.lang.String[] getPropertyNames(java.beans.PropertyDescriptor[] desc)
          Returns names of all the property desriptors in the given array.
static java.lang.Class getPropertyType(java.lang.Class beanClass, java.lang.String propertyName)
          Returns the type of the specified property on specified bean.
static java.lang.Class[] getPropertyTypes(java.beans.PropertyDescriptor[] desc)
          Returns types of all the property descriptors in the given array.
static java.lang.Object getPropertyValue(java.lang.Object target, java.lang.String propertyName)
          Gets the value of the property specified by propertyName on the target object.
static java.lang.Object[] getPropertyValues(java.beans.PropertyDescriptor[] desc, java.lang.Object target)
          Returns types of all the property descriptors in the given array.
static java.beans.PropertyDescriptor[] getReadable(java.beans.PropertyDescriptor[] desc)
          Selects descriptors of all readable properties from an array of descriptors.
static java.lang.reflect.Method getSetterMethod(java.lang.Class inspectedBean, java.lang.String propertyName)
          Gets a setter method for a property specified by propertyName
static java.beans.PropertyDescriptor[] getWritable(java.beans.PropertyDescriptor[] desc)
          Selects descriptors of all writable properties from an array of descriptors.
static boolean isGetterMethod(java.lang.reflect.Method method)
          DOCUMENT ME!
static void setPropertyValue(java.lang.Object target, java.lang.String propertyName, java.lang.Object value)
          Sets the value of the specified property on the target object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanIntrospector

public BeanIntrospector()
Method Detail

getPropertyValue

public static java.lang.Object getPropertyValue(java.lang.Object target,
                                                java.lang.String propertyName)
                                         throws java.beans.IntrospectionException,
                                                java.lang.reflect.InvocationTargetException,
                                                java.lang.IllegalAccessException
Gets the value of the property specified by propertyName on the target object. Primitive types are returned in equivalent Java objects.

Parameters:
target - the object containing the property
propertyName - the name of the property to get
Returns:
Object the value of the property
Throws:
java.beans.IntrospectionException - if an illegal property name is specified or the target object is not a Java bean
java.lang.reflect.InvocationTargetException - when an exception is thrown inside the property getter
java.lang.IllegalAccessException - when property access is restricted on the target object

getProperties

public static java.util.Map getProperties(java.lang.Object target)
                                   throws java.beans.IntrospectionException,
                                          java.lang.reflect.InvocationTargetException,
                                          java.lang.IllegalAccessException
Returns a Name-Value map of all the properties on a given object

Parameters:
target - Object
Returns:
Map
Throws:
java.beans.IntrospectionException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.NullPointerException - DOCUMENT ME!

getProperties

public static java.util.Map getProperties(java.beans.PropertyDescriptor[] properties,
                                          java.lang.Object target)
                                   throws java.beans.IntrospectionException,
                                          java.lang.reflect.InvocationTargetException,
                                          java.lang.IllegalAccessException
Returns a Name-Value map of properties described by the array of type PropertyDescriptors; Values are retrieved from the target object.

Parameters:
properties - PropertyDescriptor[]
target - Object
Returns:
Map
Throws:
java.beans.IntrospectionException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

setPropertyValue

public static void setPropertyValue(java.lang.Object target,
                                    java.lang.String propertyName,
                                    java.lang.Object value)
                             throws java.lang.NoSuchMethodException,
                                    java.lang.reflect.InvocationTargetException,
                                    java.lang.IllegalAccessException
Sets the value of the specified property on the target object.

Parameters:
target - the object containing the property
propertyName - name of the property
value - the new value of the property
Throws:
java.lang.NoSuchMethodException - if the setter does not exist
java.lang.reflect.InvocationTargetException - reflection exception
java.lang.IllegalAccessException - reflection exception

getSetterMethod

public static java.lang.reflect.Method getSetterMethod(java.lang.Class inspectedBean,
                                                       java.lang.String propertyName)
Gets a setter method for a property specified by propertyName

Parameters:
inspectedBean - Class
propertyName - String
Returns:
Method the setter method for the property

getDescriptor

public static java.beans.FeatureDescriptor getDescriptor(java.beans.FeatureDescriptor[] descriptors,
                                                         java.lang.reflect.Member m)
Retrieves the FeatureDescriptor for a member from an array of FeatureDescriptors. Member should be the method that is desribed by a MethodDescriptor or the read method of a property described by PropertyDescriptor.

Parameters:
descriptors - PropertyDescriptor[]
m - String
Returns:
java.beans.PropertyDescriptor

getDescriptorByName

public static java.beans.FeatureDescriptor getDescriptorByName(java.beans.FeatureDescriptor[] descriptors,
                                                               java.lang.String featureName)
Retrieves the FeatureDescriptor for a member from an array of FeatureDescriptors given the feature's name. Feature can be a property, a method, or an event set.

Parameters:
descriptors - FeatureDescriptor[]
featureName - String
Returns:
java.beans.FeatureDescriptor

getInterfacePropertyDescriptors

public static java.beans.PropertyDescriptor[] getInterfacePropertyDescriptors(java.lang.Class theClass,
                                                                              java.lang.Class superInterface)
Returns descriptors of the properties declared in interfaces that the current class implements, following the interface hierarchy to the superInterface specified. Descriptors of properties that are declared in the class itself or an interface, that is not a descendant of the specified interface, are not returned.

Parameters:
theClass - Class
superInterface - Class
Returns:
java.beans.PropertyDescriptor

getPropertyDescriptor

public static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Class beanClass,
                                                                  java.lang.String propertyName)
                                                           throws java.beans.IntrospectionException
Returns descriptor for the property with specified property name of bean with beanClass

Parameters:
beanClass - the Class of the bean to introspect
propertyName - the property name
Returns:
java.beans.PropertyDescriptor
Throws:
java.beans.IntrospectionException

getPropertyType

public static java.lang.Class getPropertyType(java.lang.Class beanClass,
                                              java.lang.String propertyName)
                                       throws java.beans.IntrospectionException
Returns the type of the specified property on specified bean.

Parameters:
beanClass - the Class of the bean to introspect
propertyName - the property name
Returns:
the property type
Throws:
java.beans.IntrospectionException

getPropertyNames

public static java.lang.String[] getPropertyNames(java.beans.PropertyDescriptor[] desc)
Returns names of all the property desriptors in the given array.

Parameters:
desc - PropertyDescriptor[]
Returns:
java.beans.PropertyDescriptor

getPropertyTypes

public static java.lang.Class[] getPropertyTypes(java.beans.PropertyDescriptor[] desc)
Returns types of all the property descriptors in the given array.

Parameters:
desc - PropertyDescriptor[]
Returns:
java.beans.PropertyDescriptor

getPropertyValues

public static java.lang.Object[] getPropertyValues(java.beans.PropertyDescriptor[] desc,
                                                   java.lang.Object target)
                                            throws java.beans.IntrospectionException,
                                                   java.lang.reflect.InvocationTargetException,
                                                   java.lang.IllegalAccessException
Returns types of all the property descriptors in the given array.

Parameters:
desc - PropertyDescriptor[]
target - DOCUMENT ME!
Returns:
java.beans.PropertyDescriptor
Throws:
java.beans.IntrospectionException - DOCUMENT ME!
java.lang.reflect.InvocationTargetException - DOCUMENT ME!
java.lang.IllegalAccessException - DOCUMENT ME!

getWritable

public static java.beans.PropertyDescriptor[] getWritable(java.beans.PropertyDescriptor[] desc)
Selects descriptors of all writable properties from an array of descriptors.

Parameters:
desc - PropertyDescriptor[]
Returns:
java.beans.PropertyDescriptor

getReadable

public static java.beans.PropertyDescriptor[] getReadable(java.beans.PropertyDescriptor[] desc)
Selects descriptors of all readable properties from an array of descriptors.

Parameters:
desc - PropertyDescriptor[]
Returns:
java.beans.PropertyDescriptor

getPropertyDescriptors

public static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Class theClass)
                                                              throws java.beans.IntrospectionException
Returns all the property descriptors of theClass.

Parameters:
theClass - Class
Returns:
java.beans.PropertyDescriptor
Throws:
java.beans.IntrospectionException

getPropertyDisplayString

public static java.lang.String getPropertyDisplayString(java.lang.String propertyName)
DOCUMENT ME!

Parameters:
propertyName - DOCUMENT ME!
Returns:
DOCUMENT ME!

getPropertyDisplayString

public static java.lang.String getPropertyDisplayString(java.lang.String propertyName,
                                                        boolean titleCase)
DOCUMENT ME!

Parameters:
propertyName - DOCUMENT ME!
titleCase - DOCUMENT ME!
Returns:
DOCUMENT ME!

isGetterMethod

public static boolean isGetterMethod(java.lang.reflect.Method method)
DOCUMENT ME!

Parameters:
method - DOCUMENT ME!
Returns:
DOCUMENT ME!


Copyright © 2010. All Rights Reserved.