atg.beans
Class DynamicBeanState

java.lang.Object
  extended by atg.beans.DynamicBeanState
All Implemented Interfaces:
java.io.Serializable

public class DynamicBeanState
extends java.lang.Object
implements java.io.Serializable

A DynamicBeanState is used to package the state of a DynamicBean's properties and metadata in a serializable form, regardless of the serializability of the original DynamicBean.

When a DynamicBeanState's properties are changed, it keeps track of the changed properties and can subsequently apply only these changes to the original DynamicBean. It can also copy all of its properties into a fresh DynamicBean.

Note that a DynamicBeanState is itself a dynamic bean, and so it can be treated as a surrogate for the original source bean. This is handy, for example, when a client VM wishes to modify the properties of some dynamic bean on the server VM without actually deserializing or instantiating the server bean on the client side.

See Also:
Serialized Form

Field Summary
static java.lang.String CLASS_VERSION
           
 
Constructor Summary
DynamicBeanState(java.lang.Object pBean)
          Construct a DynamicBeanState initialized from the given "source bean".
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Register a listener for the PropertyChange event.
 void applyChanges(java.lang.Object pBean)
          Saves all changed properties of this DynamicBeanState into a DynamicBean.
 void applyState(java.lang.Object pBean)
          Saves all properties (not only the changed ones) of this DynamicBeanState into a DynamicBean.
 void clearDeltas()
          Clears the record of which properties were changed since this state was last initialized.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Fire a PropertyChange event to all registered listeners.
 DynamicBeanInfo getBeanInfo()
          Returns the DynamicBeanInfo for this state's source bean, resolving the bean info first, if necessary.
 java.util.Vector getModifiedProperties()
           
 DynamicPropertyDescriptor getPropertyDescriptor(java.lang.String pName)
          Returns the DynamicPropertyDescriptor for the specified property.
 java.lang.String[] getPropertyNames()
          Returns the list of known property names.
 java.lang.Object getPropertyValue(java.lang.String pName)
          Retrieves a property value of this state.
 void initializeFrom(java.lang.Object pBean)
          Initialize this DynamicBeanState from the given "source bean".
 boolean isModified()
          Has this bean been modified?
protected  boolean isSerializableClass(java.lang.Class cl)
          Determine if a property value should be serialized as-is.
protected  boolean readValue(java.util.Hashtable pProperties, java.lang.String pName, java.lang.Object pValue)
          When unserializing a value you may need to revert it to its original type.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a listener for the PropertyChange event.
protected  java.lang.Object replaceBeanInfo(DynamicBeanInfo pInfo)
          When serializing a DynamicBeanInfo, it may need to be replaced with some portable representation.
protected  DynamicBeanInfo resolveBeanInfo(java.lang.Object pValue)
          When deserializing a DynamicBeanInfo, the read object may need to be resolved from some portable representation.
 void setBeanInfo(DynamicBeanInfo info)
           
 void setPropertyValue(java.lang.String pName, java.lang.Object pValue)
          Changes a property value of this state, recording it as a changed property.
protected  boolean writeValue(java.util.Hashtable pProperties, java.lang.String pName, java.lang.Object pValue)
          When serializing a value you may need to convert it to a serializable type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Constructor Detail

DynamicBeanState

public DynamicBeanState(java.lang.Object pBean)
                 throws java.beans.IntrospectionException
Construct a DynamicBeanState initialized from the given "source bean". The state will exhibit the DynamicBeanInfo of the source bean, and will contain all of its properties.

Parameters:
pBean - the source bean from which the DynamicBeanState should be initialized.
Throws:
java.beans.IntrospectionException
Method Detail

initializeFrom

public void initializeFrom(java.lang.Object pBean)
                    throws java.beans.IntrospectionException
Initialize this DynamicBeanState from the given "source bean". The state will exhibit the DynamicBeanInfo of the source bean, and will contain all of its properties.

Parameters:
pBean - the source bean from which this state should be initialized.
Throws:
java.beans.IntrospectionException

getBeanInfo

public DynamicBeanInfo getBeanInfo()
Returns the DynamicBeanInfo for this state's source bean, resolving the bean info first, if necessary.


setBeanInfo

public void setBeanInfo(DynamicBeanInfo info)

getPropertyDescriptor

public DynamicPropertyDescriptor getPropertyDescriptor(java.lang.String pName)
Returns the DynamicPropertyDescriptor for the specified property.

Parameters:
pName - the name of the property
Returns:
null if the DynamicBeanInfo has no such property.

getPropertyNames

public java.lang.String[] getPropertyNames()
Returns the list of known property names.


clearDeltas

public void clearDeltas()
Clears the record of which properties were changed since this state was last initialized.


isModified

public boolean isModified()
Has this bean been modified?


getModifiedProperties

public java.util.Vector getModifiedProperties()

getPropertyValue

public java.lang.Object getPropertyValue(java.lang.String pName)
Retrieves a property value of this state.

Parameters:
pName - the name of the property whose value is to be retrieved
Returns:
the value of the property

setPropertyValue

public void setPropertyValue(java.lang.String pName,
                             java.lang.Object pValue)
Changes a property value of this state, recording it as a changed property. Also fires a PropertyChange event to signal the change to listeners.

Parameters:
pName - the name of the property to be changed
pValue - the new value of the property

applyChanges

public void applyChanges(java.lang.Object pBean)
                  throws PropertyNotFoundException
Saves all changed properties of this DynamicBeanState into a DynamicBean.

Parameters:
pBean - the bean to which the changes are to be applied
Throws:
PropertyNotFoundException - if one of the changed properties cannot be applied.

applyState

public void applyState(java.lang.Object pBean)
                throws PropertyNotFoundException
Saves all properties (not only the changed ones) of this DynamicBeanState into a DynamicBean.

Parameters:
pBean - the bean to which the changes are to be applied
Throws:
PropertyNotFoundException - if one of the changed properties cannot be applied.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Register a listener for the PropertyChange event. The component state should fire a PropertyChange event whenever it is changed.

Parameters:
listener - An object to be invoked when a PropertyChange event is fired.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a listener for the PropertyChange event.

Parameters:
listener - The PropertyChange listener to be removed.

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Fire a PropertyChange event to all registered listeners. Occurs when setPropertyValue() is called.


isSerializableClass

protected boolean isSerializableClass(java.lang.Class cl)
Determine if a property value should be serialized as-is.


replaceBeanInfo

protected java.lang.Object replaceBeanInfo(DynamicBeanInfo pInfo)
When serializing a DynamicBeanInfo, it may need to be replaced with some portable representation. Subclasses may override this method to do so.


resolveBeanInfo

protected DynamicBeanInfo resolveBeanInfo(java.lang.Object pValue)
When deserializing a DynamicBeanInfo, the read object may need to be resolved from some portable representation. Subclasses may override this method to do so.


writeValue

protected boolean writeValue(java.util.Hashtable pProperties,
                             java.lang.String pName,
                             java.lang.Object pValue)
When serializing a value you may need to convert it to a serializable type. Here a property of type Class is turned into an AliasedClass. Subclasses may add their own conversions here.


readValue

protected boolean readValue(java.util.Hashtable pProperties,
                            java.lang.String pName,
                            java.lang.Object pValue)
When unserializing a value you may need to revert it to its original type. Here the AliasedClass is be turned back into a Class. Subclasses may add their own conversions here.