KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > ejb > ejbqlc > ErrorMsg


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
26 /*
27  * ErrorMsg.java
28  *
29  * Created on November 12, 2001
30  */

31
32 package com.sun.jdo.spi.persistence.support.ejb.ejbqlc;
33
34 import java.util.ResourceBundle JavaDoc;
35 import com.sun.jdo.spi.persistence.utility.I18NHelper;
36 import com.sun.jdo.spi.persistence.utility.logging.Logger;
37
38 /**
39  * This is a helper class to report error messages from the EJBQL compiler.
40  * @author Michael Bouschen
41  * @author Shing Wai Chan
42  */

43 public class ErrorMsg
44 {
45     /** I18N support. */
46     private final static ResourceBundle JavaDoc msgs = I18NHelper.loadBundle(
47         ErrorMsg.class);
48     
49     /** The logger */
50     private static Logger logger = LogHelperQueryCompilerEJB.getLogger();
51     
52     /**
53      * This method throws an EJBQLException indicating an user error.
54      * @param line line number
55      * @param col column number
56      * @param text error message
57      * @exception EJBQLException describes the user error.
58      */

59     public static void error(int line, int col, String JavaDoc text)
60         throws EJBQLException
61     {
62         EJBQLException ex = null;
63         if (line > 1) {
64             // include line and column info
65
Object JavaDoc args[] = {new Integer JavaDoc(line), new Integer JavaDoc(col), text};
66             ex = new EJBQLException(I18NHelper.getMessage(
67                 msgs, "EXC_PositionInfoMsgLineColumn", args)); //NOI18N
68
}
69         else if (col > 0) {
70             // include column info
71
Object JavaDoc args[] = {new Integer JavaDoc(col), text};
72             ex = new EJBQLException(I18NHelper.getMessage(
73                 msgs, "EXC_PositionInfoMsgColumn", args)); //NOI18N
74
}
75         else {
76             ex = new EJBQLException(I18NHelper.getMessage(
77                 msgs, "EXC_PositionInfoMsg", text)); //NOI18N
78
}
79         throw ex;
80     }
81     
82     /**
83      * This method throws an EJBQLException indicating an user error.
84      * @param text error message
85      * @param cause the cause of the error
86      * @exception EJBQLException describes the user error.
87      */

88     public static void error(String JavaDoc text, Throwable JavaDoc cause)
89         throws EJBQLException
90     {
91         throw new EJBQLException(text, cause);
92     }
93     
94     /**
95      * This method throws an EJBQLException indicating an user error.
96      * @param text error message
97      * @exception EJBQLException describes the user error.
98      */

99     public static void error(String JavaDoc text)
100         throws EJBQLException
101     {
102         throw new EJBQLException(text);
103     }
104     
105     /**
106      * This method throws an UnsupportedOperationException indicating an
107      * unsupported feature.
108      * @param line line number
109      * @param col column number
110      * @param text message
111      * @exception UnsupportedOperationException describes the unsupported
112      * feature.
113      */

114     public static void unsupported(int line, int col, String JavaDoc text)
115         throws UnsupportedOperationException JavaDoc
116     {
117         UnsupportedOperationException JavaDoc ex;
118         if (line > 1)
119         {
120             // include line and column info
121
Object JavaDoc args[] = {new Integer JavaDoc(line), new Integer JavaDoc(col), text};
122             ex = new UnsupportedOperationException JavaDoc(I18NHelper.getMessage(
123                 msgs, "EXC_PositionInfoMsgLineColumn", args)); //NOI18N
124
}
125         else if (col > 0) {
126             // include column info
127
Object JavaDoc args[] = {new Integer JavaDoc(col), text};
128             ex = new UnsupportedOperationException JavaDoc(I18NHelper.getMessage(
129                 msgs, "EXC_PositionInfoMsgColumn", args)); //NOI18N
130
}
131         else {
132             Object JavaDoc args[] = {text};
133             ex = new UnsupportedOperationException JavaDoc(I18NHelper.getMessage(
134                 msgs, "EXC_PositionInfoMsg", args)); //NOI18N
135
}
136         throw ex;
137     }
138     
139     /**
140      * This method is called in the case of an fatal internal error.
141      * @param text error message
142      * @exception EJBQLException describes the fatal internal error.
143      */

144     public static void fatal(String JavaDoc text)
145         throws EJBQLException
146     {
147         throw new EJBQLException(I18NHelper.getMessage(
148             msgs, "ERR_FatalInternalError", text)); //NOI18N
149
}
150
151     /**
152      * This method is called in the case of an fatal internal error.
153      * @param text error message
154      * @param nested the cause of the error
155      * @exception EJBQLException describes the fatal internal error.
156      */

157     public static void fatal(String JavaDoc text, Throwable JavaDoc nested)
158         throws EJBQLException
159     {
160         throw new EJBQLException(I18NHelper.getMessage(
161             msgs, "ERR_FatalInternalError", text), nested); //NOI18N
162
}
163
164     /**
165      * This method is called when we want to log an exception in a given level.
166      * Note that all other methods in this class do not log a stack trace.
167      * @param level log level
168      * @param text error message
169      * @param nested the cause of the error
170      * @exception EJBQLException describes the fatal internal error.
171      */

172     public static void log(int level, String JavaDoc text, Throwable JavaDoc nested)
173         throws EJBQLException
174     {
175         logger.log(level, text, nested);
176         throw new EJBQLException(text, nested);
177     }
178 }
179
Popular Tags