KickJava   Java API By Example, From Geeks To Geeks.

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


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 ErrorTextParserPOSTGRE extends ErrorTextParser {
25   static Logger log4j = Logger.getLogger(ErrorTextParserPOSTGRE.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 Getting DB object name
37
int pos = myMessage.indexOf("\"");
38     if (pos != -1) {
39       myMessage = myMessage.substring(pos+1);
40       pos = myMessage.indexOf("\"");
41       if (pos != -1) {
42         myMessage = myMessage.substring(pos+1);
43         pos = myMessage.indexOf("\"");
44         if (pos != -1) {
45           myMessage = myMessage.substring(pos+1);
46           int finalPos = myMessage.indexOf("\"");
47           if (finalPos==-1) finalPos = myMessage.length();
48           String JavaDoc objectName = myMessage.substring(0, finalPos);
49           if (log4j.isDebugEnabled()) log4j.debug("Object name: " + objectName);
50           pos = objectName.indexOf(".");
51           if (pos!=-1) objectName = objectName.substring(pos+1);
52           if (log4j.isDebugEnabled()) log4j.debug("Object real name: " + objectName);
53           ErrorTextParserPOSTGREData[] constraintData = ErrorTextParserPOSTGREData.select(getConnection(), objectName);
54           //BEGIN Specific parse for CONSTRAINT DB objects
55
if (constraintData!=null && constraintData.length>0) {
56             //BEGIN Search message by constraint name
57
FieldProvider fldMessage = Utility.locateMessage(getConnection(), constraintData[0].constraintName, getLanguage());
58             if (fldMessage!=null) {
59               myError = new OBError();
60               myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning"));
61               myError.setMessage(fldMessage.getField("msgtext"));
62               return myError;
63             }
64             //END Search message by constraint name
65
if (constraintData[0].constraintType.equalsIgnoreCase("C") && !constraintData[0].searchCondition.equals("")) {
66               //BEGIN Search message by constraint search condition
67
fldMessage = Utility.locateMessage(getConnection(), constraintData[0].searchCondition, getLanguage());
68               if (fldMessage!=null) {
69                 myError = new OBError();
70                 myError.setType((fldMessage.getField("msgtype").equals("E")?"Error":"Warning"));
71                 myError.setMessage(fldMessage.getField("msgtext"));
72                 return myError;
73               } else if (!constraintData[0].searchCondition.trim().equals("")) {
74                 String JavaDoc searchCond = constraintData[0].searchCondition.trim().toUpperCase();
75                 if (searchCond.endsWith(" IS NOT NULL")) {
76                   String JavaDoc columnName = searchCond.substring(0, searchCond.lastIndexOf(" IS NOT NULL")).trim();
77                   columnName = Utility.messageBD(getConnection(), columnName, getLanguage());
78                   String JavaDoc tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage());
79                   myError = new OBError();
80                   myError.setType("Error");
81                   myError.setMessage(Utility.messageBD(getConnection(), "NotNullError", getLanguage()) + ": " + tableName + " - " + columnName);
82                   return myError;
83                 } else if (searchCond.endsWith(" IN ('Y','N')") || searchCond.endsWith(" IN ('Y', 'N')") || searchCond.endsWith(" IN ('N','Y')") || searchCond.endsWith(" IN ('N', 'Y')")) {
84                   String JavaDoc columnName = searchCond.substring(0, searchCond.lastIndexOf(" IN (")).trim();
85                   columnName = Utility.messageBD(getConnection(), columnName, getLanguage());
86                   String JavaDoc tableName = Utility.messageBD(getConnection(), constraintData[0].tableName, getLanguage());
87                   myError = new OBError();
88                   myError.setType("Error");
89                   myError.setMessage(Utility.messageBD(getConnection(), "NotYNError", getLanguage()) + ": " + tableName + " - " + columnName);
90                   return myError;
91                 }
92               }
93               //END Search message by constraint search condition
94
}
95           }
96       //END Specific parse for CONSTRAINT DB objects
97
}
98         else{
99           myError = new OBError();
100           myError.setType("Error");
101           myError.setMessage(getMessage());
102           return myError;
103         }
104       }
105     }
106     else{
107       System.out.println("Error:"+getMessage());
108       myError = new OBError();
109       myError.setType("Error");
110       myError.setMessage(getMessage());
111       return myError;
112     }
113     //END Getting DB object name
114
if (myCodeError!=null) return myCodeError;
115     else return myError;
116   }
117 }
118
Popular Tags