KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > exceptions > EJBQLException


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.exceptions;
23
24 import java.util.*;
25 import oracle.toplink.essentials.exceptions.i18n.*;
26
27 /**
28  * <P><B>Purpose</B>: EJBQL parsing and resolution problems will raise this exception
29  */

30 public class EJBQLException extends TopLinkException {
31     public static final int recognitionException = 8001;
32     public static final int generalParsingException = 8002;
33     public static final int classNotFoundException = 8003;
34     public static final int aliasResolutionException = 8004;
35     public static final int resolutionClassNotFoundException = 8005;
36     public static final int missingDescriptorException = 8006;
37     public static final int missingMappingException = 8007;
38     public static final int invalidContextKeyException = 8008;
39     public static final int expressionNotSupported = 8009;
40     public static final int generalParsingException2 = 8010;
41     public static final int invalidCollectionMemberDecl = 8011;
42     public static final int notYetImplemented = 8012;
43     public static final int constructorClassNotFound = 8013;
44     public static final int invalidSizeArgument = 8014;
45     public static final int invalidEnumLiteral = 8015;
46     public static final int invalidSelectForGroupByQuery = 8016;
47     public static final int invalidHavingExpression = 8017;
48     public static final int invalidMultipleUseOfSameParameter = 8018;
49     public static final int multipleVariableDeclaration = 8019;
50     public static final int invalidFunctionArgument = 8020;
51     public static final int expectedOrderableOrderByItem = 8021;
52     public static final int invalidExpressionArgument = 8022;
53     public static final int syntaxError = 8023;
54     public static final int syntaxErrorAt = 8024;
55     public static final int unexpectedToken = 8025;
56     public static final int unexpectedChar = 8026;
57     public static final int expectedCharFound = 8027;
58     public static final int unexpectedEOF = 8028;
59     public static final int invalidNavigation = 8029;
60     public static final int unknownAttribute = 8030;
61     public static final int unsupportJoinArgument = 8031;
62     public Collection internalExceptions = null;
63
64     /**
65     * INTERNAL
66     * Only TopLink can throw and create these excpetions
67     */

68     protected EJBQLException() {
69         super();
70     }
71
72     /**
73     * INTERNAL
74     * Only TopLink can throw and create these excpetions
75     */

76     protected EJBQLException(String JavaDoc theMessage) {
77         super(theMessage);
78     }
79
80     /**
81     * INTERNAL
82     * Only TopLink can throw and create these excpetions
83     */

84     protected EJBQLException(String JavaDoc message, Exception JavaDoc internalException) {
85         super(message, internalException);
86     }
87
88     /**
89     * INTERNAL
90     * Only TopLink can throw and create these excpetions
91     */

92     protected EJBQLException(String JavaDoc message, Exception JavaDoc internalException, int theErrorCode) {
93         this(message, internalException);
94         this.setErrorCode(theErrorCode);
95     }
96
97     /**
98      * INTERNAL
99      * Create an exception to wrap the recognition exception thrown
100      */

101     public static EJBQLException recognitionException(String JavaDoc theEjbql, String JavaDoc theMessage) {
102         Object JavaDoc[] args = { theEjbql, theMessage };
103
104         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, recognitionException, args);
105         EJBQLException exception = new EJBQLException(message);
106         exception.setErrorCode(recognitionException);
107         return exception;
108     }
109
110     /**
111      * INTERNAL
112      * Create an exception to wrap a general parsing exception
113      */

114     public static EJBQLException generalParsingException(String JavaDoc theEjbql, Exception JavaDoc theException) {
115         Object JavaDoc[] args = { theEjbql, theException.getMessage() };
116
117         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, generalParsingException, args);
118         EJBQLException exception = new EJBQLException(message, theException, generalParsingException);
119         exception.setErrorCode(generalParsingException);
120         return exception;
121     }
122
123     /**
124      * INTERNAL
125      * Create an exception to wrap a general parsing exception
126      */

127     public static EJBQLException generalParsingException(String JavaDoc theEjbql) {
128         Object JavaDoc[] args = { theEjbql };
129
130         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, generalParsingException2, args);
131         EJBQLException exception = new EJBQLException(message);
132         exception.setErrorCode(generalParsingException);
133         return exception;
134     }
135
136     public static EJBQLException classNotFoundException(String JavaDoc theClassName, String JavaDoc theMessage, Exception JavaDoc theException) {
137         Object JavaDoc[] args = { theClassName, theMessage };
138
139         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, classNotFoundException, args);
140         EJBQLException exception = new EJBQLException(message, theException, classNotFoundException);
141         exception.setErrorCode(classNotFoundException);
142         return exception;
143     }
144
145     public static EJBQLException resolutionClassNotFoundException(String JavaDoc theClassName) {
146         Object JavaDoc[] args = { theClassName };
147
148         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, resolutionClassNotFoundException, args);
149         EJBQLException exception = new EJBQLException(message);
150         exception.setErrorCode(resolutionClassNotFoundException);
151         return exception;
152     }
153
154     public static EJBQLException missingDescriptorException(String JavaDoc theClassName) {
155         Object JavaDoc[] args = { theClassName };
156
157         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, missingDescriptorException, args);
158         EJBQLException exception = new EJBQLException(message);
159         exception.setErrorCode(missingDescriptorException);
160
161         return exception;
162     }
163
164     public static EJBQLException missingMappingException(String JavaDoc theAttributeName) {
165         Object JavaDoc[] args = { theAttributeName };
166
167         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, missingMappingException, args);
168         EJBQLException exception = new EJBQLException(message);
169         exception.setErrorCode(missingMappingException);
170
171         return exception;
172     }
173
174     public static EJBQLException aliasResolutionException(String JavaDoc theAlias) {
175         Object JavaDoc[] args = { theAlias };
176
177         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, aliasResolutionException, args);
178         EJBQLException exception = new EJBQLException(message);
179         exception.setErrorCode(aliasResolutionException);
180         return exception;
181     }
182
183     public static EJBQLException invalidContextKeyException(String JavaDoc theKey) {
184         Object JavaDoc[] args = { theKey };
185
186         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, invalidContextKeyException, args);
187         EJBQLException exception = new EJBQLException(message);
188         exception.setErrorCode(invalidContextKeyException);
189         return exception;
190     }
191
192     public static EJBQLException expressionNotSupported(String JavaDoc unsupportedExpression) {
193         Object JavaDoc[] args = { unsupportedExpression };
194
195         String JavaDoc message = ExceptionMessageGenerator.buildMessage(EJBQLException.class, expressionNotSupported, args);
196         EJBQLException exception = new EJBQLException(message);
197         exception.setErrorCode(expressionNotSupported);
198         return exception;
199     }
200
201     public static EJBQLException invalidCollectionMemberDecl(String JavaDoc attributeName) {
202         Object JavaDoc[] args = { attributeName };
203
204         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
205             EJBQLException.class, invalidCollectionMemberDecl, args);
206         EJBQLException exception = new EJBQLException(message);
207         exception.setErrorCode(invalidCollectionMemberDecl);
208         return exception;
209     }
210
211     public static EJBQLException notYetImplemented(String JavaDoc detail) {
212         Object JavaDoc[] args = { detail };
213
214         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
215             EJBQLException.class, notYetImplemented, args);
216         EJBQLException exception = new EJBQLException(message);
217         exception.setErrorCode(notYetImplemented);
218         return exception;
219     }
220
221     public static EJBQLException constructorClassNotFound(String JavaDoc className) {
222         Object JavaDoc[] args = { className };
223
224         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
225             EJBQLException.class, constructorClassNotFound, args);
226         EJBQLException exception = new EJBQLException(message);
227         exception.setErrorCode(constructorClassNotFound);
228         return exception;
229     }
230
231     public static EJBQLException invalidSizeArgument(String JavaDoc attributeName) {
232         Object JavaDoc[] args = { attributeName };
233
234         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
235             EJBQLException.class, invalidSizeArgument, args);
236         EJBQLException exception = new EJBQLException(message);
237         exception.setErrorCode(invalidSizeArgument);
238         return exception;
239     }
240
241     public static EJBQLException invalidEnumLiteral(String JavaDoc enumType, String JavaDoc constant) {
242         Object JavaDoc[] args = { enumType, constant };
243
244         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
245             EJBQLException.class, invalidEnumLiteral, args);
246         EJBQLException exception = new EJBQLException(message);
247         exception.setErrorCode(invalidEnumLiteral);
248         return exception;
249     }
250
251     public static EJBQLException invalidSelectForGroupByQuery(String JavaDoc select, String JavaDoc groupBy) {
252         Object JavaDoc[] args = { select, groupBy };
253
254         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
255             EJBQLException.class, invalidSelectForGroupByQuery, args);
256         EJBQLException exception = new EJBQLException(message);
257         exception.setErrorCode(invalidSelectForGroupByQuery);
258         return exception;
259     }
260
261     public static EJBQLException invalidHavingExpression(String JavaDoc having, String JavaDoc groupBy) {
262         Object JavaDoc[] args = { having, groupBy };
263
264         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
265             EJBQLException.class, invalidHavingExpression, args);
266         EJBQLException exception = new EJBQLException(message);
267         exception.setErrorCode(invalidHavingExpression);
268         return exception;
269     }
270
271     public static EJBQLException invalidMultipleUseOfSameParameter(
272         String JavaDoc parameter, String JavaDoc oldType, String JavaDoc newType) {
273         Object JavaDoc[] args = { parameter, oldType, newType };
274
275         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
276             EJBQLException.class, invalidMultipleUseOfSameParameter, args);
277         EJBQLException exception = new EJBQLException(message);
278         exception.setErrorCode(invalidMultipleUseOfSameParameter);
279         return exception;
280     }
281
282     public static EJBQLException multipleVariableDeclaration(
283         String JavaDoc variable, String JavaDoc oldDecl) {
284         Object JavaDoc[] args = { variable, oldDecl };
285
286         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
287             EJBQLException.class, multipleVariableDeclaration, args);
288         EJBQLException exception = new EJBQLException(message);
289         exception.setErrorCode(multipleVariableDeclaration);
290         return exception;
291     }
292
293     public static EJBQLException invalidFunctionArgument(String JavaDoc functionName, String JavaDoc attributeName, String JavaDoc type) {
294         Object JavaDoc[] args = { functionName, attributeName, type };
295
296         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
297             EJBQLException.class, invalidFunctionArgument, args);
298         EJBQLException exception = new EJBQLException(message);
299         exception.setErrorCode(invalidFunctionArgument);
300         return exception;
301     }
302
303     public static EJBQLException invalidExpressionArgument(String JavaDoc functionName, String JavaDoc attributeName, String JavaDoc type) {
304         Object JavaDoc[] args = { functionName, attributeName, type };
305
306         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
307             EJBQLException.class, invalidExpressionArgument, args);
308         EJBQLException exception = new EJBQLException(message);
309         exception.setErrorCode(invalidExpressionArgument);
310         return exception;
311     }
312
313     public static EJBQLException unsupportJoinArgument(String JavaDoc functionName, String JavaDoc type) {
314         Object JavaDoc[] args = { functionName, type };
315
316         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
317             EJBQLException.class, unsupportJoinArgument, args);
318         EJBQLException exception = new EJBQLException(message);
319         exception.setErrorCode(unsupportJoinArgument);
320         return exception;
321     }
322
323     public static EJBQLException expectedOrderableOrderByItem(String JavaDoc item, String JavaDoc type) {
324         Object JavaDoc[] args = { item, type };
325
326         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
327             EJBQLException.class, expectedOrderableOrderByItem, args);
328         EJBQLException exception = new EJBQLException(message);
329         exception.setErrorCode(expectedOrderableOrderByItem);
330         return exception;
331     }
332
333     public static EJBQLException syntaxError(String JavaDoc query) {
334         Object JavaDoc[] args = { query };
335
336         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
337             EJBQLException.class, syntaxError, args);
338         EJBQLException exception = new EJBQLException(message);
339         exception.setErrorCode(syntaxError);
340         return exception;
341     }
342
343     public static EJBQLException syntaxErrorAt(String JavaDoc query, String JavaDoc token) {
344         Object JavaDoc[] args = { query, token };
345
346         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
347             EJBQLException.class, syntaxErrorAt, args);
348         EJBQLException exception = new EJBQLException(message);
349         exception.setErrorCode(syntaxErrorAt);
350         return exception;
351     }
352
353     public static EJBQLException unexpectedToken(String JavaDoc query, String JavaDoc token) {
354         Object JavaDoc[] args = { query, token };
355
356         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
357             EJBQLException.class, unexpectedToken, args);
358         EJBQLException exception = new EJBQLException(message);
359         exception.setErrorCode(unexpectedToken);
360         return exception;
361     }
362
363     public static EJBQLException unexpectedChar(String JavaDoc query, String JavaDoc unexpected) {
364         Object JavaDoc[] args = { query, unexpected };
365
366         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
367             EJBQLException.class, unexpectedChar, args);
368         EJBQLException exception = new EJBQLException(message);
369         exception.setErrorCode(unexpectedChar);
370         return exception;
371     }
372
373     public static EJBQLException expectedCharFound(String JavaDoc query, String JavaDoc expected, String JavaDoc found) {
374         Object JavaDoc[] args = { query, expected, found };
375
376         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
377             EJBQLException.class, expectedCharFound, args);
378         EJBQLException exception = new EJBQLException(message);
379         exception.setErrorCode(expectedCharFound);
380         return exception;
381     }
382
383     public static EJBQLException unexpectedEOF(String JavaDoc query) {
384         Object JavaDoc[] args = { query };
385
386         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
387             EJBQLException.class, unexpectedEOF, args);
388         EJBQLException exception = new EJBQLException(message);
389         exception.setErrorCode(unexpectedEOF);
390         return exception;
391     }
392
393     public static EJBQLException invalidNavigation(
394         String JavaDoc expr, String JavaDoc lhs, String JavaDoc type) {
395         Object JavaDoc[] args = { expr, lhs, type };
396
397         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
398             EJBQLException.class, invalidNavigation, args);
399         EJBQLException exception = new EJBQLException(message);
400         exception.setErrorCode(invalidNavigation);
401         return exception;
402     }
403
404     public static EJBQLException unknownAttribute(String JavaDoc type, String JavaDoc name) {
405         Object JavaDoc[] args = { type, name };
406
407         String JavaDoc message = ExceptionMessageGenerator.buildMessage(
408             EJBQLException.class, unknownAttribute, args);
409         EJBQLException exception = new EJBQLException(message);
410         exception.setErrorCode(unknownAttribute);
411         return exception;
412     }
413
414     /**
415      * INTERNAL
416      * Add an internal Exception to the collection of
417      * internal Exceptions
418      */

419     public Object JavaDoc addInternalException(Object JavaDoc theException) {
420         getInternalExceptions().add(theException);
421         return theException;
422     }
423
424     /**
425      * INTERNAL
426      * Does this exception have any internal errors?
427      */

428     public boolean hasInternalExceptions() {
429         return !getInternalExceptions().isEmpty();
430     }
431
432     /**
433      * INTERNAL
434      * Return the collection of internal Exceptions.
435      * Intialize if there are no exceptions
436      */

437     public Collection getInternalExceptions() {
438         if (internalExceptions == null) {
439             setInternalExceptions(new Vector());
440         }
441         return internalExceptions;
442     }
443
444     /**
445      * INTERNAL
446      * Store the exceptions related to this exception
447      */

448     public void setInternalExceptions(Collection theExceptions) {
449         internalExceptions = theExceptions;
450     }
451
452     /**
453      * PUBLIC
454      * Print the stack trace for each error generated by the
455      * parser. This method is intended to assist in debugging
456      * problems in EJBQL
457      */

458     public void printFullStackTrace() {
459         if (hasInternalExceptions()) {
460             Iterator exceptions = getInternalExceptions().iterator();
461             while (exceptions.hasNext()) {
462                 Throwable JavaDoc error = (Throwable JavaDoc)exceptions.next();
463                 error.printStackTrace();
464             }
465         }
466     }
467 }
468
Popular Tags