KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > utility > ErrorTextParserORACLE


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.utility;
20
21 import org.openbravo.data.FieldProvider;
22 import org.apache.log4j.Logger;
23
24 public class ErrorTextParserORACLE extends ErrorTextParser {
25   static Logger log4j = Logger.getLogger(ErrorTextParserORACLE.class);
26
27   public OBError parse() throws Exception JavaDoc {
28     if (getMessage().equals("")) return null;
29     else if (getConnection()==null) return null;
30     OBError myError = null;
31     OBError myCodeError = null;
32     int errorCode = 0;
33     String JavaDoc errorCodeText = "";
34     String JavaDoc myMessage = getMessage();
35     if (log4j.isDebugEnabled()) log4j.debug("Message: " + myMessage);
36     //BEGIN Checking if it's a DB error
37
int pos = myMessage.indexOf("ORA-");
38     if (pos!=-1) {
39       //BEGIN Getting error code
40
try {
41         errorCode = Integer.valueOf(myMessage.substring(pos+4, myMessage.indexOf(":", pos+4))).intValue();
42         errorCodeText = myMessage.substring(pos, myMessage.indexOf(":", pos));
43       } catch (Exception JavaDoc ignored) {
44         errorCode = 0;
45         errorCodeText = "";
46       }
47       if (log4j.isDebugEnabled()) log4j.debug("Error code: " + Integer.toString(errorCode));
48       if (errorCode!=0) {
49         FieldProvider fldMessage = Utility.locateMessage(getConnection(), errorCodeText, getLanguage());
50         if (fldMessage!=null) {
51           myCodeError = new OBError();
52           myCodeError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning"));
53           myCodeError.setMessage(fldMessage.getField("msgtext"));
54           //return myError;
55
} else if (errorCode>= 20000 && errorCode<=30000) {
56           myError = new OBError();
57           myError.setType("Error");
58           String JavaDoc messageAux = Utility.parseTranslation(getConnection(), getVars(), getLanguage(), myMessage.replace(errorCodeText + ": ", ""));
59           if (log4j.isDebugEnabled()) log4j.debug("Message parsed: " + messageAux);
60           myError.setMessage(messageAux);
61           return myError;
62         }
63       }
64       //END Getting error code
65
//BEGIN Getting DB object name
66
pos = myMessage.indexOf("(", pos+4);
67       if (pos != -1) {
68         int finalPos = myMessage.indexOf(")", pos+1);
69         if (finalPos==-1) finalPos = myMessage.length();
70         String JavaDoc objectName = myMessage.substring(pos + 1, finalPos);
71         if (log4j.isDebugEnabled()) log4j.debug("Object name: " + objectName);
72         pos = objectName.indexOf(".");
73         if (pos!=-1) objectName = objectName.substring(pos+1);
74         if (log4j.isDebugEnabled()) log4j.debug("Object real name: " + objectName);
75         ErrorTextParserORACLEData[] constraintData = ErrorTextParserORACLEData.select(getConnection(), objectName);
76         //BEGIN Specific parse for CONSTRAINT DB objects
77
if (constraintData!=null && constraintData.length>0) {
78           //BEGIN Search message by constraint name
79
FieldProvider fldMessage = Utility.locateMessage(getConnection(), constraintData[0].constraintName, getLanguage());
80           if (fldMessage!=null) {
81             myError = new OBError();
82             myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning"));
83             myError.setMessage(fldMessage.getField("msgtext"));
84             return myError;
85           }
86           //END Search message by constraint name
87
if (constraintData[0].constraintType.equalsIgnoreCase("C") && !constraintData[0].searchCondition.equals("")) {
88             //BEGIN Search message by constraint search condition
89
fldMessage = Utility.locateMessage(getConnection(), constraintData[0].searchCondition, getLanguage());
90             if (fldMessage!=null) {
91               myError = new OBError();
92               myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning"));
93               myError.setMessage(fldMessage.getField("msgtext"));
94               return myError;
95             } else if (!constraintData[0].searchCondition.trim().equals("")) {
96               String JavaDoc searchCond = constraintData[0].searchCondition.trim().toUpperCase();
97               if (searchCond.endsWith(" IS NOT NULL")) {
98                 String JavaDoc columnName = searchCond.substring(0, searchCond.lastIndexOf(" IS NOT NULL")).trim();
99                 columnName = Utility.messageBD(getConnection(), columnName, getLanguage());
100                 String JavaDoc tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage());
101                 myError = new OBError();
102                 myError.setType("Error");
103                 myError.setMessage(Utility.messageBD(getConnection(), "NotNullError", getLanguage()) + ": " + tableName + " - " + columnName);
104                 return myError;
105               } else if (searchCond.endsWith(" IN ('Y','N')") || searchCond.endsWith(" IN ('Y', 'N')") || searchCond.endsWith(" IN ('N','Y')") || searchCond.endsWith(" IN ('N', 'Y')")) {
106                 String JavaDoc columnName = searchCond.substring(0, searchCond.lastIndexOf(" IN (")).trim();
107                 columnName = Utility.messageBD(getConnection(), columnName, getLanguage());
108                 String JavaDoc tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage());
109                 myError = new OBError();
110                 myError.setType("Error");
111                 myError.setMessage(Utility.messageBD(getConnection(), "NotYNError", getLanguage()) + ": " + tableName + " - " + columnName);
112                 return myError;
113               }
114             }
115             //END Search message by constraint search condition
116
}
117         }
118         //END Specific parse for CONSTRAINT DB objects
119
}
120       //END Getting DB object name
121
}
122     //END Checking if it's a DB error
123
if (myCodeError!=null) return myCodeError;
124     else return myError;
125   }
126 }
127
Popular Tags