001: /*******************************************************************************
002: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 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: *******************************************************************************/package net.sf.oval;
013:
014: import java.io.Serializable;
015: import java.util.Map;
016:
017: import net.sf.oval.context.OValContext;
018: import net.sf.oval.exception.OValException;
019:
020: /**
021: * interface for classes that can check/validate if a constraint is satisfied
022: *
023: * @author Sebastian Thomschke
024: */
025: public interface Check extends Serializable {
026: /**
027: * @return the error code that will be used in a corresponding ConstraintViolation object
028: */
029: String getErrorCode();
030:
031: /**
032: * gets the default message that is displayed if a corresponding message key
033: * is not found in the messages properties file
034: * <br>
035: * default processed place holders are:
036: * <ul>
037: * <li>{context} => specifies which getter, method parameter or field was validated
038: * <li>{invalidValue} => string representation of the validated value
039: * </ul>
040: */
041: String getMessage();
042:
043: /**
044: * values that are used to fill place holders when rendering the error message.
045: * A key "min" with a value "4" will replace the place holder {min} in an error message
046: * like "Value cannot be smaller than {min}" with the string "4".
047: */
048: Map<String, String> getMessageVariables();
049:
050: /**
051: * @return the profiles, may return null
052: */
053: String[] getProfiles();
054:
055: /**
056: * @return the severity
057: */
058: int getSeverity();
059:
060: /**
061: * This method implements the validation logic
062: *
063: * @param validatedObject the object/bean to validate the value against, for static fields or methods this is the class
064: * @param valueToValidate the value to validate, may be null when validating pre conditions for static methods
065: * @param context the validation context (e.g. a field, a constructor parameter or a method parameter)
066: * @param validator the calling validator
067: * @return true if the value satisfies the checked constraint
068: */
069: boolean isSatisfied(Object validatedObject, Object valueToValidate,
070: OValContext context, Validator validator)
071: throws OValException;
072:
073: /**
074: * @param errorCode the error code to set
075: */
076: void setErrorCode(String errorCode);
077:
078: /**
079: * sets the default message that is displayed if a corresponding message key
080: * is not found in the messages properties file
081: *
082: * <br>
083: * default processed place holders are:
084: * <ul>
085: * <li>{context} => specifies which getter, method parameter or field was validated
086: * <li>{invalidValue} => string representation of the validated value
087: * </ul>
088: */
089: void setMessage(String message);
090:
091: /**
092: * @param profiles the profiles to set
093: */
094: void setProfiles(String... profiles);
095:
096: /**
097: * @param severity the severity to set
098: */
099: void setSeverity(int severity);
100: }
|