org.springframework.binding.validation.support
Class RulesValidator

java.lang.Object
  extended by org.springframework.binding.validation.support.RulesValidator
All Implemented Interfaces:
RichValidator, Validator, ObjectNameResolver

public class RulesValidator
extends Object
implements RichValidator, ObjectNameResolver

Implementation of a RichValidator which will check the formObject against rules found in a RulesSource. This RulesSource can be specifically supplied, which allows multiple rulesSources, or can be globally defined in the Application Context. In the latter case the RulesValidator will look for the specific RulesSource type in the context.

When validating an object, all results are cached. Any following validation of a specific property will validate that property, update the cached results accordingly and return all validation results of the object.

Author:
Keith Donald, Jan Hoskens

Constructor Summary
RulesValidator(FormModel formModel)
          Creates a RulesValidator for the given formModel.
RulesValidator(FormModel formModel, RulesSource rulesSource)
          Create a RulesValidator which uses the supplied RulesSource on the FormModel.
 
Method Summary
 void clearMessages()
          Clear the current validationMessages and the errors.
protected  void constraintSatisfied(PropertyConstraint exp)
           
protected  void constraintViolated(PropertyConstraint exp, PropertyResults propertyResults)
           
 String getRulesContextId()
          Returns the rules context id set on this validator.
 String resolveObjectName(String objectName)
          resolves a field name to a user friendly display name
 void setRulesContextId(String rulesContextId)
          Set the rules context id.
 ValidationResults validate(Object object)
          Validates the provided object.
 ValidationResults validate(Object object, String propertyName)
          Validates the given property of the provided object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RulesValidator

public RulesValidator(FormModel formModel)
Creates a RulesValidator for the given formModel. When no RulesSource is given, a default/global RulesSource is retrieved by the ApplicationServices class.

See Also:
org.springframework.richclient.application.ApplicationServices#getRulesSource()

RulesValidator

public RulesValidator(FormModel formModel,
                      RulesSource rulesSource)
Create a RulesValidator which uses the supplied RulesSource on the FormModel.

Method Detail

validate

public ValidationResults validate(Object object)
Validates the provided object.

Specified by:
validate in interface Validator
Parameters:
object - the object to validate
Returns:
the results on the validation

validate

public ValidationResults validate(Object object,
                                  String propertyName)
Validates the given property of the provided object.

Specified by:
validate in interface RichValidator
Parameters:
object - the object to validate (may be an implementation of
propertyName - the name of the only property that has changed since the last call to validate.
Returns:
the results on the validation

constraintSatisfied

protected void constraintSatisfied(PropertyConstraint exp)

constraintViolated

protected void constraintViolated(PropertyConstraint exp,
                                  PropertyResults propertyResults)

getRulesContextId

public String getRulesContextId()
Returns the rules context id set on this validator.


setRulesContextId

public void setRulesContextId(String rulesContextId)
Set the rules context id. This is passed in the call to RulesSource.getRules(Class, String) to allow for context specific rules.

Parameters:
rulesContextId -

resolveObjectName

public String resolveObjectName(String objectName)
resolves a field name to a user friendly display name

Specified by:
resolveObjectName in interface ObjectNameResolver

clearMessages

public void clearMessages()
Clear the current validationMessages and the errors.

See Also:
validate(Object, String)


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