001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.valid;
016    
017    import org.apache.tapestry.IRender;
018    
019    /**
020     * Thrown by a {@link IValidator}when submitted input is not valid.
021     * 
022     * @author Howard Lewis Ship
023     * @since 1.0.8
024     */
025    
026    public class ValidatorException extends Exception
027    {
028        private static final long serialVersionUID = 2451683137746501377L;
029    
030        private final IRender _errorRenderer;
031    
032        private final ValidationConstraint _constraint;
033    
034        public ValidatorException(String errorMessage)
035        {
036            this(errorMessage, null, null);
037        }
038    
039        public ValidatorException(String errorMessage, ValidationConstraint constraint)
040        {
041            this(errorMessage, null, constraint);
042        }
043    
044        /**
045         * Creates a new instance.
046         * 
047         * @param errorMessage
048         *            the default error message to be used (this may be overriden by the
049         *            {@link IValidationDelegate})
050         * @param errorRenderer
051         *            to use to render the error message (may be null). This is used with custom
052         *            validators that create renderers that produce rich markup (such as icons or links
053         *            to help pages). Such renderes are expected to implement a <code>toString()</code>
054         *            that returns a simple error message (without any markup).
055         * @param constraint
056         *            a validation constraint that has been compromised, or null if no constraint is
057         *            applicable
058         */
059    
060        public ValidatorException(String errorMessage, IRender errorRenderer,
061                ValidationConstraint constraint)
062        {
063            super(errorMessage);
064    
065            _errorRenderer = errorRenderer;
066            _constraint = constraint;
067        }
068    
069        public ValidationConstraint getConstraint()
070        {
071            return _constraint;
072        }
073    
074        /**
075         * Returns the error renderer for this exception, which may be null.
076         * 
077         * @since 3.0 *
078         */
079    
080        public IRender getErrorRenderer()
081        {
082            return _errorRenderer;
083        }
084    }