|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdsto.dfc.util.Beans
public final class Beans
Utilities for messing with JavaBeans.
| Method Summary | |
|---|---|
static boolean |
addListener(Class listenerInterface,
Object source,
Object listener)
Add an event listener to a JavaBean using reflection. |
static boolean |
addListener(Object source,
String eventType,
Class listenerClass,
Object listener)
Dynamically add a listener to an event type using reflection. |
static Class |
classForName(String name)
Like Class.forName () but also handles the primitive classes "int", "float", etc. |
static String |
convertPropertyToString(Object propertyValue)
Convert an object to its stringified value using (if possible) its PropertyEditor. |
static Object |
convertStringToProperty(Class propertyType,
String propertyText)
Convert a stringfied object to an instance by using (if possible) its PropertyEditor. |
protected static Method |
findEventListenerMethod(Class sourceClass,
String prefix,
String eventType,
Class listenerClass)
|
static PropertyDescriptor |
findProperty(PropertyDescriptor[] properties,
String name)
Find a property descriptor with a given name. |
static PropertyEditor |
findPropertyEditor(Class type)
|
static Class |
getPropertyClass(Class beanClass,
String property)
Get the type of a property. |
static Method |
getPropertyReadMethod(Class beanClass,
String propertyName)
Get the method used to read a JavaBean property. |
static Object |
getPropertyValue(Object target,
String property)
Get the value of a given property. |
static Method |
getPropertyWriteMethod(Class beanClass,
String propertyName)
Get the method used to write a given JavaBean property. |
static Method |
getPropertyWriteMethod(Class targetClass,
String propertyName,
Class valueClass)
Attempt to resolve a JavaBean's method for writing a property value. |
static Object |
getSingletonInstance(Class theClass)
Get the global instance of a singleton class. |
static boolean |
hasWritableProperty(Class targetClass,
String propertyName)
Similar to hasWritableProperty(Class, String, Class) except the
type of the property is not checked. |
static boolean |
hasWritableProperty(Class targetClass,
String propertyName,
Class valueClass)
True if a JavaBean has a writable property with a given name. |
static boolean |
isBean(Class aClass)
Test if a given class is a JavaBean. |
static boolean |
isSingletonClass(Class theClass)
Test if a class is a singleton class type (see Singleton for
details on what constitues a singleton class). |
static Class |
objectToPrimitive(Class theClass)
|
static Class |
primitiveToObject(Class theClass)
Convert a class representing a primitive type (eg 'int') to its equivalent Object-based type (eg 'java.lang.Integer'). |
static boolean |
removeListener(Class listenerInterface,
Object source,
Object listener)
Remove an event listener to a JavaBean using reflection. |
static boolean |
removeListener(Object source,
String eventType,
Class listenerClass,
Object listener)
Dynamically remove a listener to an event type using reflection. |
static void |
setPropertyValue(Object target,
String propertyName,
Object propertyValue)
Set the value of a writeable JavaBean property. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean isBean(Class aClass)
aClass - The class to test
public static Method getPropertyWriteMethod(Class beanClass,
String propertyName)
beanClass - The class of JavaBean to analyse.propertyName - The name of the property.
getPropertyWriteMethod(Class,String,Class),
getPropertyReadMethod(Class, String)
public static Method getPropertyReadMethod(Class beanClass,
String propertyName)
throws NoSuchMethodException
beanClass - The class of the bean.propertyName - The property name.
NoSuchMethodException - if no method for that property
could be resolved.getPropertyWriteMethod(Class, String)
public static Method getPropertyWriteMethod(Class targetClass,
String propertyName,
Class valueClass)
targetClass - The class of JavaBean to analyse.propertyName - The name of the property.valueClass - The type of the property.
getPropertyWriteMethod(Class,String)
public static boolean hasWritableProperty(Class targetClass,
String propertyName,
Class valueClass)
targetClass - The JavaBean class.propertyName - The property name.valueClass - The type of property value.
getPropertyWriteMethod(java.lang.Class, java.lang.String),
setPropertyValue(java.lang.Object, java.lang.String, java.lang.Object)
public static boolean hasWritableProperty(Class targetClass,
String propertyName)
hasWritableProperty(Class, String, Class) except the
type of the property is not checked. This is a little faster than
the full version.
targetClass - The class to check.propertyName - The name of the property.
public static void setPropertyValue(Object target,
String propertyName,
Object propertyValue)
throws NoSuchMethodException,
InvocationTargetException
target - The JavaBean.propertyName - The name of the property.propertyValue - The new value of the property.
NoSuchMethodException - if the property does not exist.
InvocationTargetException - if the property setter method threw
an exception.
public static Object getPropertyValue(Object target,
String property)
throws NoSuchMethodException
target - The object to read the value from.property - The property name.
NoSuchMethodException - if the property does not exist
or an error occurred during the property method invocation.
public static Class getPropertyClass(Class beanClass,
String property)
throws NoSuchMethodException
beanClass - The class of the JavaBean.property - The property name.
NoSuchMethodException - if the property does not exist.public static Class primitiveToObject(Class theClass)
theClass - The primitive class.
public static Class objectToPrimitive(Class theClass)
public static Class classForName(String name)
throws ClassNotFoundException
name - The class name.
ClassNotFoundException - if class is not defined.public static boolean isSingletonClass(Class theClass)
Singleton for
details on what constitues a singleton class).
public static Object getSingletonInstance(Class theClass)
throws IllegalArgumentException
Singleton for
details on what constitues a singleton class.
theClass - The class to examine. For convenience, theClass does
not have to implement the Singleton interface, it just has to have either
a static getSingletonInstance() method or a static INSTANCE variable.
IllegalArgumentException - if theClass is not a singleton class.
public static boolean addListener(Class listenerInterface,
Object source,
Object listener)
listenerInterface - The event listener interface (eg
PropertyChangeListener).source - The event source bean.listener - The event listener (must implement
listenerInterface).
public static boolean removeListener(Class listenerInterface,
Object source,
Object listener)
listenerInterface - The event listener interface (eg
PropertyChangeListener).source - The event source bean.listener - The event listener (must implement
listenerInterface).
public static PropertyEditor findPropertyEditor(Class type)
public static PropertyDescriptor findProperty(PropertyDescriptor[] properties,
String name)
properties - The properties to search.name - The name to find.
public static String convertPropertyToString(Object propertyValue)
propertyValue - The value to convert.
convertStringToProperty(java.lang.Class, java.lang.String)
public static Object convertStringToProperty(Class propertyType,
String propertyText)
throws IllegalArgumentException
propertyType - The type of the new property value.propertyText - The stringified property value
IllegalArgumentException - If propertyText could not be converted
to an object (eg format error or no converter was found).convertPropertyToString(java.lang.Object)
public static boolean addListener(Object source,
String eventType,
Class listenerClass,
Object listener)
source - The object to add the listener to.eventType - The event type eg "change" for ChangeListener,
"propertyChange" for PropertyChangeListener.listenerClass - The listener interface class eg
PropertyChangeListener.class for "propertyChange" events.listener - The listener class. Must implement the interface
defined by listenerClass.
public static boolean removeListener(Object source,
String eventType,
Class listenerClass,
Object listener)
source - The object to remove the listener from.eventType - The event type eg "change" for ChangeListener,
"propertyChange" for PropertyChangeListener.listenerClass - The listener interface class eg
PropertyChangeListener.class for "propertyChange" events.listener - The listener class. Must implement the interface
defined by listenerClass.
protected static Method findEventListenerMethod(Class sourceClass,
String prefix,
String eventType,
Class listenerClass)
throws NoSuchMethodException
NoSuchMethodException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||