KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > shared > common > error > ExceptionUtil


1 /*
2    Derby - Class org.apache.derby.common.error.ExceptionUtil
3  
4    Licensed to the Apache Software Foundation (ASF) under one or more
5    contributor license agreements. See the NOTICE file distributed with
6    this work for additional information regarding copyright ownership.
7    The ASF licenses this file to you under the Apache License, Version 2.0
8    (the "License"); you may not use this file except in compliance with
9    the License. You may obtain a copy of the License at
10  
11       http://www.apache.org/licenses/LICENSE-2.0
12  
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18  
19  */

20 package org.apache.derby.shared.common.error;
21
22 import org.apache.derby.shared.common.error.ExceptionSeverity;
23
24 /**
25  * This class provides utility routines for exceptions
26  */

27 public class ExceptionUtil
28 {
29     /**
30      * Convert a message identifer from
31      * org.apache.derby.shared.common.reference.SQLState to
32      * a SQLState five character string.
33      *
34      * @param messageID - the sql state id of the message from cloudscape
35      * @return String - the 5 character code of the SQLState ID to returned to the user
36     */

37     public static String JavaDoc getSQLStateFromIdentifier(String JavaDoc messageID) {
38
39         if (messageID.length() == 5)
40             return messageID;
41         return messageID.substring(0, 5);
42     }
43     
44     /**
45     * Get the severity given a message identifier from SQLState.
46     */

47     public static int getSeverityFromIdentifier(String JavaDoc messageID) {
48
49         int lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;
50
51         switch (messageID.length()) {
52         case 5:
53             switch (messageID.charAt(0)) {
54             case '0':
55                 switch (messageID.charAt(1)) {
56                 case '1':
57                     lseverity = ExceptionSeverity.WARNING_SEVERITY;
58                     break;
59                 case 'A':
60                 case '7':
61                     lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
62                     break;
63                 case '8':
64                     lseverity = ExceptionSeverity.SESSION_SEVERITY;
65                     break;
66                 }
67                 break;
68             case '2':
69             case '3':
70                 lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
71                 break;
72             case '4':
73                 switch (messageID.charAt(1)) {
74                 case '0':
75                     lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;
76                     break;
77                 case '2':
78                     lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
79                     break;
80                 }
81                 break;
82             }
83             break;
84
85         default:
86             switch (messageID.charAt(6)) {
87             case 'M':
88                 lseverity = ExceptionSeverity.SYSTEM_SEVERITY;
89                 break;
90             case 'D':
91                 lseverity = ExceptionSeverity.DATABASE_SEVERITY;
92                 break;
93             case 'C':
94                 lseverity = ExceptionSeverity.SESSION_SEVERITY;
95                 break;
96             case 'T':
97                 lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;
98                 break;
99             case 'S':
100                 lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
101                 break;
102             case 'U':
103                 lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;
104                 break;
105             }
106             break;
107         }
108
109         return lseverity;
110     }
111
112 }
113
Popular Tags