--- /dev/null
+/*\r
+ Derby - Class org.apache.derby.common.error.ExceptionUtil\r
+ \r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+ \r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+ \r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+ \r
+ */\r
+package org.apache.derby.shared.common.error;\r
+\r
+import org.apache.derby.shared.common.error.ExceptionSeverity;\r
+\r
+/**\r
+ * This class provides utility routines for exceptions \r
+ */\r
+public class ExceptionUtil\r
+{\r
+ /**\r
+ * Convert a message identifer from \r
+ * org.apache.derby.shared.common.reference.SQLState to\r
+ * a SQLState five character string.\r
+ *\r
+ * @param messageID - the sql state id of the message from Derby\r
+ * @return String - the 5 character code of the SQLState ID to returned to the user \r
+ */\r
+ public static String getSQLStateFromIdentifier(String messageID) {\r
+\r
+ if (messageID.length() == 5)\r
+ return messageID;\r
+ return messageID.substring(0, 5);\r
+ }\r
+ \r
+ /**\r
+ * Get the severity given a message identifier from SQLState.\r
+ */\r
+ public static int getSeverityFromIdentifier(String messageID) {\r
+\r
+ int lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;\r
+\r
+ switch (messageID.length()) {\r
+ case 5:\r
+ switch (messageID.charAt(0)) {\r
+ case '0':\r
+ switch (messageID.charAt(1)) {\r
+ case '1':\r
+ lseverity = ExceptionSeverity.WARNING_SEVERITY;\r
+ break;\r
+ case 'A':\r
+ case '7':\r
+ lseverity = ExceptionSeverity.STATEMENT_SEVERITY;\r
+ break;\r
+ case '8':\r
+ lseverity = ExceptionSeverity.SESSION_SEVERITY;\r
+ break;\r
+ }\r
+ break; \r
+ case '2':\r
+ case '3':\r
+ lseverity = ExceptionSeverity.STATEMENT_SEVERITY;\r
+ break;\r
+ case '4':\r
+ switch (messageID.charAt(1)) {\r
+ case '0':\r
+ lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;\r
+ break;\r
+ case '2':\r
+ lseverity = ExceptionSeverity.STATEMENT_SEVERITY;\r
+ break;\r
+ }\r
+ break; \r
+ }\r
+ break;\r
+\r
+ default:\r
+ switch (messageID.charAt(6)) {\r
+ case 'M':\r
+ lseverity = ExceptionSeverity.SYSTEM_SEVERITY;\r
+ break;\r
+ case 'D':\r
+ lseverity = ExceptionSeverity.DATABASE_SEVERITY;\r
+ break;\r
+ case 'C':\r
+ lseverity = ExceptionSeverity.SESSION_SEVERITY;\r
+ break;\r
+ case 'T':\r
+ lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;\r
+ break;\r
+ case 'S':\r
+ lseverity = ExceptionSeverity.STATEMENT_SEVERITY;\r
+ break;\r
+ case 'U':\r
+ lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;\r
+ break;\r
+ }\r
+ break;\r
+ }\r
+\r
+ return lseverity;\r
+ }\r
+\r
+}\r