edu.washington.cs.supple.beanlike
Class BeanlikeBindingUtils

java.lang.Object
  extended byedu.washington.cs.supple.beanlike.BeanlikeBindingUtils

public final class BeanlikeBindingUtils
extends java.lang.Object

Utility methods for interfacing with "beanlike" objects using reflection (java.beans is not available for all target VMs). Expects a "beanlike" with property "propName" to use "getPropName" and "setPropName" as accessor names, optionally using "isPropName" for boolean and Boolean types. *

Author:
dbc1

Method Summary
static void addPropertyChangeListener(java.lang.Object bean, java.beans.PropertyChangeListener listener)
          Add property change listener - if possible.
static BeanlikePropertyDescriptor[] convertProperties(java.lang.Class beanlikeClass, java.lang.String[] propertyNames)
          Convert property names to descriptors.
static BeanlikeEventDescriptor getEventDescriptor(java.lang.Class c, java.lang.String eventName)
          Get a BeanlikePropertyDescriptor from a beanlike class.
static BeanlikeEventDescriptor getEventDescriptor(java.lang.Object beanlike, java.lang.String eventName)
          Get a BeanlikeEventDescriptor from a beanlike object.
static BeanlikeInfo getInfo(java.lang.Class c)
          Get BeanlikeInfo for a given class.
static BeanlikePropertyDescriptor getPropertyDescriptor(java.lang.Class c, java.lang.String propertyName)
          Get a BeanlikePropertyDescriptor from a beanlike class.
static BeanlikePropertyDescriptor getPropertyDescriptor(java.lang.Object beanlike, java.lang.String propertyName)
          Get a BeanlikePropertyDescriptor from a beanlike object.
static java.lang.Class getPropertyType(java.lang.Object beanlike, java.lang.String propertyName)
           
static java.lang.Object getPropertyValue(java.lang.Object beanlike, java.lang.String propertyName)
          Get the value of a given property for a given beanlike object.
static void removePropertyChangeListener(java.lang.Object bean, java.beans.PropertyChangeListener listener)
          Remove property change listener - if possible.
static void setPropertyValue(java.lang.Object beanlike, java.lang.String propertyName, java.lang.Object v)
          Set the value of the given beanlike object property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getPropertyValue

public static java.lang.Object getPropertyValue(java.lang.Object beanlike,
                                                java.lang.String propertyName)
                                         throws java.lang.IllegalArgumentException
Get the value of a given property for a given beanlike object.

Parameters:
propertyName - property name
Returns:
value of the property
Throws:
java.lang.IllegalArgumentException - if property does not exist or cannot be read

getPropertyType

public static java.lang.Class getPropertyType(java.lang.Object beanlike,
                                              java.lang.String propertyName)
                                       throws java.lang.IllegalArgumentException
Parameters:
beanlike -
propertyName -
Returns:
the class of the given property
Throws:
java.lang.IllegalArgumentException - if property does not exist or cannot be read

setPropertyValue

public static void setPropertyValue(java.lang.Object beanlike,
                                    java.lang.String propertyName,
                                    java.lang.Object v)
                             throws java.lang.IllegalArgumentException
Set the value of the given beanlike object property.

Parameters:
beanlike -
propertyName -
v -
Throws:
java.lang.IllegalArgumentException

getPropertyDescriptor

public static BeanlikePropertyDescriptor getPropertyDescriptor(java.lang.Object beanlike,
                                                               java.lang.String propertyName)
                                                        throws java.lang.IllegalArgumentException
Get a BeanlikePropertyDescriptor from a beanlike object.

Parameters:
beanlike -
propertyName -
Returns:
Throws:
java.lang.IllegalArgumentException

getEventDescriptor

public static BeanlikeEventDescriptor getEventDescriptor(java.lang.Object beanlike,
                                                         java.lang.String eventName)
                                                  throws java.lang.IllegalArgumentException
Get a BeanlikeEventDescriptor from a beanlike object.

Parameters:
beanlike -
eventName -
Returns:
Throws:
java.lang.IllegalArgumentException

getPropertyDescriptor

public static BeanlikePropertyDescriptor getPropertyDescriptor(java.lang.Class c,
                                                               java.lang.String propertyName)
                                                        throws java.lang.IllegalArgumentException
Get a BeanlikePropertyDescriptor from a beanlike class.

Throws:
java.lang.IllegalArgumentException

getEventDescriptor

public static BeanlikeEventDescriptor getEventDescriptor(java.lang.Class c,
                                                         java.lang.String eventName)
                                                  throws java.lang.IllegalArgumentException
Get a BeanlikePropertyDescriptor from a beanlike class.

Parameters:
c -
Returns:
Throws:
java.lang.IllegalArgumentException

getInfo

public static BeanlikeInfo getInfo(java.lang.Class c)
Get BeanlikeInfo for a given class.

Parameters:
c -
Returns:

addPropertyChangeListener

public static void addPropertyChangeListener(java.lang.Object bean,
                                             java.beans.PropertyChangeListener listener)
Add property change listener - if possible. Does not throw an exception if event cannot be found.


removePropertyChangeListener

public static void removePropertyChangeListener(java.lang.Object bean,
                                                java.beans.PropertyChangeListener listener)
Remove property change listener - if possible. Does not throw an exception if event cannot be found.


convertProperties

public static BeanlikePropertyDescriptor[] convertProperties(java.lang.Class beanlikeClass,
                                                             java.lang.String[] propertyNames)
Convert property names to descriptors.