org.springjutsu.validation.rules
Class ValidationRule

java.lang.Object
  extended by org.springjutsu.validation.rules.ValidationRule

public class ValidationRule
extends Object

Java representation of an XML validation rule.

Author:
Clark Duplichien, Taylor Wicksell

Field Summary
protected  CollectionStrategy collectionStrategy
          Indicates whether the rule should be applied to individual collection members, or to the collection object itself.
protected  String errorPath
          The path on which the error should be written on the @link{Errors} object.
protected  List<String> formConstraints
          A list of form mappings, if provided, the rule will only execute when the specified form(s) is/are loaded.
protected  String message
          An optional message code which may be used to resolve a non-default error message (a message other than that which is coded for the rule executor).
protected  String path
          Path to the field to validate.
protected  List<ValidationRule> rules
          These are any validation rules that were nested within the current rule in XML.
protected  List<ValidationTemplateReference> templateReferences
          These are any validation template references that were nested within the current rule in XML.
protected  String type
          Name of the rule executor, implies the type of rule to apply.
protected  String value
          This is the argument to be passed to the rule executor.
 
Constructor Summary
ValidationRule(String path, String type, String value)
          Default constructor, utilized by @link{ValidationDefinitionParser}
 
Method Summary
 void addFormConstraint(String form)
           
 void addRule(ValidationRule rule)
          Adds a rule to the nested validation rules.
 void addTemplateReference(ValidationTemplateReference templateReference)
          Adds a template ref to the nested validation template references.
 boolean appliesToForm(String form)
          Returns true if the rule applies to the current form.
 void applyBasePathReplacement(String oldBasePath, String newBasePath)
          Replaces a base path within this and any sub rules.
 ValidationRule clone()
          Straight up clone.
 ValidationRule cloneWithBasePath(String basePath)
          Clones this validation rule but with a different base path Used within validation logic of @link{ValidationManager} The base path is also applied to all sub rules recursively.
 ValidationRule cloneWithPath(String path)
          Clones this validation rule but with a different path Used within validation logic of @link{ValidationManager}
 CollectionStrategy getCollectionStrategy()
           
 String getErrorPath()
           
 List<String> getFormConstraints()
           
 String getMessage()
           
 String getPath()
           
 List<ValidationRule> getRules()
           
 List<ValidationTemplateReference> getTemplateReferences()
           
 String getType()
           
 String getValue()
           
 boolean hasChildren()
           
 void setCollectionStrategy(CollectionStrategy collectionStrategy)
           
 void setErrorPath(String errorPath)
           
 void setFormConstraints(List<String> formConstraints)
           
 void setMessage(String message)
           
 void setPath(String path)
           
 void setRules(List<ValidationRule> rules)
           
 void setTemplateReferences(List<ValidationTemplateReference> templateReferences)
           
 void setType(String type)
           
 void setValue(String value)
           
 String toString()
          The toString() representation is a reconstruction of the XML syntax of the validation rule, minus any nested validation rules.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

path

protected String path
Path to the field to validate.


type

protected String type
Name of the rule executor, implies the type of rule to apply.


value

protected String value
This is the argument to be passed to the rule executor.


message

protected String message
An optional message code which may be used to resolve a non-default error message (a message other than that which is coded for the rule executor).


errorPath

protected String errorPath
The path on which the error should be written on the @link{Errors} object. In case you want to validate one field, but put the error message onto another field.


collectionStrategy

protected CollectionStrategy collectionStrategy
Indicates whether the rule should be applied to individual collection members, or to the collection object itself.


formConstraints

protected List<String> formConstraints
A list of form mappings, if provided, the rule will only execute when the specified form(s) is/are loaded.


rules

protected List<ValidationRule> rules
These are any validation rules that were nested within the current rule in XML. If nested rules exist and this rule passed, the nested rules would be run. If nested rules exist, an error is not recorded when this rule fails.


templateReferences

protected List<ValidationTemplateReference> templateReferences
These are any validation template references that were nested within the current rule in XML. If nested templates exist and this rule passed, the nested templates would be run. If nested templates exist, an error is not recorded when this rule fails.

Constructor Detail

ValidationRule

public ValidationRule(String path,
                      String type,
                      String value)
Default constructor, utilized by @link{ValidationDefinitionParser}

Parameters:
path - See path docs.
type - See type docs.
value - See value docs.
Method Detail

clone

public ValidationRule clone()
Straight up clone.

Overrides:
clone in class Object
Returns:
cloned rule

cloneWithPath

public ValidationRule cloneWithPath(String path)
Clones this validation rule but with a different path Used within validation logic of @link{ValidationManager}

Parameters:
path - The new path to apply to the cloned rule
Returns:
A cloned rule with the new path.

cloneWithBasePath

public ValidationRule cloneWithBasePath(String basePath)
Clones this validation rule but with a different base path Used within validation logic of @link{ValidationManager} The base path is also applied to all sub rules recursively.

Parameters:
path - The new path to apply to the cloned rule
Returns:
A cloned rule with the new path.

applyBasePathReplacement

public void applyBasePathReplacement(String oldBasePath,
                                     String newBasePath)
Replaces a base path within this and any sub rules.

Parameters:
oldBasePath - the old base path to replace
newBasePath - the new base path to apply

hasChildren

public boolean hasChildren()
Returns:
true if there are nested validation rules.

toString

public String toString()
The toString() representation is a reconstruction of the XML syntax of the validation rule, minus any nested validation rules.

Overrides:
toString in class Object

appliesToForm

public boolean appliesToForm(String form)
Returns true if the rule applies to the current form. Replace any REST variable wildcards with wildcard regex. Replace ant path wildcards with wildcard regexes as well. Iterate through possible form names to find the first match.


addFormConstraint

public void addFormConstraint(String form)

addRule

public void addRule(ValidationRule rule)
Adds a rule to the nested validation rules.

Parameters:
rule - The rule to add.

addTemplateReference

public void addTemplateReference(ValidationTemplateReference templateReference)
Adds a template ref to the nested validation template references.

Parameters:
templateReference - The template reference to add.

getPath

public String getPath()
Returns:
the path

setPath

public void setPath(String path)
Parameters:
path - the path to set

getType

public String getType()
Returns:
the type.

setType

public void setType(String type)
Parameters:
type - the type to set.

getValue

public String getValue()
Returns:
the value / argument

setValue

public void setValue(String value)
Parameters:
value - the value / argument to set

getRules

public List<ValidationRule> getRules()
Returns:
the rules

setRules

public void setRules(List<ValidationRule> rules)
Parameters:
rules - the rules to set

getMessage

public String getMessage()
Returns:
the message

setMessage

public void setMessage(String message)
Parameters:
message - the message to set

getErrorPath

public String getErrorPath()
Returns:
the errorPath

setErrorPath

public void setErrorPath(String errorPath)
Parameters:
errorPath - the errorPath to set

getCollectionStrategy

public CollectionStrategy getCollectionStrategy()

setCollectionStrategy

public void setCollectionStrategy(CollectionStrategy collectionStrategy)

getFormConstraints

public List<String> getFormConstraints()

setFormConstraints

public void setFormConstraints(List<String> formConstraints)

getTemplateReferences

public List<ValidationTemplateReference> getTemplateReferences()
Returns:
the templateReferences

setTemplateReferences

public void setTemplateReferences(List<ValidationTemplateReference> templateReferences)
Parameters:
templateReferences - the templateReferences to set


Copyright © 2013 Spring Jutsu. All Rights Reserved.