net.sf.oval
Interface Check

All Superinterfaces:
Serializable
All Known Subinterfaces:
AnnotationCheck<ConstraintAnnotation>
All Known Implementing Classes:
AbstractAnnotationCheck, AbstractCheck, AssertCheck, AssertConstraintSetCheck, AssertFalseCheck, AssertFieldConstraintsCheck, AssertNullCheck, AssertTrueCheck, AssertURLCheck, AssertValidCheck, CheckWithCheck, ConstraintsCheck, DateRangeCheck, DigitsCheck, EmailCheck, EqualToFieldCheck, FutureCheck, HasSubstringCheck, InstanceOfAnyCheck, InstanceOfCheck, LengthCheck, MatchPatternCheck, MaxCheck, MaxLengthCheck, MaxSizeCheck, MemberOfCheck, MinCheck, MinLengthCheck, MinSizeCheck, NoSelfReferenceCheck, NotBlankCheck, NotEmptyCheck, NotEqualCheck, NotEqualToFieldCheck, NotMatchPatternCheck, NotMemberOfCheck, NotNegativeCheck, NotNullCheck, PastCheck, PostCheck, PreCheck, RangeCheck, SizeCheck, ValidateWithMethodCheck

public interface Check
extends Serializable

interface for classes that can check/validate if a constraint is satisfied

Author:
Sebastian Thomschke

Method Summary
 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.
 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)
           
 boolean isSatisfied(Object validatedObject, Object valueToValidate, OValContext context, Validator validator)
          This method implements the validation logic
 void setAppliesTo(ConstraintTarget... target)
           
 void setContext(OValContext context)
           
 void setErrorCode(String errorCode)
           
 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.
 

Method Detail

getAppliesTo

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.


getContext

OValContext getContext()
Returns:
Returns the context where the constraint was declared.
See Also:
ClassContext, FieldContext, MethodEntryContext, MethodExitContext, MethodParameterContext, MethodReturnValueContext

getErrorCode

String getErrorCode()
Returns:
the error code that will be used in a corresponding ConstraintViolation object

getMessage

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:


getMessageVariables

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".


getProfiles

String[] getProfiles()
Returns:
the profiles, may return null

getSeverity

int getSeverity()
Returns:
the severity

getTarget

String getTarget()
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.


  • getWhen

    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)

    Returns:
    the formula

    isActive

    boolean isActive(Object validatedObject,
                     Object valueToValidate,
                     Validator validator)
    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

    isSatisfied

    boolean isSatisfied(Object validatedObject,
                        Object valueToValidate,
                        OValContext context,
                        Validator validator)
                        throws OValException
    This method implements the validation logic

    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
    context - the validation context (e.g. a field, a constructor parameter or a method parameter)
    validator - the calling validator
    Returns:
    true if the value satisfies the checked constraint
    Throws:
    OValException

    setAppliesTo

    void setAppliesTo(ConstraintTarget... target)
    Parameters:
    target - the constraint target to set

    setContext

    void setContext(OValContext context)
    Parameters:
    context - the context to set

    setErrorCode

    void setErrorCode(String errorCode)
    Parameters:
    errorCode - the error code to set

    setMessage

    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:


    setProfiles

    void setProfiles(String... profiles)
    Parameters:
    profiles - the profiles to set

    setSeverity

    void setSeverity(int severity)
    Parameters:
    severity - the severity to set

    setTarget

    void setTarget(String target)
    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.


  • setWhen

    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)

    Parameters:
    when - formula calculating if this check is active


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