com.sptci
Class PropertyChangeListener

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

public class PropertyChangeListener
extends java.lang.Object
implements java.beans.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,v 1.3 2006/02/08 23:31:16 rakesh Exp $
Author:
Rakesh Vidyadharan 2006-01-22

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

Field Detail

logger

private static final java.util.logging.Logger logger
The logger used to log errors/warnings.


typeMapping

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


bean

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


properties

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

Constructor Detail

PropertyChangeListener

protected PropertyChangeListener()
Default constructor. Initialises properties.


PropertyChangeListener

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

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

propertyChange

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

Specified by:
propertyChange in interface java.beans.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 java.beans.IntrospectionException
Populate properties by introspecting the bean.

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

modifyPrimitive

protected void modifyPrimitive(java.beans.PropertyChangeEvent event,
                               java.beans.PropertyDescriptor descriptor)
                        throws java.lang.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:
java.lang.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 java.lang.Object objectFromString(java.beans.PropertyChangeEvent event,
                                            java.beans.PropertyDescriptor descriptor)
                                     throws java.lang.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
Throws:
java.lang.RuntimeException - If errors are encountered while trying to initialise the wrapper object.

modifyObject

protected void modifyObject(java.beans.PropertyChangeEvent event,
                            java.beans.PropertyDescriptor descriptor)
                     throws java.lang.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:
java.lang.RuntimeException - If errors are encountered while trying to invoke the mutator method.

getBean

public final java.lang.Object getBean()
Returns bean.

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

setBean

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

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

getProperties

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

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


Copyright © 2006 Sans Pareil Technologies, Inc. All Rights Reserved.