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.guard;
014    
015    import net.sf.oval.AbstractCheck;
016    import net.sf.oval.Validator;
017    import net.sf.oval.context.OValContext;
018    import net.sf.oval.exception.OValException;
019    
020    /**
021     * @author Sebastian Thomschke
022     */
023    public class PreCheck extends AbstractCheck
024    {
025            private static final long serialVersionUID = 1L;
026    
027            private String expression;
028            private String language;
029    
030            public void configure(final Pre constraintAnnotation)
031            {
032                    setMessage(constraintAnnotation.message());
033                    setErrorCode(constraintAnnotation.errorCode());
034                    setSeverity(constraintAnnotation.severity());
035                    setExpression(constraintAnnotation.expr());
036                    setLanguage(constraintAnnotation.lang());
037                    setProfiles(constraintAnnotation.profiles());
038            }
039    
040            /**
041             * @return the condition
042             */
043            public String getExpression()
044            {
045                    return expression;
046            }
047    
048            /**
049             * @return the language
050             */
051            public String getLanguage()
052            {
053                    return language;
054            }
055    
056            /**
057             * {@inheritDoc}
058             */
059            public boolean isSatisfied(final Object validatedObject, final Object valueToValidate, final OValContext context,
060                            final Validator validator) throws OValException
061            {
062                    throw new UnsupportedOperationException();
063            }
064    
065            /**
066             * @param condition the condition to set
067             */
068            public void setExpression(final String condition)
069            {
070                    expression = condition;
071            }
072    
073            /**
074             * @param language the language to set
075             */
076            public void setLanguage(final String language)
077            {
078                    this.language = language;
079            }
080    }