net.sf.oval.constraint
Annotation Type Assert


@Documented
@Retention(value=RUNTIME)
@Target(value={FIELD,PARAMETER,METHOD,TYPE})
@Constraint(checkWith=AssertCheck.class)
public @interface Assert

Check if evaluating the expression in the specified expression language returns true.

Author:
Sebastian Thomschke

Required Element Summary
 String expr
          Formula in the given expression language describing the constraint.
 String lang
          the expression language that is used, e.g.
 
Optional Element Summary
 ConstraintTarget[] appliesTo
          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.
 String errorCode
          failure code passed to the ConstraintViolation object
 String message
          message to be used for constructing the ConstraintViolation object
 String[] profiles
          The associated constraint profiles.
 int severity
          severity passed to the ConstraintViolation object
 String target
          An expression to specify where in the object graph relative from this object the expression should be applied.
 String when
          Formula returning true if this constraint shall be evaluated and false if it shall be ignored for the current validation.
 

Element Detail

expr

public abstract String expr
Formula in the given expression language describing the constraint. The formula must return true if the constraint is satisfied.

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)


lang

public abstract String lang
the expression language that is used, e.g. "bsh" / "beanshell", "groovy", or "js" / "javascript".

appliesTo

public abstract ConstraintTarget[] appliesTo

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.

Default:
CONTAINER

errorCode

public abstract String errorCode
failure code passed to the ConstraintViolation object

Default:
"net.sf.oval.constraint.Assert"

message

public abstract String message
message to be used for constructing the ConstraintViolation object

See Also:
ConstraintViolation
Default:
"net.sf.oval.constraint.Assert.violated"

profiles

public abstract String[] profiles
The associated constraint profiles.

Default:
{}

severity

public abstract int severity
severity passed to the ConstraintViolation object

Default:
0

target

public abstract String target
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.

    Default:
    ""

  • when

    public abstract String when
    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)

    Default:
    ""


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