livespace.services
Class PropertySynchronizer

java.lang.Object
  extended by livespace.services.Synchronizer
      extended by livespace.services.PropertySynchronizer
All Implemented Interfaces:
PropertyListener, EventListener

public class PropertySynchronizer
extends Synchronizer

Allows synchronisation to take place when a given property changes to a set value.

Author:
Matthew Phillips

Field Summary
static Object NON_NULL_VALUE
          Indicates any non-null value.
protected  PropertyPath propertyPath
           
protected  Object value
           
 
Fields inherited from class livespace.services.Synchronizer
source, synced
 
Constructor Summary
PropertySynchronizer(IDataObject source, Object property, Object value)
          Create a new instance.
PropertySynchronizer(IDataObject source, PropertyPath path, Object value)
          Create a new instance.
PropertySynchronizer(IDataObject source, String path, Object value)
          Create a new instance.
 
Method Summary
protected  String createFailMessage()
          Create an error message indicating why synchronization has failed.
 Object getValue(IDataObject object)
          Shortcut to get the value of the property for a given object.
protected  boolean isSynchronized()
          Called to test whether the object is currently synchronized.
protected  boolean isSynchronized(PropertyEvent e)
          This is called whenever a property changes on the object of interest.
static void waitForNonNullProperty(IDataObject object, Object property)
          Shortcut for using this class to wait for a property to become any non-null value (i.e.
static void waitForNonNullProperty(IDataObject object, String path)
          Shortcut for using this class to wait for a property path to become any non-null value (i.e.
static void waitForProperty(IDataObject object, Object property, Object value)
          Shortcut for using this class to wait for a property change.
static void waitForProperty(IDataObject object, String path, Object value)
          Shortcut for using this class to wait for a property change.
 
Methods inherited from class livespace.services.Synchronizer
propertyValueChanged, synchronize, synchronize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NON_NULL_VALUE

public static final Object NON_NULL_VALUE
Indicates any non-null value.


propertyPath

protected final PropertyPath propertyPath

value

protected final Object value
Constructor Detail

PropertySynchronizer

public PropertySynchronizer(IDataObject source,
                            Object property,
                            Object value)
Create a new instance.

Parameters:
source - The source object.
property - The property to monitor.
value - The new value. Use NON_NULL_VALUEto indicate match any non-null value for the property.

PropertySynchronizer

public PropertySynchronizer(IDataObject source,
                            String path,
                            Object value)
Create a new instance.

Parameters:
source - The source object.
path - The property path to monitor. This may be a property path in the form "property1/property2".
value - The new value. Use NON_NULL_VALUEto indicate match any non-null value for the property.

PropertySynchronizer

public PropertySynchronizer(IDataObject source,
                            PropertyPath path,
                            Object value)
Create a new instance.

Parameters:
source - The source object.
path - The property path to monitor.
value - The new value. Use NON_NULL_VALUEto indicate match any non-null value for the property.
Method Detail

waitForProperty

public static void waitForProperty(IDataObject object,
                                   Object property,
                                   Object value)
                            throws SynchronizationException
Shortcut for using this class to wait for a property change.

Parameters:
object - The obect to listen to.
property - The property.
value - The value.
Throws:
SynchronizationException - if property doesn't become equal to value within the default timeout.
See Also:
PropertySynchronizer(IDataObject, Object, Object)

waitForProperty

public static void waitForProperty(IDataObject object,
                                   String path,
                                   Object value)
                            throws SynchronizationException
Shortcut for using this class to wait for a property change.

Parameters:
object - The obect to listen to.
path - The property path of form "property1/property2/...".
value - The value.
Throws:
SynchronizationException - if property doesn't become equal to value within the default timeout.
See Also:
PropertySynchronizer(IDataObject, String, Object), PropertyPath.PropertyPath(String)

waitForNonNullProperty

public static void waitForNonNullProperty(IDataObject object,
                                          Object property)
                                   throws SynchronizationException
Shortcut for using this class to wait for a property to become any non-null value (i.e. to become a defined property).

Parameters:
object - The obect to listen to.
property - The property.
Throws:
SynchronizationException - if property doesn't become non-null within the default timeout.

waitForNonNullProperty

public static void waitForNonNullProperty(IDataObject object,
                                          String path)
                                   throws SynchronizationException
Shortcut for using this class to wait for a property path to become any non-null value (i.e. to become a defined property).

Parameters:
object - The obect to listen to.
path - The property path of form "property1/property2/...".
Throws:
SynchronizationException - if property doesn't become non-null within the default timeout.
See Also:
PropertyPath.PropertyPath(String)

getValue

public Object getValue(IDataObject object)
Shortcut to get the value of the property for a given object.


isSynchronized

protected boolean isSynchronized()
Description copied from class: Synchronizer
Called to test whether the object is currently synchronized.

Specified by:
isSynchronized in class Synchronizer

isSynchronized

protected boolean isSynchronized(PropertyEvent e)
Description copied from class: Synchronizer
This is called whenever a property changes on the object of interest. By default it simply calls Synchronizer.isSynchronized(). Subclasses may override this if they want to use the property change event as part of the test.

Overrides:
isSynchronized in class Synchronizer

createFailMessage

protected String createFailMessage()
Description copied from class: Synchronizer
Create an error message indicating why synchronization has failed.

Specified by:
createFailMessage in class Synchronizer


Copyright © 2008 Commonwealth of Australia