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