1 16 19 20 package org.apache.xalan.lib.sql; 21 22 import java.sql.SQLException ; 23 import java.sql.SQLWarning ; 24 25 import org.apache.xml.dtm.DTM; 26 import org.apache.xml.dtm.DTMManager; 27 28 43 44 47 public class SQLErrorDocument extends DTMDocument 48 { 49 51 private static final String S_EXT_ERROR = "ext-error"; 52 54 private static final String S_SQL_ERROR = "sql-error"; 55 57 private static final String S_MESSAGE = "message"; 58 60 private static final String S_CODE = "code"; 61 62 64 private static final String S_STATE = "state"; 65 66 68 private static final String S_SQL_WARNING = "sql-warning"; 69 70 72 private int m_ErrorExt_TypeID = DTM.NULL; 73 75 private int m_Message_TypeID = DTM.NULL; 76 78 private int m_Code_TypeID = DTM.NULL; 79 80 82 private int m_State_TypeID = DTM.NULL; 83 84 86 private int m_SQLWarning_TypeID = DTM.NULL; 87 88 90 private int m_SQLError_TypeID = DTM.NULL; 91 92 94 private int m_rootID = DTM.NULL; 95 97 private int m_extErrorID = DTM.NULL; 98 100 private int m_MainMessageID = DTM.NULL; 101 102 109 public SQLErrorDocument( DTMManager mgr, int ident, SQLException error ) 110 { 111 super(mgr, ident); 112 113 createExpandedNameTable(); 114 buildBasicStructure(error); 115 116 int sqlError = addElement(2, m_SQLError_TypeID, m_extErrorID, m_MainMessageID); 117 int element = DTM.NULL; 118 119 element = addElementWithData( 120 new Integer (error.getErrorCode()), 3, 121 m_Code_TypeID, sqlError, element); 122 123 element = addElementWithData( 124 error.getLocalizedMessage(), 3, 125 m_Message_TypeID, sqlError, element); 126 127 } 129 130 131 137 public SQLErrorDocument( DTMManager mgr, int ident, Exception error ) 138 { 139 super(mgr, ident); 140 createExpandedNameTable(); 141 buildBasicStructure(error); 142 } 143 144 150 public SQLErrorDocument(DTMManager mgr, int ident, Exception error, SQLWarning warning, boolean full) 151 { 152 super(mgr, ident); 153 createExpandedNameTable(); 154 buildBasicStructure(error); 155 156 SQLException se = null; 157 int prev = m_MainMessageID; 158 boolean inWarnings = false; 159 160 if ( error != null && error instanceof SQLException ) 161 se = (SQLException )error; 162 else if ( full && warning != null ) 163 { 164 se = warning; 165 inWarnings = true; 166 } 167 168 while ( se != null ) 169 { 170 int sqlError = addElement(2, inWarnings ? m_SQLWarning_TypeID : m_SQLError_TypeID, m_extErrorID, prev); 171 prev = sqlError; 172 int element = DTM.NULL; 173 174 element = addElementWithData( 175 new Integer (se.getErrorCode()), 3, 176 m_Code_TypeID, sqlError, element); 177 178 element = addElementWithData( 179 se.getLocalizedMessage(), 3, 180 m_Message_TypeID, sqlError, element); 181 182 if ( full ) 183 { 184 String state = se.getSQLState(); 185 if ( state != null && state.length() > 0 ) 186 element = addElementWithData( 187 state, 3, 188 m_State_TypeID, sqlError, element); 189 190 if ( inWarnings ) 191 se = ((SQLWarning )se).getNextWarning(); 192 else 193 se = se.getNextException(); 194 } 195 else 196 se = null; 197 } 198 } 199 200 205 private void buildBasicStructure( Exception e ) 206 { 207 m_rootID = addElement(0, m_Document_TypeID, DTM.NULL, DTM.NULL); 208 m_extErrorID = addElement(1, m_ErrorExt_TypeID, m_rootID, DTM.NULL); 209 m_MainMessageID = addElementWithData 210 (e != null ? e.getLocalizedMessage() : "SQLWarning", 2, m_Message_TypeID, m_extErrorID, DTM.NULL); 211 } 212 213 218 protected void createExpandedNameTable( ) 219 { 220 221 super.createExpandedNameTable(); 222 223 m_ErrorExt_TypeID = 224 m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_EXT_ERROR, DTM.ELEMENT_NODE); 225 226 m_SQLError_TypeID = 227 m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SQL_ERROR, DTM.ELEMENT_NODE); 228 229 m_Message_TypeID = 230 m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_MESSAGE, DTM.ELEMENT_NODE); 231 232 m_Code_TypeID = 233 m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_CODE, DTM.ELEMENT_NODE); 234 235 m_State_TypeID = 236 m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_STATE, DTM.ELEMENT_NODE); 237 238 m_SQLWarning_TypeID = 239 m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_SQL_WARNING, DTM.ELEMENT_NODE); 240 } 241 242 } 243 | Popular Tags |