net.sf.oval
Class AbstractCheck

java.lang.Object
  extended by net.sf.oval.AbstractCheck
All Implemented Interfaces:
Serializable, Check
Direct Known Subclasses:
AbstractAnnotationCheck, PostCheck, PreCheck

public abstract class AbstractCheck
extends Object
implements Check

Partial implementation of check classes.

Author:
Sebastian Thomschke
See Also:
Serialized Form

Constructor Summary
AbstractCheck()
           
 
Method Summary
protected  Map<String,? extends Serializable> createMessageVariables()
           
 ConstraintTarget[] getAppliesTo()
          

In case the constraint is declared for an array, collection or map this controls how the constraint is applied to it and it's child objects.

protected  ConstraintTarget[] getAppliesToDefault()
           
 OValContext getContext()
          
 String getErrorCode()
          
 String getMessage()
          gets the default message that is displayed if a corresponding message key is not found in the messages properties file
default processed place holders are:
  • {context} => specifies which getter, method parameter or field was validated
  • {invalidValue} => string representation of the validated value
 Map<String,? extends Serializable> getMessageVariables()
          Values that are used to fill place holders when rendering the error message.
 String[] getProfiles()
          
 int getSeverity()
          
 String getTarget()
          An expression to specify where in the object graph relative from this object the expression should be applied.
 String getWhen()
          Formula returning true if this constraint shall be evaluated and false if it shall be ignored for the current validation.
 boolean isActive(Object validatedObject, Object valueToValidate, Validator validator)
          
protected  void requireMessageVariablesRecreation()
          Calling this method indicates that the createMessageVariables() method needs to be called before the message for the next violation of this check is rendered.
 void setAppliesTo(ConstraintTarget... targets)
          
 void setContext(OValContext context)
          
 void setErrorCode(String failureCode)
          
 void setMessage(String message)
          sets the default message that is displayed if a corresponding message key is not found in the messages properties file
default processed place holders are:
  • {context} => specifies which getter, method parameter or field was validated
  • {invalidValue} => string representation of the validated value
 void setProfiles(String... profiles)
          
 void setSeverity(int severity)
          
 void setTarget(String target)
          Sets an expression to specify where in the object graph relative from this object the expression should be applied.
 void setWhen(String when)
          Sets the formula returning true if this constraint shall be evaluated and false if it shall be ignored for the current validation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.oval.Check
isSatisfied
 

Constructor Detail

AbstractCheck

public AbstractCheck()
Method Detail

createMessageVariables

protected Map<String,? extends Serializable> createMessageVariables()

getAppliesTo

public ConstraintTarget[] getAppliesTo()

In case the constraint is declared for an array, collection or map this controls how the constraint is applied to it and it's child objects.

Default: ConstraintTarget.CONTAINER

Note: This setting is ignored for object types other than array, map and collection.

Specified by:
getAppliesTo in interface Check

getAppliesToDefault

protected ConstraintTarget[] getAppliesToDefault()
Returns:
the default behavior when the constraint is validated for a array/map/collection reference.

getContext

public OValContext getContext()

Specified by:
getContext in interface Check
Returns:
Returns the context where the constraint was declared.
See Also:
ClassContext, FieldContext, MethodEntryContext, MethodExitContext, MethodParameterContext, MethodReturnValueContext

getErrorCode

public String getErrorCode()

Specified by:
getErrorCode in interface Check
Returns:
the error code that will be used in a corresponding ConstraintViolation object

getMessage

public String getMessage()
gets the default message that is displayed if a corresponding message key is not found in the messages properties file
default processed place holders are:

Specified by:
getMessage in interface Check

getMessageVariables

public final Map<String,? extends Serializable> getMessageVariables()
Values that are used to fill place holders when rendering the error message. A key "min" with a value "4" will replace the place holder {min} in an error message like "Value cannot be smaller than {min}" with the string "4". Note: Override createMessageVariables() to create and fill the map

Specified by:
getMessageVariables in interface Check
Returns:
an unmodifiable map

getProfiles

public String[] getProfiles()

Specified by:
getProfiles in interface Check
Returns:
the profiles, may return null

getSeverity

public int getSeverity()

Specified by:
getSeverity in interface Check
Returns:
the severity

getTarget

public String getTarget()
Description copied from interface: Check
An expression to specify where in the object graph relative from this object the expression should be applied.

Examples:

  • "owner" would apply this constraint to the current object's property owner
  • "owner.id" would apply this constraint to the current object's owner's property id
  • "jxpath:owner/id" would use the JXPath implementation to traverse the object graph to locate the object where this constraint should be applied.

    Specified by:
    getTarget in interface Check
    Returns:
    the target

  • getWhen

    public String getWhen()
    Formula returning true if this constraint shall be evaluated and false if it shall be ignored for the current validation.

    Important: The formula must be prefixed with the name of the scripting language that is used. E.g. groovy:_this.amount > 10

    Available context variables are:
    _this -> the validated bean
    _value -> the value to validate (e.g. the field value, parameter value, method return value, or the validated bean for object level constraints)

    Specified by:
    getWhen in interface Check
    Returns:
    the formula

    isActive

    public boolean isActive(Object validatedObject,
                            Object valueToValidate,
                            Validator validator)

    Specified by:
    isActive in interface Check
    Parameters:
    validatedObject - the object/bean to validate the value against, for static fields or methods this is the class
    valueToValidate - the value to validate, may be null when validating pre conditions for static methods
    validator - the calling validator
    Returns:
    true if this check is active and must be satisfied

    requireMessageVariablesRecreation

    protected void requireMessageVariablesRecreation()
    Calling this method indicates that the createMessageVariables() method needs to be called before the message for the next violation of this check is rendered.


    setAppliesTo

    public void setAppliesTo(ConstraintTarget... targets)

    Specified by:
    setAppliesTo in interface Check
    Parameters:
    targets - the constraint target to set

    setContext

    public void setContext(OValContext context)

    Specified by:
    setContext in interface Check
    Parameters:
    context - the context to set

    setErrorCode

    public void setErrorCode(String failureCode)

    Specified by:
    setErrorCode in interface Check
    Parameters:
    failureCode - the error code to set

    setMessage

    public void setMessage(String message)
    sets the default message that is displayed if a corresponding message key is not found in the messages properties file
    default processed place holders are:

    Specified by:
    setMessage in interface Check

    setProfiles

    public void setProfiles(String... profiles)

    Specified by:
    setProfiles in interface Check
    Parameters:
    profiles - the profiles to set

    setSeverity

    public void setSeverity(int severity)

    Specified by:
    setSeverity in interface Check
    Parameters:
    severity - the severity to set

    setTarget

    public void setTarget(String target)
    Description copied from interface: Check
    Sets an expression to specify where in the object graph relative from this object the expression should be applied.

    Examples:

  • "owner" would apply this constraint to the current object's property owner
  • "owner.id" would apply this constraint to the current object's owner's property id
  • "jxpath:owner/id" would use the JXPath implementation to traverse the object graph to locate the object where this constraint should be applied.

    Specified by:
    setTarget in interface Check
    Parameters:
    target - the target to set

  • setWhen

    public void setWhen(String when)
    Sets the formula returning true if this constraint shall be evaluated and false if it shall be ignored for the current validation.

    Important: The formula must be prefixed with the name of the scripting language that is used. E.g. groovy:_this.amount > 10

    Available context variables are:
    _this -> the validated bean
    _value -> the value to validate (e.g. the field value, parameter value, method return value, or the validated bean for object level constraints)

    Specified by:
    setWhen in interface Check
    Parameters:
    when - formula calculating if this check is active


    Copyright © 2005–2015 The OVal Development Team. All rights reserved.