org.springframework.binding.value.support
Class AbstractValueModel

java.lang.Object
  extended by org.springframework.binding.value.support.AbstractPropertyChangePublisher
      extended by org.springframework.binding.value.support.AbstractValueModel
All Implemented Interfaces:
PropertyChangePublisher, ValueModel
Direct Known Subclasses:
AbstractDerivedValueModel, AbstractIndexAdapter, BufferedValueModel, ListSelectionValueModelAdapter, MapKeyAdapter, ValueHolder

public abstract class AbstractValueModel
extends AbstractPropertyChangePublisher
implements ValueModel

An abstract class that minimizes the effort required to implement the ValueModel interface. It provides convenience methods to convert boolean, double, float, int, and long to their corresponding Object values.

Subclasses must implement getValue() and setValue(Object) to get and set the observable value.

Author:
Karsten Lentzsch, Keith Donald, Oliver Hutchison

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Fields inherited from interface org.springframework.binding.value.ValueModel
VALUE_PROPERTY
 
Constructor Summary
AbstractValueModel()
           
 
Method Summary
 void addValueChangeListener(PropertyChangeListener listener)
          Registers the given PropertyChangeListener with this ValueModel.
protected  void fireValueChange(boolean oldValue, boolean newValue)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireValueChange(double oldValue, double newValue)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireValueChange(int oldValue, int newValue)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireValueChange(long oldValue, long newValue)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireValueChange(Object oldValue, Object newValue)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireValueChangeEvent(Object oldValue, Object newValue)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireValueChangeWhenStillEqual()
          This method can be called when it in necessary to send a PropertyChangeEvent to any registered PropertyChangeListeners even though the encapsulated value has not changed.
protected  ValueChangeDetector getValueChangeDetector()
          Get the installed value change detector.
protected  boolean hasValueChanged(Object oldValue, Object newValue)
          Delegates to configured ValueChangeDetector.
 void removeValueChangeListener(PropertyChangeListener listener)
          Deregisters the given PropertyChangeListener from this ValueModel.
 void setValueChangeDetector(ValueChangeDetector valueChangeDetector)
          Set the object that will be used to detect changes between two values.
 void setValueSilently(Object newValue, PropertyChangeListener listenerToSkip)
          Sets a new value and if the value has changed notifies all registered value change listeners except for the specified listener to skip.
 
Methods inherited from class org.springframework.binding.value.support.AbstractPropertyChangePublisher
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, firePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasChanged, hasChanged, hasChanged, hasChanged, hasChanged, hasChanged, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.binding.value.ValueModel
getValue, setValue
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

AbstractValueModel

public AbstractValueModel()
Method Detail

setValueSilently

public final void setValueSilently(Object newValue,
                                   PropertyChangeListener listenerToSkip)
Description copied from interface: ValueModel
Sets a new value and if the value has changed notifies all registered value change listeners except for the specified listener to skip.

Specified by:
setValueSilently in interface ValueModel
Parameters:
newValue - the value to be set
listenerToSkip - the PropertyChangeListener that should not be notified of this change (may be null).

addValueChangeListener

public final void addValueChangeListener(PropertyChangeListener listener)
Description copied from interface: ValueModel
Registers the given PropertyChangeListener with this ValueModel. The listener will be notified if the value has changed. The PropertyChangeEvents delivered to the listener must have the name set to "value". The latter ensures that all ValueModel implementers behave like the AbstractValueModel subclasses.

To comply with the above specification implementers can use the PropertyChangeSupport's #addPropertyChangeListener method that accepts a property name, so that listeners will be invoked only if that specific property has changed.

Specified by:
addValueChangeListener in interface ValueModel
Parameters:
listener - the listener to be added
See Also:
addValueChangeListener(PropertyChangeListener)

removeValueChangeListener

public final void removeValueChangeListener(PropertyChangeListener listener)
Description copied from interface: ValueModel
Deregisters the given PropertyChangeListener from this ValueModel.

Specified by:
removeValueChangeListener in interface ValueModel
Parameters:
listener - the listener to be removed

fireValueChangeWhenStillEqual

protected void fireValueChangeWhenStillEqual()
This method can be called when it in necessary to send a PropertyChangeEvent to any registered PropertyChangeListeners even though the encapsulated value has not changed. FIXME: This needs a much better name!


fireValueChange

protected final void fireValueChange(boolean oldValue,
                                     boolean newValue)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
oldValue - the boolean value before the change
newValue - the boolean value after the change

fireValueChange

protected final void fireValueChange(int oldValue,
                                     int newValue)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
oldValue - the int value before the change
newValue - the int value after the change

fireValueChange

protected final void fireValueChange(long oldValue,
                                     long newValue)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
oldValue - the long value before the change
newValue - the long value after the change

fireValueChange

protected final void fireValueChange(double oldValue,
                                     double newValue)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
oldValue - the double value before the change
newValue - the double value after the change

fireValueChange

protected void fireValueChange(Object oldValue,
                               Object newValue)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
oldValue - the float value before the change
newValue - the float value after the change

hasValueChanged

protected boolean hasValueChanged(Object oldValue,
                                  Object newValue)
Delegates to configured ValueChangeDetector.


fireValueChangeEvent

protected void fireValueChangeEvent(Object oldValue,
                                    Object newValue)
Notifies all listeners that have registered interest for notification on this event type. This method does not check if there is any change between the old and new value unlike the various fireValueChanged() methods.


setValueChangeDetector

public void setValueChangeDetector(ValueChangeDetector valueChangeDetector)
Set the object that will be used to detect changes between two values.

Parameters:
valueChangeDetector - to use

getValueChangeDetector

protected ValueChangeDetector getValueChangeDetector()
Get the installed value change detector. If none has been directly installed then get the one configured in the application context.

Returns:
value change detector to use


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.