com.sas
Class PropertyLinkAdaptor

com.sas.PropertyLinkAdaptor
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener

public class PropertyLinkAdaptor
implements java.beans.PropertyChangeListener

PropertyLinkAdaptor is the controller which handles a property link between two properties. It listens for PropertyChangeEvents from the source property and calls the write method for the target property. The value of the source property may be transformed to a value suitable for the target property if an appropriate transform is registered (or set when the link is added).

PropertyLinkAdaptor tries to be efficient by caching as much information as possible about how to transform the source value and set it on the target property.

The PropertyLinkAdaptor also has the ability to use another object which implements the PropertyValueQueryInterface to get/set the property values to/from. This is useful in cases where real JavaBeans properties do not exist or the application wishes to avoid using reflection to get/set the property value.

See Also:
PropertyValueQueryInterface

Field Summary
protected  boolean enabled
          true if the link is enabled and PropertyChangeEvents are handled.
protected  java.util.EventListener eventListenerProxy
           
protected  java.util.Set interfaceSet
           
protected  boolean linkConnected
           
protected  com.sas.PropertyValueQueryInterface propertyValueSource
          null if the property values should be queried from the sourceObject.
protected  com.sas.PropertyValueQueryInterface propertyValueTarget
          null if the property values should be set by calling the sourceObject.
protected static java.util.Map proxyMap
           
static java.lang.String RB_KEY
           
protected  java.lang.Class sourceClass
          The cached Class of the source property value.
protected  java.lang.reflect.Method sourceGetMethod
          The cached "get" method for the source property.
protected static java.util.Map sourceMap
           
protected  java.lang.Object sourceObject
          The object whose property value change should trigger the link.
protected  java.lang.String sourceProperty
          The property of the source object which should trigger the link.
protected  java.lang.Class targetClass
          The cached Class of the target property value.
protected  java.lang.Object targetObject
          The object which should have its property value set when the source property changes.
protected  java.lang.String targetProperty
          The property of the target object which should be set with the value of the source property (or a transformation of that value) when the value of the source property changes.
protected  java.lang.reflect.Method targetSetMethod
          The cached "set" method for the target property.
protected  com.sas.util.transforms.TransformInterface transform
          The transform used to convert the value of the source property to the type used by the target property.
protected  boolean transformSpecified
          true if the transform was specified when the PropertyLinkAdaptor was created.
static java.util.Map userProxyMap
           
 
Constructor Summary
PropertyLinkAdaptor(java.lang.Object sourceObject, java.lang.Object targetObject, java.lang.String sourceProperty, java.lang.String targetProperty)
          Constructor.
PropertyLinkAdaptor(java.lang.Object sourceObject, java.lang.Object targetObject, java.lang.String sourceProperty, java.lang.String targetProperty, com.sas.util.transforms.TransformInterface specifiedTransform)
          Constructor.
PropertyLinkAdaptor(java.lang.Object sourceObject, java.lang.Object targetObject, java.lang.String sourceProperty, java.lang.String targetProperty, com.sas.util.transforms.TransformInterface specifiedTransform, com.sas.PropertyValueQueryInterface propertyValueSource, com.sas.PropertyValueQueryInterface propertyValueTarget)
          Constructor.
 
Method Summary
 void addLink()
          Add a link between the current source and target if one doesn't already exist.
static PropertyLinkAdaptor addLink(java.lang.Object sourceObject, java.lang.String sourceProperty, java.lang.Object targetObject, java.lang.String targetProperty)
          Utility method to create a link between two properties.
static PropertyLinkAdaptor addLink(java.lang.Object sourceObject, java.lang.String sourceProperty, java.lang.Object targetObject, java.lang.String targetProperty, com.sas.util.transforms.TransformInterface specifiedTransform)
          Utility method to create a link between two properties.
static PropertyLinkAdaptor addLink(java.lang.Object sourceObject, java.lang.String sourceProperty, java.lang.Object targetObject, java.lang.String targetProperty, com.sas.util.transforms.TransformInterface specifiedTransform, com.sas.PropertyValueQueryInterface propertyValueSource, com.sas.PropertyValueQueryInterface propertyValueTarget)
          Utility method to create a link between two properties.
protected  void addToSourceAdaptors()
          Add the current source object and property to a tracking map.
protected  void cleanUpLoopingHistory(java.beans.PropertyChangeEvent evt)
          Helper method to clean up the looping history on the target component.
protected static boolean containsProxy(java.lang.Class sourceClass, java.lang.String sourceProperty, java.util.Map listenerProxyMap)
          Test if the listener proxy map contains the specified source property.
protected  java.lang.Object createLinkListenerProxy(java.util.Set methodSet, java.util.Set interfaceSet, PropertyLinkAdaptor target)
          Create a proxy object that implements the interfaces from the interfaceSet.
protected  java.util.List findListenerMethodList(java.lang.Class sourceClass, java.lang.String sourceProperty)
          Find any listener methods for the specified source property.
protected  java.util.List getAdaptors(java.lang.Object source, java.lang.String propertyName)
           
protected  java.lang.Object getPropertyValue()
          Retrieves the value of the source property from the source component.
protected static java.util.Map getProxyMap()
          Get the current list of methods to use in the proxy for each specific property.
 java.lang.Object getSource()
           
 java.lang.String getSourceProperty()
           
 java.lang.Object getTarget()
           
 java.lang.String getTargetProperty()
           
 boolean isConnected()
          Determine if the PropertyLinkAdaptor is already connected.
 boolean isEnabled()
          isEnabled returns whether the link is currently handling PropertyChangeEvents received from the source component.
static boolean isLinkable(java.lang.Object source, java.lang.String property)
          Check if a specific property is able to be linked to.
protected static void loadProxyMap()
          Load the map of properties and methods to activate any links from those properties.
protected  void processEventListener(java.lang.String listenerOperation, java.util.Set listenerInterfaceSet, java.lang.Object eventSource, java.util.EventListener eventListener)
          Process the eventListener.
protected  void processInterfaceMethods(java.util.List listenerMethodList, java.util.Set interfaceSet, java.util.Set methodSet)
          Process the list of methods to produce an interface set and a method set.
protected  java.util.List processListenerMethodList(java.lang.String listenerList)
          Process the list of listenerInterfaces and methods.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          propertyChange handles the PropertyChangeEvent from the source object.
protected  boolean removeFromSourceAdaptors()
          Remove the current source object and property from the tracking map.
 void removeLink()
          Disconnect the current link if it is connected.
static void removeLink(PropertyLinkAdaptor adaptor)
          Utility method to remove a link between two properties.
 void setEnabled(boolean enabled)
          setEnabled sets whether the link is currently handling PropertyChangeEvents received from the source component.
protected  void setPropertyValue(java.lang.Object newValue)
          Sets the property value on the target property.
 void synchronizeValues()
          Synchonize the values of the source and the target of the link.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

sourceObject

protected java.lang.Object sourceObject
The object whose property value change should trigger the link.


targetObject

protected java.lang.Object targetObject
The object which should have its property value set when the source property changes.


sourceProperty

protected java.lang.String sourceProperty
The property of the source object which should trigger the link.


targetProperty

protected java.lang.String targetProperty
The property of the target object which should be set with the value of the source property (or a transformation of that value) when the value of the source property changes.


transform

protected com.sas.util.transforms.TransformInterface transform
The transform used to convert the value of the source property to the type used by the target property.


sourceGetMethod

protected java.lang.reflect.Method sourceGetMethod
The cached "get" method for the source property.


targetSetMethod

protected java.lang.reflect.Method targetSetMethod
The cached "set" method for the target property.


sourceClass

protected java.lang.Class sourceClass
The cached Class of the source property value.


targetClass

protected java.lang.Class targetClass
The cached Class of the target property value.


transformSpecified

protected boolean transformSpecified
true if the transform was specified when the PropertyLinkAdaptor was created. false otherwise.


propertyValueSource

protected com.sas.PropertyValueQueryInterface propertyValueSource
null if the property values should be queried from the sourceObject. If non-null, the property's value is queried from the the propertyValueSource object.


propertyValueTarget

protected com.sas.PropertyValueQueryInterface propertyValueTarget
null if the property values should be set by calling the sourceObject. If non-null, the property's value is set by calling the propertyValueTarget object.


enabled

protected boolean enabled
true if the link is enabled and PropertyChangeEvents are handled. false if the link is disabled and PropertyChangeEvents are ignored.


interfaceSet

protected java.util.Set interfaceSet

eventListenerProxy

protected java.util.EventListener eventListenerProxy

linkConnected

protected boolean linkConnected

sourceMap

protected static java.util.Map sourceMap

proxyMap

protected static java.util.Map proxyMap

userProxyMap

public static java.util.Map userProxyMap
Constructor Detail

PropertyLinkAdaptor

public PropertyLinkAdaptor(java.lang.Object sourceObject,
                           java.lang.Object targetObject,
                           java.lang.String sourceProperty,
                           java.lang.String targetProperty)
Constructor.

Parameters:
sourceObject - The object to listen for changes to the value of the sourceProperty on.
targetObject - The object to set the value on when the link is triggered.
sourceProperty - The property on the source object to listen for changes to.
targetProperty - The property on the target object to set.

PropertyLinkAdaptor

public PropertyLinkAdaptor(java.lang.Object sourceObject,
                           java.lang.Object targetObject,
                           java.lang.String sourceProperty,
                           java.lang.String targetProperty,
                           com.sas.util.transforms.TransformInterface specifiedTransform)
Constructor.

Parameters:
sourceObject - The object to listen for changes to the value of the sourceProperty on.
targetObject - The object to set the value on when the link is triggered.
sourceProperty - The property on the source object to listen for changes to.
targetProperty - The property on the target object to set.
specifiedTransform - The transform to be used to convert the source property value to the target property type.

PropertyLinkAdaptor

public PropertyLinkAdaptor(java.lang.Object sourceObject,
                           java.lang.Object targetObject,
                           java.lang.String sourceProperty,
                           java.lang.String targetProperty,
                           com.sas.util.transforms.TransformInterface specifiedTransform,
                           com.sas.PropertyValueQueryInterface propertyValueSource,
                           com.sas.PropertyValueQueryInterface propertyValueTarget)
Constructor.

Parameters:
sourceObject - The object to listen for changes to the value of the sourceProperty on.
targetObject - The object to set the value on when the link is triggered.
sourceProperty - The property on the source object to listen for changes to.
targetProperty - The property on the target object to set.
specifiedTransform - The transform to be used to convert the source property value to the target property type.
propertyValueSource - The object to get/set the property values from. Passing in null means that reflection should be used to get/set the value of the property from the sourceObject and the targetObject.
Method Detail

addLink

public static PropertyLinkAdaptor addLink(java.lang.Object sourceObject,
                                          java.lang.String sourceProperty,
                                          java.lang.Object targetObject,
                                          java.lang.String targetProperty)
Utility method to create a link between two properties.

Parameters:
sourceObject - The object to listen for changes to the value of the sourceProperty on.
targetObject - The object to set the value on when the link is triggered.
sourceProperty - The property on the source object to listen for changes to.
targetProperty - The property on the target object to set.

addLink

public static PropertyLinkAdaptor addLink(java.lang.Object sourceObject,
                                          java.lang.String sourceProperty,
                                          java.lang.Object targetObject,
                                          java.lang.String targetProperty,
                                          com.sas.util.transforms.TransformInterface specifiedTransform)
Utility method to create a link between two properties. The transform to be used to convert the source property value to the target property type may be specified.

Parameters:
sourceObject - The object to listen for changes to the value of the sourceProperty on.
targetObject - The object to set the value on when the link is triggered.
sourceProperty - The property on the source object to listen for changes to.
targetProperty - The property on the target object to set.
specifiedTransform - The transform to be used to convert the source property value to the target property type. This value may be null, indicating that a transform will be looked up in the list of registered transforms.

addLink

public static PropertyLinkAdaptor addLink(java.lang.Object sourceObject,
                                          java.lang.String sourceProperty,
                                          java.lang.Object targetObject,
                                          java.lang.String targetProperty,
                                          com.sas.util.transforms.TransformInterface specifiedTransform,
                                          com.sas.PropertyValueQueryInterface propertyValueSource,
                                          com.sas.PropertyValueQueryInterface propertyValueTarget)
Utility method to create a link between two properties. The transform to be used to convert the source property value to the target property type may be specified. This method will create a new adaptor object and then call addLink() on the new adaptor.

Parameters:
sourceObject - The object to listen for changes to the value of the sourceProperty on.
targetObject - The object to set the value on when the link is triggered.
sourceProperty - The property on the source object to listen for changes to.
targetProperty - The property on the target object to set.
specifiedTransform - The transform to be used to convert the source property value to the target property type. This value may be null, indicating that a transform will be looked up in the list of registered transforms.
propertyValueSource - The object to get/set the property values from. Passing in null means that reflection should be used to get/set the value of the property from the sourceObject and the targetObject.

isLinkable

public static boolean isLinkable(java.lang.Object source,
                                 java.lang.String property)
Check if a specific property is able to be linked to. To be linkable, the property either has to be specified using com.sas.beans.PropertyDescriptor objects, be a bound property, or have an entry in the proxy map or the user proxy map.

Parameters:
source - the source object that the link will get the value for the target from
property - the property on the source to check if it is linkable

isConnected

public boolean isConnected()
Determine if the PropertyLinkAdaptor is already connected. This is set to true when addLink() is initially called and false when removeLink() is called. A link can also be disabled but still connected. When a link is connected, all the listeners between the source and target objects are still connected.

Returns:
true if the link is connected

getSource

public java.lang.Object getSource()

getTarget

public java.lang.Object getTarget()

getSourceProperty

public java.lang.String getSourceProperty()

getTargetProperty

public java.lang.String getTargetProperty()

createLinkListenerProxy

protected java.lang.Object createLinkListenerProxy(java.util.Set methodSet,
                                                   java.util.Set interfaceSet,
                                                   PropertyLinkAdaptor target)
Create a proxy object that implements the interfaces from the interfaceSet. The proxy will handle the methods provided by the method set and call the target.synchronizeValues() method when any of those methods are called.

Parameters:
methodSet - the methods which the proxy specifically handle
interfaceSet - the interfaces which the proxy will implement
target - the PropertyLinkAdaptor to call synchronizeValues() on when one of the methods in the methodSet is called

processInterfaceMethods

protected void processInterfaceMethods(java.util.List listenerMethodList,
                                       java.util.Set interfaceSet,
                                       java.util.Set methodSet)
Process the list of methods to produce an interface set and a method set. If the list includes a .class entry, then a instance of the class is created and will be added to a list of LinkEventInterface objects. The interface set will include the Class objects for the interface and the method set will include the Method objects.


loadProxyMap

protected static void loadProxyMap()
Load the map of properties and methods to activate any links from those properties.


getProxyMap

protected static java.util.Map getProxyMap()
Get the current list of methods to use in the proxy for each specific property. The map includes the source property as the key and the method used to activate the link for that property. The map will be loaded if it hasn't already been and then any user mappings will be applied.


processListenerMethodList

protected java.util.List processListenerMethodList(java.lang.String listenerList)
Process the list of listenerInterfaces and methods.

Returns:
a list of listener interface method names

containsProxy

protected static boolean containsProxy(java.lang.Class sourceClass,
                                       java.lang.String sourceProperty,
                                       java.util.Map listenerProxyMap)
Test if the listener proxy map contains the specified source property. This method will walk up the class heirarchy to find a map entry that contains the property.

Parameters:
sourceClass - the class of with the property to find in the listener proxy map
sourceProperty - the property to find in the listener proxy map
listenerProxyMap - the map to search for the property

findListenerMethodList

protected java.util.List findListenerMethodList(java.lang.Class sourceClass,
                                                java.lang.String sourceProperty)
Find any listener methods for the specified source property. This method will walk up the class heirarchy to find a proxy map entry that contains the property.

Parameters:
sourceClass - the class of with the property to find in the listener proxy map
sourceProperty - the property to find in the listener proxy map

processEventListener

protected void processEventListener(java.lang.String listenerOperation,
                                    java.util.Set listenerInterfaceSet,
                                    java.lang.Object eventSource,
                                    java.util.EventListener eventListener)
Process the eventListener. Execute the specified method on the listener for each entry in the listenerInterfaceSet. An example method is an addActionListener(): "add" is the listenerOperation, ActionListener is the listener interface name, it is called on the eventSource, and the eventListener is passed in as the parameter.

Parameters:
listenerOperation - the prefix of the method to execute
listenerInterfaceSet - the set of listener interfaces to execute the method for
eventSource - the object used to execute the specified method
eventListener - the argument for the method to execute

addLink

public void addLink()
Add a link between the current source and target if one doesn't already exist.


addToSourceAdaptors

protected void addToSourceAdaptors()
Add the current source object and property to a tracking map.


removeFromSourceAdaptors

protected boolean removeFromSourceAdaptors()
Remove the current source object and property from the tracking map.

Returns:
true if the current source was removed, otherwise false is returned

getAdaptors

protected java.util.List getAdaptors(java.lang.Object source,
                                     java.lang.String propertyName)

synchronizeValues

public void synchronizeValues()
Synchonize the values of the source and the target of the link. This method will first check the values on each object to see if they are already equal. If they are not, the propertyChange() method is called to force the values to be synchonized. The get method for a property may be called from this method and also from the propertyChange() method.


removeLink

public static void removeLink(PropertyLinkAdaptor adaptor)
Utility method to remove a link between two properties.

Parameters:
adaptor - The adaptor that should no longer be linking.

removeLink

public void removeLink()
Disconnect the current link if it is connected. This will remove any proxy listeners that were added based on the proxy map. Also any LinkEventInterface objects that were used will have the link property set to null.


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
propertyChange handles the PropertyChangeEvent from the source object. It determines if the event is due to the source property and performs the link synchronization if it is. The value of the source property is either retrieved from the event or read of the source object. That value is then transformed (if necessary) to the Class of the target property. The value is then set on the target property of the target object.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
evt - The property change event from the source object.

cleanUpLoopingHistory

protected void cleanUpLoopingHistory(java.beans.PropertyChangeEvent evt)
Helper method to clean up the looping history on the target component.

Parameters:
evt - The PropertyChangeEvent that is currently being handled.

getPropertyValue

protected java.lang.Object getPropertyValue()
Retrieves the value of the source property from the source component. Reflection or a PropertyValueQueryInterface will be used to get the value.

Returns:
the value of the source property.

setPropertyValue

protected void setPropertyValue(java.lang.Object newValue)
Sets the property value on the target property. Reflection or a PropertyValueQueryInterface will be used to perform the set.

Parameters:
newValue - The new value for the property.

isEnabled

public boolean isEnabled()
isEnabled returns whether the link is currently handling PropertyChangeEvents received from the source component.

Returns:
whether the link is currently handling PropertyChangeEvents received from the source component.
See Also:
setEnabled(boolean)

setEnabled

public void setEnabled(boolean enabled)
setEnabled sets whether the link is currently handling PropertyChangeEvents received from the source component.

Parameters:
enabled - whether the link is currently handling PropertyChangeEvents received from the source component.
See Also:
isEnabled()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.