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; 014 015 import java.io.Serializable; 016 017 import net.sf.oval.context.OValContext; 018 import net.sf.oval.exception.OValException; 019 020 /** 021 * interface for classes that can exclude the checking of constraints 022 * 023 * @author Sebastian Thomschke 024 */ 025 public interface CheckExclusion extends Serializable 026 { 027 /** 028 * @return the profiles, may return null 029 */ 030 String[] getProfiles(); 031 032 /** 033 * Formula returning <code>true</code> if this constraint shall be evaluated and 034 * <code>false</code> if it shall be ignored for the current validation. 035 * <p> 036 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used. 037 * E.g. <code>groovy:_this.amount > 10</code> 038 * <p> 039 * Available context variables are:<br> 040 * <b>_this</b> -> the validated bean<br> 041 * <b>_value</b> -> the value to validate (e.g. the field value, parameter value, method return value, 042 * or the validated bean for object level constraints) 043 * 044 * @return the formula 045 */ 046 String getWhen(); 047 048 /** 049 * @param validatedObject the object/bean to validate the value against, for static fields or methods this is the class 050 * @param valueToValidate the value to validate, may be null when validating pre conditions for static methods 051 * @param validator the calling validator 052 * @return <code>true</code> if this check exclusion is active and must be satisfied 053 */ 054 boolean isActive(final Object validatedObject, final Object valueToValidate, final Validator validator); 055 056 /** 057 * This method implements the validation logic 058 * 059 * @param check a check that OVal is about to validate 060 * @param validatedObject the object/bean to validate the value against, for static fields or methods this is 061 * the class 062 * @param valueToValidate the value to validate, may be null when validating pre conditions for static methods 063 * @param context the validation context (e.g. a field, a constructor parameter or a method parameter) 064 * @param validator the calling validator 065 * @return true if the value satisfies the checked constraint 066 */ 067 boolean isCheckExcluded(Check check, Object validatedObject, Object valueToValidate, OValContext context, 068 Validator validator) throws OValException; 069 070 /** 071 * @param profiles the profiles to set 072 */ 073 void setProfiles(String... profiles); 074 075 /** 076 * Sets the formula returning <code>true</code> if this constraint shall be evaluated and 077 * <code>false</code> if it shall be ignored for the current validation. 078 * <p> 079 * <b>Important:</b> The formula must be prefixed with the name of the scripting language that is used. 080 * E.g. <code>groovy:_this.amount > 10</code> 081 * <p> 082 * Available context variables are:<br> 083 * <b>_this</b> -> the validated bean<br> 084 * <b>_value</b> -> the value to validate (e.g. the field value, parameter value, method return value, 085 * or the validated bean for object level constraints) 086 * 087 * @param when formula calculating if this check is active 088 */ 089 void setWhen(final String when); 090 }