KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > model > util > ModelValidationException


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ModelValidationException.java
26  *
27  * Created on September 22, 2000, 1:05 PM
28  */

29
30 package com.sun.jdo.api.persistence.model.util;
31
32 import java.util.ResourceBundle JavaDoc;
33
34 import com.sun.jdo.api.persistence.model.ModelException;
35 import com.sun.jdo.spi.persistence.utility.I18NHelper;
36 import com.sun.jdo.spi.persistence.utility.StringHelper;
37
38 /**
39  *
40  * @author raccah
41  * @version %I%
42  */

43 public class ModelValidationException extends ModelException
44 {
45     /** Constant representing an error. */
46     public static final int ERROR = 0;
47
48     /** Constant representing a warning. */
49     public static final int WARNING = 1;
50
51     /** I18N message handler */
52     private static final ResourceBundle JavaDoc _messages = I18NHelper.loadBundle(
53         "com.sun.jdo.api.persistence.model.Bundle", // NOI18N
54
ModelValidationException.class.getClassLoader());
55
56     /** This field holds the type -- one of {@link #ERROR} or {@link #WARNING}
57      */

58     private int _type;
59
60     /** This field holds the offending object -- the one being validated
61      * when the problem occurred
62      */

63     private Object JavaDoc _offendingObject;
64
65     /** @return I18N message handler for this element
66      */

67     protected static final ResourceBundle JavaDoc getMessages ()
68     {
69         return _messages;
70     }
71
72     /**
73      * Creates new <code>ModelValidationException</code> of type {@link #ERROR}
74      * without a detail message and with <code>null</code> as the
75      * offending object.
76      */

77     public ModelValidationException ()
78     {
79     }
80
81     /**
82      * Constructs a <code>ModelValidationException</code> of type
83      * {@link #ERROR} with the specified detail message and
84      * <code>null</code> as the offending object.
85      * @param msg the detail message.
86      */

87     public ModelValidationException (String JavaDoc msg)
88     {
89         super(msg);
90     }
91
92     /**
93      * Constructs a <code>ModelValidationException</code> of type
94      * {@link #ERROR} with the specified offending object and no
95      * detail message.
96      * @param offendingObject the offending object.
97      */

98     public ModelValidationException (Object JavaDoc offendingObject)
99     {
100         super();
101         _offendingObject = offendingObject;
102     }
103
104     /**
105      * Constructs a <code>ModelValidationException</code> of type
106      * {@link #ERROR} with the specified detail message and offending
107      * object.
108      * @param offendingObject the offending object.
109      * @param msg the detail message.
110      */

111     public ModelValidationException (Object JavaDoc offendingObject, String JavaDoc msg)
112     {
113         this(ERROR, offendingObject, msg);
114     }
115
116     /**
117      * Constructs a <code>ModelValidationException</code> of the specified
118      * type with the specified detail message and offending object.
119      * @param errorType the type -- one of {@link #ERROR} or {@link #WARNING}.
120      * @param offendingObject the offending object.
121      * @param msg the detail message.
122      */

123     public ModelValidationException (int errorType, Object JavaDoc offendingObject,
124         String JavaDoc msg)
125     {
126         super(msg);
127         _type = errorType;
128         _offendingObject = offendingObject;
129     }
130
131     /**
132      * Get the offending object -- the one being validated when the problem
133      * occurred.
134      */

135     public Object JavaDoc getOffendingObject () { return _offendingObject; }
136
137     /**
138      * Get the type -- one of {@link #ERROR} or {@link #WARNING}.
139      */

140     public int getType () { return _type; }
141
142     /**
143     * Returns the error message string of this throwable object.
144     * @return the error message string of this
145     * <code>ModelValidationException</code>, prepended with the warning string
146     * if the type is {@link #WARNING}
147     *
148     */

149     public String JavaDoc getMessage ()
150     {
151         String JavaDoc message = super.getMessage();
152
153         if ((WARNING == getType()) && !StringHelper.isEmpty(message))
154         {
155             message = I18NHelper.getMessage(getMessages(),
156                 "util.validation.warning") + message; //NOI18N
157
}
158
159         return message;
160     }
161 }
162
Popular Tags