johng 2003/06/19 11:11:30
Modified: java/src/org/apache/xalan/lib/sql SQLErrorDocument.java
Log:
Added code by Art Welsh to hande full errors, where multiple warning
stattments wll be output into the error document
Revision Changes Path
1.7 +80 -1
xml-xalan/java/src/org/apache/xalan/lib/sql/SQLErrorDocument.java
Index: SQLErrorDocument.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/SQLErrorDocument.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SQLErrorDocument.java 30 Jan 2003 18:45:44 -0000 1.6
+++ SQLErrorDocument.java 19 Jun 2003 18:11:29 -0000 1.7
@@ -59,6 +59,7 @@
package org.apache.xalan.lib.sql;
import java.sql.SQLException;
+import java.sql.SQLWarning;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMManager;
@@ -99,6 +100,14 @@
/**
*/
+ private static final String S_STATE = "state";
+
+ /**
+ */
+ private static final String S_SQL_WARNING = "sql-warning";
+
+ /**
+ */
private int m_ErrorExt_TypeID = DTM.NULL;
/**
*/
@@ -109,6 +118,14 @@
/**
*/
+ private int m_State_TypeID = DTM.NULL;
+
+ /**
+ */
+ private int m_SQLWarning_TypeID = DTM.NULL;
+
+ /**
+ */
private int m_SQLError_TypeID = DTM.NULL;
/**
@@ -164,6 +181,62 @@
}
/**
+ * Build up an Error Exception with just the Standard Error Information
+ * @param mgr
+ * @param ident
+ * @param error
+ */
+ public SQLErrorDocument(DTMManager mgr, int ident, Exception error,
SQLWarning warning, boolean full)
+ {
+ super(mgr, ident);
+ createExpandedNameTable();
+ buildBasicStructure(error);
+
+ SQLException se = null;
+ int prev = m_MainMessageID;
+ boolean inWarnings = false;
+
+ if ( error != null && error instanceof SQLException )
+ se = (SQLException)error;
+ else if ( full && warning != null )
+ {
+ se = warning;
+ inWarnings = true;
+ }
+
+ while ( se != null )
+ {
+ int sqlError = addElement(2, inWarnings ? m_SQLWarning_TypeID :
m_SQLError_TypeID, m_extErrorID, prev);
+ prev = sqlError;
+ int element = DTM.NULL;
+
+ element = addElementWithData(
+ new Integer(se.getErrorCode()), 3,
+ m_Code_TypeID, sqlError, element);
+
+ element = addElementWithData(
+ se.getLocalizedMessage(), 3,
+ m_Message_TypeID, sqlError, element);
+
+ if ( full )
+ {
+ String state = se.getSQLState();
+ if ( state != null && state.length() > 0 )
+ element = addElementWithData(
+ state, 3,
+ m_State_TypeID, sqlError, element);
+
+ if ( inWarnings )
+ se = ((SQLWarning)se).getNextWarning();
+ else
+ se = se.getNextException();
+ }
+ else
+ se = null;
+ }
+ }
+
+ /**
* Build up the basic structure that is common for each error.
* @param e
* @return
@@ -173,7 +246,7 @@
m_rootID = addElement(0, m_Document_TypeID, DTM.NULL, DTM.NULL);
m_extErrorID = addElement(1, m_ErrorExt_TypeID, m_rootID, DTM.NULL);
m_MainMessageID = addElementWithData
- (e.getLocalizedMessage(), 2, m_Message_TypeID, m_extErrorID, DTM.NULL);
+ (e != null ? e.getLocalizedMessage() : "SQLWarning", 2,
m_Message_TypeID, m_extErrorID, DTM.NULL);
}
/**
@@ -197,6 +270,12 @@
m_Code_TypeID =
m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_CODE,
DTM.ELEMENT_NODE);
+
+ m_State_TypeID =
+ m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_STATE,
DTM.ELEMENT_NODE);
+
+ m_SQLWarning_TypeID =
+ m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SQL_WARNING,
DTM.ELEMENT_NODE);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]