org.makumba.providers.datadefinition.mdd
Class ValidationRuleNode

java.lang.Object
  extended by antlr.BaseAST
      extended by antlr.CommonAST
          extended by org.makumba.providers.datadefinition.mdd.MDDAST
              extended by org.makumba.providers.datadefinition.mdd.ValidationRuleNode
All Implemented Interfaces:
antlr.collections.AST, Serializable, Comparable<ValidationRule>, ValidationRule
Direct Known Subclasses:
ComparisonValidationRule, MultiUniquenessValidationRule, RangeValidationRule, RegExpValidationRule

public class ValidationRuleNode
extends MDDAST
implements ValidationRule, Comparable<ValidationRule>

See Also:
Serialized Form

Field Summary
protected  ArrayList<String> arguments
          arguments of the comparison rule
protected  ComparisonExpressionNode comparisonExpression
          comparison expression
protected  String expression
          regex expression
protected  FieldNode field
          field node the rule applies to. this is only used for single-field validation rules, as convenience mechanism to check the rule applicability.
protected  String lowerBound
          range validation limits
protected  MDDNode mdd
          the parent MDD
protected  String message
          message
protected  String name
          name of the rule
protected  ValidationType type
          type of the rule
protected  String upperBound
           
 
Fields inherited from class org.makumba.providers.datadefinition.mdd.MDDAST
makumbaType, wasIncluded
 
Fields inherited from class antlr.BaseAST
down, right
 
Constructor Summary
ValidationRuleNode(MDDNode mdd, antlr.collections.AST originAST)
           
ValidationRuleNode(MDDNode mdd, antlr.collections.AST originAST, FieldNode field)
           
ValidationRuleNode(MDDNode mdd, antlr.collections.AST originAST, ValidationType type, FieldNode parentField)
           
 
Method Summary
 void checkApplicability()
          Checks if the type of the rule is compatible with the field types it refers to
 int compareTo(ValidationRule o)
          We order the rules such that comparison rules come last.
 ComparisonExpressionNode getComparisonExpression()
           
 DataDefinition getDataDefinition()
          Gets the DataDefinition this rule applies to
 String getErrorMessage()
          Gets the error message that should be shown for this rule.
 String getExpression()
           
 FieldDefinition getFieldDefinition()
          Gets the FieldDefinition this rule applies to.
 String getLowerBound()
           
 String getRuleName()
          Gets the name of this rule.
 String getUpperBound()
           
 Collection<String> getValidationRuleArguments()
          Gets the arguments (field names) this rule applies to
 FieldDefinition getValidationRuleArgumentType(String fieldName)
           
 ValidationType getValidationType()
           
protected  void throwException()
          Throw a default exception.
 String toString()
           
 boolean validate(Object value, Transaction t)
          should be overridden in extended classes
 
Methods inherited from class org.makumba.providers.datadefinition.mdd.MDDAST
getColumn, getLine, initialize, initialize, setCol, setLine
 
Methods inherited from class antlr.CommonAST
getText, getType, initialize, setText, setType
 
Methods inherited from class antlr.BaseAST
addChild, decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getFirstChild, getNextSibling, getNumberOfChildren, getTokenNames, removeChildren, setFirstChild, setNextSibling, setVerboseStringConversion, toStringList, toStringTree, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected String name
name of the rule


type

protected ValidationType type
type of the rule


message

protected String message
message


field

protected transient FieldNode field
field node the rule applies to. this is only used for single-field validation rules, as convenience mechanism to check the rule applicability. TODO maybe drop this in favor of using the arguments


mdd

protected MDDNode mdd
the parent MDD


lowerBound

protected String lowerBound
range validation limits


upperBound

protected String upperBound

arguments

protected ArrayList<String> arguments
arguments of the comparison rule


expression

protected String expression
regex expression


comparisonExpression

protected ComparisonExpressionNode comparisonExpression
comparison expression

Constructor Detail

ValidationRuleNode

public ValidationRuleNode(MDDNode mdd,
                          antlr.collections.AST originAST)

ValidationRuleNode

public ValidationRuleNode(MDDNode mdd,
                          antlr.collections.AST originAST,
                          FieldNode field)

ValidationRuleNode

public ValidationRuleNode(MDDNode mdd,
                          antlr.collections.AST originAST,
                          ValidationType type,
                          FieldNode parentField)
Method Detail

checkApplicability

public void checkApplicability()
Checks if the type of the rule is compatible with the field types it refers to


getRuleName

public String getRuleName()
Description copied from interface: ValidationRule
Gets the name of this rule.

Specified by:
getRuleName in interface ValidationRule

getValidationType

public ValidationType getValidationType()

getErrorMessage

public String getErrorMessage()
Description copied from interface: ValidationRule
Gets the error message that should be shown for this rule.

Specified by:
getErrorMessage in interface ValidationRule

getFieldDefinition

public FieldDefinition getFieldDefinition()
Description copied from interface: ValidationRule
Gets the FieldDefinition this rule applies to.

Specified by:
getFieldDefinition in interface ValidationRule

validate

public boolean validate(Object value,
                        Transaction t)
                 throws InvalidValueException
should be overridden in extended classes

Specified by:
validate in interface ValidationRule
t - TODO
Throws:
InvalidValueException - if the validation fails

compareTo

public int compareTo(ValidationRule o)
We order the rules such that comparison rules come last. This is important for live validation, where first the validity of each field by itself should be checked.

Specified by:
compareTo in interface Comparable<ValidationRule>

throwException

protected void throwException()
                       throws InvalidValueException
Throw a default exception.

Throws:
InvalidValueException

toString

public String toString()
Specified by:
toString in interface antlr.collections.AST
Overrides:
toString in class antlr.BaseAST

getValidationRuleArguments

public Collection<String> getValidationRuleArguments()
Description copied from interface: ValidationRule
Gets the arguments (field names) this rule applies to

Specified by:
getValidationRuleArguments in interface ValidationRule

getValidationRuleArgumentType

public FieldDefinition getValidationRuleArgumentType(String fieldName)

getDataDefinition

public DataDefinition getDataDefinition()
Description copied from interface: ValidationRule
Gets the DataDefinition this rule applies to

Specified by:
getDataDefinition in interface ValidationRule

getLowerBound

public String getLowerBound()

getUpperBound

public String getUpperBound()

getExpression

public String getExpression()

getComparisonExpression

public ComparisonExpressionNode getComparisonExpression()