org.springframework.binding.validation.support
Class DefaultValidationResultsModel

Show UML class diagram
java.lang.Object
  extended by org.springframework.binding.validation.support.DefaultValidationResultsModel
All Implemented Interfaces:
PropertyChangeListener, EventListener, ValidationListener, ValidationResults, ValidationResultsModel, PropertyChangePublisher

public class DefaultValidationResultsModel
extends Object
implements ValidationResultsModel, ValidationListener, PropertyChangeListener

Default implementation of ValidationResultsModel. Several events are fired when validationResults are set and can be tracked by registering the appropriate listener.

You can register listeners on:

A child-parent relation can be used to bundle events and results. A listener set on a parent will receive events originating from the child and when polling for messages, childMessages will be available as well. This makes it possible to efficiently couple formModels and their validation aspect and provides a means to bundle validation reporting. When eg using a {@link org.springframework.richclient.form.ValidationResultsReporter}, you have the opportunity to bundle results from various unrelated formModels to report to one end point.

Example:

 DefaultFormModel formModelA = ...
 DefaultFormModel formModelChildOfA = ...
 formModelA.addChild(formModelChildOfA);
 
 DefaultFormModel formModelB = ...
 
 \\ At this stage, the ValidationResultsModel of formModelChildOfA will route results & 
 \\ events to the ValidationResultsModel of formModelA
 
 DefaultValidationResultsModel container = new DefaultValidationResultsModel();
 container.add(formModelA.getValidationResults());
 container.add(formModelB.getValidationResults());
 
 new SimpleValidationResultsReporter(container, messagable);
 
 \\ the reporter will now receive events & results of all formModels and can show messages of each of them
 
 

Author:
Oliver Hutchison, Jan Hoskens
See Also:
DefaultFormModel.addChild(org.springframework.binding.form.HierarchicalFormModel), SimpleValidationResultsReporter

Field Summary
 
Fields inherited from interface org.springframework.binding.validation.ValidationResultsModel
HAS_ERRORS_PROPERTY, HAS_INFO_PROPERTY, HAS_WARNINGS_PROPERTY
 
Constructor Summary
DefaultValidationResultsModel()
          Constructor without delegate.
DefaultValidationResultsModel(ValidationResultsModel delegateFor)
          Constructor with delegate.
 
Method Summary
 void add(ValidationResultsModel validationResultsModel)
          Add a validationResultsModel as a child to this one.
 void addMessage(ValidationMessage validationMessage)
           
 void addPropertyChangeListener(PropertyChangeListener listener)
          Register a listener to all properties of this publisher.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Register a listener to a specific property.
 void addValidationListener(String propertyName, ValidationListener listener)
          Adds a listener that will be notified when there is any change to the set validation messages for the specified property.
 void addValidationListener(ValidationListener listener)
          Adds a listener that will be notified when there is any change to the set of validation messages.
 void clearAllValidationResults()
           
protected  void fireChangedEvents()
           
protected  void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
           
protected  void fireValidationResultsChanged()
           
protected  void fireValidationResultsChanged(String propertyName)
           
 boolean getHasErrors()
          Returns true of there are any validation messages of Severity.ERROR.
 boolean getHasInfo()
          Returns true of there are any validation messages of Severity.INFO.
 boolean getHasWarnings()
          Returns true of there are any validation messages of Severity.WARNING.
 int getMessageCount()
          Returns the total number of validation messages.
 int getMessageCount(Severity severity)
          Returns the total number of validation messages of the specified Severity.
 int getMessageCount(String propertyName)
          Returns the total number of validation messages that apply to the specified property name.
 Set getMessages()
          Returns a set holding all of the validation messages.
 Set getMessages(Severity severity)
          Returns a set holding all of the validation messages of the specified Severity.
 Set getMessages(String propertyName)
          Returns a set holding all of the validation messages that apply to the specified property name.
protected  EventListenerListHelper getPropertyChangeListeners(String propertyName)
           
protected  EventListenerListHelper getValidationListeners(String propertyName)
           
 void propertyChange(PropertyChangeEvent evt)
          Forwarding of known property events coming from child models.
 void remove(ValidationResultsModel validationResultsModel)
          Remove the given validationResultsModel from the list of children.
 void removeMessage(ValidationMessage validationMessage)
           
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove the listener from all properties of this publisher.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Remove the listener from a specific property.
 void removeValidationListener(String propertyName, ValidationListener listener)
          Removes the provided validation listener.
 void removeValidationListener(ValidationListener listener)
          Removes the provided validation listener.
 void replaceMessage(ValidationMessage messageToReplace, ValidationMessage replacementMessage)
           
 String toString()
           
 void updateValidationResults(ValidationResults newValidationResults)
           
 void validationResultsChanged(ValidationResults results)
          DefaultValidationResultsModel registers itself as a validationListener on it's children to forward the event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultValidationResultsModel

public DefaultValidationResultsModel()
Constructor without delegate. (Delegating for 'this').


DefaultValidationResultsModel

public DefaultValidationResultsModel(ValidationResultsModel delegateFor)
Constructor with delegate.

Parameters:
delegateFor - delegate object.
Method Detail

updateValidationResults

public void updateValidationResults(ValidationResults newValidationResults)

addMessage

public void addMessage(ValidationMessage validationMessage)

removeMessage

public void removeMessage(ValidationMessage validationMessage)

replaceMessage

public void replaceMessage(ValidationMessage messageToReplace,
                           ValidationMessage replacementMessage)

clearAllValidationResults

public void clearAllValidationResults()

getHasErrors

public boolean getHasErrors()
Description copied from interface: ValidationResults
Returns true of there are any validation messages of Severity.ERROR.

Specified by:
getHasErrors in interface ValidationResults
Returns:
true if this instance of one of its children has errors contained in their results.

getHasInfo

public boolean getHasInfo()
Description copied from interface: ValidationResults
Returns true of there are any validation messages of Severity.INFO.

Specified by:
getHasInfo in interface ValidationResults
Returns:
true if this instance of one of its children has info contained in their results.

getHasWarnings

public boolean getHasWarnings()
Description copied from interface: ValidationResults
Returns true of there are any validation messages of Severity.WARNING.

Specified by:
getHasWarnings in interface ValidationResults
Returns:
true if this instance of one of its children has warnings contained in their results.

getMessageCount

public int getMessageCount()
Description copied from interface: ValidationResults
Returns the total number of validation messages.

Specified by:
getMessageCount in interface ValidationResults

getMessageCount

public int getMessageCount(Severity severity)
Description copied from interface: ValidationResults
Returns the total number of validation messages of the specified Severity.

Specified by:
getMessageCount in interface ValidationResults

getMessageCount

public int getMessageCount(String propertyName)
Description copied from interface: ValidationResults
Returns the total number of validation messages that apply to the specified property name.

Specified by:
getMessageCount in interface ValidationResults

getMessages

public Set getMessages()
Description copied from interface: ValidationResults
Returns a set holding all of the validation messages.

Specified by:
getMessages in interface ValidationResults

getMessages

public Set getMessages(Severity severity)
Description copied from interface: ValidationResults
Returns a set holding all of the validation messages of the specified Severity.

Specified by:
getMessages in interface ValidationResults

getMessages

public Set getMessages(String propertyName)
Description copied from interface: ValidationResults
Returns a set holding all of the validation messages that apply to the specified property name.

Specified by:
getMessages in interface ValidationResults

addValidationListener

public void addValidationListener(ValidationListener listener)
Description copied from interface: ValidationResultsModel
Adds a listener that will be notified when there is any change to the set of validation messages.

Specified by:
addValidationListener in interface ValidationResultsModel

removeValidationListener

public void removeValidationListener(ValidationListener listener)
Description copied from interface: ValidationResultsModel
Removes the provided validation listener.

Specified by:
removeValidationListener in interface ValidationResultsModel

addValidationListener

public void addValidationListener(String propertyName,
                                  ValidationListener listener)
Description copied from interface: ValidationResultsModel
Adds a listener that will be notified when there is any change to the set validation messages for the specified property.

Specified by:
addValidationListener in interface ValidationResultsModel

removeValidationListener

public void removeValidationListener(String propertyName,
                                     ValidationListener listener)
Description copied from interface: ValidationResultsModel
Removes the provided validation listener.

Specified by:
removeValidationListener in interface ValidationResultsModel

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: PropertyChangePublisher
Register a listener to all properties of this publisher.

Specified by:
addPropertyChangeListener in interface PropertyChangePublisher
Parameters:
listener - the PropertyChangeListener to register.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: PropertyChangePublisher
Remove the listener from all properties of this publisher.

Specified by:
removePropertyChangeListener in interface PropertyChangePublisher
Parameters:
listener - the PropertyChangeListener to remove.

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Description copied from interface: PropertyChangePublisher
Register a listener to a specific property.

Specified by:
addPropertyChangeListener in interface PropertyChangePublisher
Parameters:
propertyName - the property to monitor.
listener - the PropertyChangeListener to register.

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Description copied from interface: PropertyChangePublisher
Remove the listener from a specific property.

Specified by:
removePropertyChangeListener in interface PropertyChangePublisher
Parameters:
propertyName - the property that was being monitored.
listener - the PropertyChangeListener to remove.

fireChangedEvents

protected void fireChangedEvents()

fireValidationResultsChanged

protected void fireValidationResultsChanged()

fireValidationResultsChanged

protected void fireValidationResultsChanged(String propertyName)

getValidationListeners

protected EventListenerListHelper getValidationListeners(String propertyName)

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  boolean oldValue,
                                  boolean newValue)

getPropertyChangeListeners

protected EventListenerListHelper getPropertyChangeListeners(String propertyName)

toString

public String toString()
Overrides:
toString in class Object

add

public void add(ValidationResultsModel validationResultsModel)
Add a validationResultsModel as a child to this one. Attach listeners and if it already has messages, fire events.

Specified by:
add in interface ValidationResultsModel
Parameters:
validationResultsModel -

remove

public void remove(ValidationResultsModel validationResultsModel)
Remove the given validationResultsModel from the list of children. Remove listeners and if it had messages, fire events.

Specified by:
remove in interface ValidationResultsModel
Parameters:
validationResultsModel -

validationResultsChanged

public void validationResultsChanged(ValidationResults results)
DefaultValidationResultsModel registers itself as a validationListener on it's children to forward the event.

Specified by:
validationResultsChanged in interface ValidationListener
Parameters:
results - the set of valiation results, this set will incude results for all properties even if the listener is only listening for changes to a specific properties results.

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Forwarding of known property events coming from child models. Each event triggers a specific evaluation of the parent property, which will trigger events as needed.

Specified by:
propertyChange in interface PropertyChangeListener


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