001    /*******************************************************************************
002     * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
003     * Thomschke.
004     * 
005     * All Rights Reserved. This program and the accompanying materials
006     * are made available under the terms of the Eclipse Public License v1.0
007     * which accompanies this distribution, and is available at
008     * http://www.eclipse.org/legal/epl-v10.html
009     * 
010     * Contributors:
011     *     Sebastian Thomschke - initial implementation.
012     *******************************************************************************/
013    package net.sf.oval.constraint;
014    
015    import java.lang.annotation.Documented;
016    import java.lang.annotation.ElementType;
017    import java.lang.annotation.Retention;
018    import java.lang.annotation.RetentionPolicy;
019    import java.lang.annotation.Target;
020    
021    import net.sf.oval.configuration.annotation.Constraint;
022    import net.sf.oval.configuration.annotation.Constraints;
023    
024    /**
025     * Check if the value satisfies the constraints defined for the specified field.
026     * 
027     * @author Sebastian Thomschke
028     */
029    @Documented
030    @Retention(RetentionPolicy.RUNTIME)
031    @Target({ElementType.PARAMETER, ElementType.METHOD})
032    @Constraint(checkWith = AssertFieldConstraintsCheck.class)
033    public @interface AssertFieldConstraints
034    {
035            @Documented
036            @Retention(RetentionPolicy.RUNTIME)
037            @Target({ElementType.PARAMETER, ElementType.METHOD})
038            @Constraints
039            public @interface List
040            {
041                    /**
042                     * The AssertFieldConstraints constraints.
043                     */
044                    AssertFieldConstraints[] value();
045    
046                    /**
047                     * Formula returning <code>true</code> if this constraint shall be evaluated and
048                     * <code>false</code> if it shall be ignored for the current validation.
049                     * <p>
050                     * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
051                     * E.g. <code>groovy:_this.amount > 10</code>
052                     * <p>
053                     * Available context variables are:<br>
054                     * <b>_this</b> -&gt; the validated bean<br>
055                     * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
056                     *    or the validated bean for object level constraints)
057                     */
058                    String when() default "";
059            }
060    
061            /**
062             * The class in which the field is declared. If omitted the current class and it's super 
063             * classes are searched for a field with the given name.
064             * The default value Void.class means the current class.
065             */
066            Class< ? > declaringClass() default Void.class;
067    
068            /**
069             * The associated constraint profiles.
070             */
071            String[] profiles() default {};
072    
073            /**
074             * Name of the field. If not specified, the constraints of the field with the same name as
075             * the annotated constructor/method parameter are applied.
076             */
077            String value() default "";
078    
079            /**
080             * Formula returning <code>true</code> if this constraint shall be evaluated and
081             * <code>false</code> if it shall be ignored for the current validation.
082             * <p>
083             * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used.
084             * E.g. <code>groovy:_this.amount > 10</code>
085             * <p>
086             * Available context variables are:<br>
087             * <b>_this</b> -&gt; the validated bean<br>
088             * <b>_value</b> -&gt; the value to validate (e.g. the field value, parameter value, method return value,
089             *    or the validated bean for object level constraints)
090             */
091            String when() default "";
092    }