KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > latka > ValidationException


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.latka;
18
19 /**
20  * This exception is thrown by <em>validators</em> when a validation has failed
21  *
22  * @author Doug Sale
23  * @author dIon Gillard (mainly javadoc)
24  * @version $Revision$
25  */

26 public class ValidationException extends Exception JavaDoc {
27     
28     /**
29      * Create a validation exception with a null label and reason
30      */

31     public ValidationException() {
32         this(null, null);
33     }
34
35     /**
36      * Create a validation exception with the given
37      * label and reason
38      * @param label the user's description of the assertion/test
39      * @param reason the reason it failed
40      */

41     public ValidationException(String JavaDoc label, String JavaDoc reason) {
42         _label = label;
43         _reason = reason;
44     }
45
46     /** User's description of the test/assertion */
47     private String JavaDoc _label = null;
48
49     /** Why the test/assertion failed */
50     private String JavaDoc _reason = null;
51
52     /**
53      * the message of the exception
54      * @return the message of the exception, built from
55      * the label and reason
56      */

57     public String JavaDoc getMessage() {
58         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
59         if (null != getLabel()) {
60             buf.append(getLabel());
61             if (null != getReason()) {
62                 buf.append(": ");
63             }
64         }
65         if (null != getReason()) {
66             buf.append(getReason());
67         }
68         return buf.toString();
69     }
70
71     /**
72      * User's description of the test/assertion
73      * @return User's description of the test/assertion
74      */

75     public String JavaDoc getLabel() {
76         return _label;
77     }
78
79     /**
80      * Why the test/assertion failed
81      * @return Why the test/assertion failed
82      */

83     public String JavaDoc getReason() {
84         return _reason;
85     }
86 }
87
Popular Tags