SPT Core API

com.sptci
Class PropertyChangeListener

java.lang.Object
  extended by com.sptci.PropertyChangeListener
All Implemented Interfaces:
PropertyChangeListener, EventListener
Direct Known Subclasses:
PropertyChangeListener, PropertyChangeListener

public class PropertyChangeListener
extends Object
implements PropertyChangeListener

An implementation of PropertyChangeListener used to synchronise changes made to properties in UI components to the bean java bean.

Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: PropertyChangeListener.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2006-01-22

Field Summary
protected  Object bean
          The java bean which is to be kept synchronised with updates made to UI components.
protected  HashMap<String,PropertyDescriptor> properties
          A HashMap of all the properties defined in the bean.
protected static HashMap<String,String> typeMapping
          A HashMap that provides the mapping for primitives to their object wrappers.
 
Constructor Summary
protected PropertyChangeListener()
          Default constructor.
  PropertyChangeListener(Object bean)
          Create a new instance of the class using the specified java bean.
 
Method Summary
 Object getBean()
          Returns bean.
 HashMap<String,PropertyDescriptor> getProperties()
          Returns a shallow-clone of properties.
protected  void initProperties()
          Populate properties by introspecting the bean.
protected  void modifyObject(PropertyChangeEvent event, PropertyDescriptor descriptor)
          Modify an object property in bean.
protected  void modifyPrimitive(PropertyChangeEvent event, PropertyDescriptor descriptor)
          Modify a primitive property in bean.
protected  Object objectFromString(PropertyChangeEvent event, PropertyDescriptor descriptor)
          Convert the given String value to an Object wrapper of the appropriate kind.
 void propertyChange(PropertyChangeEvent event)
          Implementation of the method defined in PropertyChangeListener.
 void setBean(Object bean)
          Set bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typeMapping

protected static final HashMap<String,String> typeMapping
A HashMap that provides the mapping for primitives to their object wrappers.


bean

protected Object bean
The java bean which is to be kept synchronised with updates made to UI components.


properties

protected HashMap<String,PropertyDescriptor> properties
A HashMap of all the properties defined in the bean.

Constructor Detail

PropertyChangeListener

protected PropertyChangeListener()
Default constructor. Initialises properties.


PropertyChangeListener

public PropertyChangeListener(Object bean)
                       throws IntrospectionException
Create a new instance of the class using the specified java bean.

Parameters:
bean - The data object which is to be managed.
Throws:
IntrospectionException - If errors are encountered while introspecting the bean class.
See Also:
setBean(java.lang.Object)
Method Detail

propertyChange

public void propertyChange(PropertyChangeEvent event)
Implementation of the method defined in PropertyChangeListener.

Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
event - A PropertyChangeEvent object describing the event source and the property that has changed.
See Also:
modifyPrimitive(java.beans.PropertyChangeEvent, java.beans.PropertyDescriptor), modifyObject(java.beans.PropertyChangeEvent, java.beans.PropertyDescriptor)

initProperties

protected void initProperties()
                       throws IntrospectionException
Populate properties by introspecting the bean.

Throws:
IntrospectionException - If errors are encountered while introspecting the bean class.

modifyPrimitive

protected void modifyPrimitive(PropertyChangeEvent event,
                               PropertyDescriptor descriptor)
                        throws RuntimeException
Modify a primitive property in bean.

Parameters:
event - A PropertyChangeEvent object that contains the property to change and the old and new values.
descriptor - A PropertyDescriptor object that describes the property
Throws:
RuntimeException - If the appropriate mutator method for the property cannot be accessed, or if the specified value does not directly match a primitive type or is not a string.

objectFromString

protected Object objectFromString(PropertyChangeEvent event,
                                  PropertyDescriptor descriptor)
                           throws RuntimeException
Convert the given String value to an Object wrapper of the appropriate kind.

Parameters:
event - A PropertyChangeEvent object that contains the property to change and the old and new values.
descriptor - A PropertyDescriptor object that describes the property
Returns:
The object wrapper for the string.
Throws:
RuntimeException - If errors are encountered while trying to initialise the wrapper object.

modifyObject

protected void modifyObject(PropertyChangeEvent event,
                            PropertyDescriptor descriptor)
                     throws RuntimeException
Modify an object property in bean.

Parameters:
event - A PropertyChangeEvent object that contains the property to change and the old and new values.
descriptor - A PropertyDescriptor object that describes the property
Throws:
RuntimeException - If errors are encountered while trying to invoke the mutator method.

getBean

public final Object getBean()
Returns bean.

Returns:
Object The value/reference of/to bean.

setBean

public void setBean(Object bean)
             throws IntrospectionException
Set bean. Re-initialises properties.

Parameters:
bean - The value to set.
Throws:
IntrospectionException - If errors are encountered while introspecting the bean class.
See Also:
initProperties()

getProperties

public final HashMap<String,PropertyDescriptor> getProperties()
Returns a shallow-clone of properties.

Returns:
HashMap The value/reference of/to properties.

SPT Core API