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.ConstraintTarget; 022 import net.sf.oval.configuration.annotation.Constraint; 023 import net.sf.oval.configuration.annotation.Constraints; 024 025 /** 026 * Check if the value satisfies the all constraints of specified constraint set. 027 * 028 * @author Sebastian Thomschke 029 */ 030 @Documented 031 @Retention(RetentionPolicy.RUNTIME) 032 @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) 033 @Constraint(checkWith = AssertConstraintSetCheck.class) 034 public @interface AssertConstraintSet 035 { 036 @Documented 037 @Retention(RetentionPolicy.RUNTIME) 038 @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) 039 @Constraints 040 public @interface List 041 { 042 /** 043 * The AssertConstraintSet constraints. 044 */ 045 AssertConstraintSet[] value(); 046 047 /** 048 * Formula returning <code>true</code> if this constraint shall be evaluated and 049 * <code>false</code> if it shall be ignored for the current validation. 050 * <p> 051 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used. 052 * E.g. <code>groovy:_this.amount > 10</code> 053 * <p> 054 * Available context variables are:<br> 055 * <b>_this</b> -> the validated bean<br> 056 * <b>_value</b> -> the value to validate (e.g. the field value, parameter value, method return value, 057 * or the validated bean for object level constraints) 058 */ 059 String when() default ""; 060 } 061 062 /** 063 * <p>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. 064 * 065 * <p><b>Default:</b> ConstraintTarget.CONTAINER 066 * 067 * <p><b>Note:</b> This setting is ignored for object types other than array, map and collection. 068 */ 069 ConstraintTarget[] appliesTo() default ConstraintTarget.CONTAINER; 070 071 /** 072 * The id of the constraint set to apply here<br> 073 */ 074 String id(); 075 076 /** 077 * The associated constraint profiles. 078 */ 079 String[] profiles() default {}; 080 081 /** 082 * Formula returning <code>true</code> if this constraint shall be evaluated and 083 * <code>false</code> if it shall be ignored for the current validation. 084 * <p> 085 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used. 086 * E.g. <code>groovy:_this.amount > 10</code> 087 * <p> 088 * Available context variables are:<br> 089 * <b>_this</b> -> the validated bean<br> 090 * <b>_value</b> -> the value to validate (e.g. the field value, parameter value, method return value, 091 * or the validated bean for object level constraints) 092 */ 093 String when() default ""; 094 }