1 package org.ejen.ext.db; 22 23 import org.ejen.util.DOMUtil; 24 import org.ejen.util.XSLUtil; 25 import java.sql.Statement ; 26 import java.sql.ResultSetMetaData ; 27 import java.sql.ResultSet ; 28 import java.sql.Connection ; 29 import java.sql.DatabaseMetaData ; 30 import java.sql.SQLException ; 31 import org.w3c.dom.Document ; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 import org.apache.xpath.NodeSet; 35 import org.apache.xml.utils.WrappedRuntimeException; 36 import org.apache.xalan.extensions.ExpressionContext; 37 38 44 public abstract class MetaDataNodeBuilder { 45 public static final String S_DI_NODE_NAME = "database-information"; 47 public static final String S_DI_DATABASE_PRODUCT_NAME = "database-product-name"; 48 public static final String S_DI_DATABASE_PRODUCT_VERSION = "database-product-version"; 49 public static final String S_RS_COLUMN_NODE_NAME = "column"; 51 public static final String S_RS_CATALOG_NAME = "catalog-name"; 52 public static final String S_RS_COLUMN_CLASS_NAME = "column-class-name"; 53 public static final String S_RS_COLUMN_DISPLAY_SIZE = "column-display-size"; 54 public static final String S_RS_COLUMN_LABEL = "column-label"; 55 public static final String S_RS_COLUMN_NAME = "column-name"; 56 public static final String S_RS_COLUMN_TYPE = "column-type"; 57 public static final String S_RS_COLUMN_TYPE_NAME = "column-type-name"; 58 public static final String S_RS_PRECISION = "precision"; 59 public static final String S_RS_SCALE = "scale"; 60 public static final String S_RS_SCHEMA_NAME = "schema-name"; 61 public static final String S_RS_TABLE_NAME = "table-name"; 62 public static final String S_RS_AUTO_INCREMENT = "auto-increment"; 63 public static final String S_RS_CASE_SENSITIVE = "case-sensitive"; 64 public static final String S_RS_CURRENCY = "currency"; 65 public static final String S_RS_DEFINITELY_WRITABLE = "definitely-writable"; 66 public static final String S_RS_NULLABLE = "nullable"; 67 public static final String S_RS_READ_ONLY = "read-only"; 68 public static final String S_RS_SEARCHABLE = "searchable"; 69 public static final String S_RS_SIGNED = "signed"; 70 public static final String S_RS_WRITABLE = "writable"; 71 public static final String S_RS_COLUMN_NO_NULLS = "column-no-nulls"; 72 public static final String S_RS_COLUMN_NULLABLE = "column-nullable"; 73 public static final String S_RS_COLUMN_NULLABLE_UNKNOWN = "column-nullable-unknown"; 74 public static final String S_PK_NODE_NAME = "primary-key"; 76 public static final String S_PK_TABLE_CAT = "table-cat"; 77 public static final String S_PK_TABLE_SCHEM = "table-shem"; 78 public static final String S_PK_TABLE_NAME = "table-name"; 79 public static final String S_PK_COLUMN_NAME = "column-name"; 80 public static final String S_PK_KEY_SEQ = "key-seq"; 81 public static final String S_PK_PK_NAME = "pk-name"; 82 public static final String S_EIK_EK_NODE_NAME = "exported-key"; 84 public static final String S_EIK_IK_NODE_NAME = "imported-key"; 85 public static final String S_EIK_PKTABLE_CAT = "pktable-cat"; 86 public static final String S_EIK_PKTABLE_SCHEM = "pktable-shem"; 87 public static final String S_EIK_PKTABLE_NAME = "pktable-name"; 88 public static final String S_EIK_PKCOLUMN_NAME = "pkcolumn-name"; 89 public static final String S_EIK_FKTABLE_CAT = "fktable-cat"; 90 public static final String S_EIK_FKTABLE_SCHEM = "fktable-shem"; 91 public static final String S_EIK_FKTABLE_NAME = "fktable-name"; 92 public static final String S_EIK_FKCOLUMN_NAME = "fkcolumn-name"; 93 public static final String S_EIK_KEY_SEQ = "key-seq"; 94 public static final String S_EIK_UPDATE_RULE = "update-rule"; 95 public static final String S_EIK_DELETE_RULE = "delete-rule"; 96 public static final String S_EIK_FK_NAME = "fk-name"; 97 public static final String S_EIK_PK_NAME = "pk-name"; 98 public static final String S_EIK_DEFERRABILITY = "deferrability"; 99 public static final String S_II_NODE_NAME = "index"; 101 public static final String S_II_TABLE_CAT = "table-cat"; 102 public static final String S_II_TABLE_SCHEM = "table-shem"; 103 public static final String S_II_TABLE_NAME = "table-name"; 104 public static final String S_II_NON_UNIQUE = "non-unique"; 105 public static final String S_II_INDEX_QUALIFIER = "index-qualifier"; 106 public static final String S_II_INDEX_NAME = "index-name"; 107 public static final String S_II_TYPE = "type"; 108 public static final String S_II_ORDINAL_POSITION = "ordinal-position"; 109 public static final String S_II_COLUMN_NAME = "column-name"; 110 public static final String S_II_ASC_OR_DESC = "asc-or-desc"; 111 public static final String S_II_CARDINALITY = "cardinality"; 112 public static final String S_II_PAGES = "pages"; 113 public static final String S_II_FILTER_CONDITION = "filter-condition"; 114 public static final String S_EXCEPTION_NODE_NAME = "exception"; 116 public static final String S_EXCEPTION_CLASS_NAME = "class-name"; 117 public static final String S_EXCEPTION_CODE = "code"; 118 public static final String S_NOT_SUPPORTED = "#NOT_SUPPORTED"; 120 public static final String S_NULL = "#NULL"; 121 122 123 protected static NodeSet _errors = null; 124 125 126 protected static Connection _activeConn = null; 127 128 134 protected static Connection getConnection() throws SQLException { 135 if (_activeConn == null) { 136 throw new SQLException ("Not connected"); 137 } 138 return _activeConn; 139 } 140 141 162 public static NodeSet getErrors(ExpressionContext context) { 163 return _errors; 164 } 165 166 193 public static Node getDatabaseInformation(ExpressionContext context) { 194 Document doc = XSLUtil.getContextDocument(context); 195 196 try { 197 DatabaseMetaData dbmd = getConnection().getMetaData(); 198 Element elt = doc.createElement(S_DI_NODE_NAME); 199 200 elt.setAttribute(S_DI_DATABASE_PRODUCT_NAME, 201 noNull(dbmd.getDatabaseProductName())); 202 elt.setAttribute(S_DI_DATABASE_PRODUCT_VERSION, 203 noNull(dbmd.getDatabaseProductVersion())); 204 return elt; 205 } catch (SQLException e) { 206 appendErrorNode(e); 207 } catch (Exception e) { 208 throw new WrappedRuntimeException(e); 209 } 210 return null; 211 } 212 213 280 public static NodeSet getResultSetMetaData(ExpressionContext context, 281 String table) { 282 table = XSLUtil.evaluate(context, table); 283 _errors = null; 284 return getResultSetMetaData(table, "*", S_RS_COLUMN_NODE_NAME, 285 XSLUtil.getContextDocument(context)); 286 } 287 288 310 public static NodeSet getResultSetMetaData(ExpressionContext context, 311 String table, 312 String columns) { 313 table = XSLUtil.evaluate(context, table); 314 columns = XSLUtil.evaluate(context, columns); 315 _errors = null; 316 return getResultSetMetaData(table, columns, S_RS_COLUMN_NODE_NAME, 317 XSLUtil.getContextDocument(context)); 318 } 319 320 333 protected static NodeSet getResultSetMetaData(String table, 334 String columns, 335 String eltName, 336 Document doc) { 337 Statement stmt = null; 338 339 try { 340 stmt = getConnection().createStatement(); 341 ResultSetMetaData rsmd 342 = stmt.executeQuery("SELECT " + columns + " FROM " + table).getMetaData(); 343 String columnNoNulls = String.valueOf(rsmd.columnNoNulls); 344 String columnNullable = String.valueOf(rsmd.columnNullable); 345 String columnNullableUnknown = String.valueOf(rsmd.columnNullableUnknown); 346 int count = rsmd.getColumnCount(); 347 NodeSet ns = new NodeSet(); 348 349 ns.setShouldCacheNodes(true); 350 for (int i = 1; i <= count; i++) { 351 Element elt = doc.createElement(eltName); 352 353 try { 354 elt.setAttribute(S_RS_CATALOG_NAME, 355 noNull(rsmd.getCatalogName(i))); 356 } catch (SQLException e) { 357 elt.setAttribute(S_RS_CATALOG_NAME, S_NOT_SUPPORTED); 358 } 359 try { 360 elt.setAttribute(S_RS_COLUMN_CLASS_NAME, 361 noNull(rsmd.getColumnClassName(i))); 362 } catch (SQLException e) { 363 elt.setAttribute(S_RS_COLUMN_CLASS_NAME, S_NOT_SUPPORTED); 364 } 365 try { 366 elt.setAttribute(S_RS_COLUMN_DISPLAY_SIZE, 367 String.valueOf(rsmd.getColumnDisplaySize(i))); 368 } catch (SQLException e) { 369 elt.setAttribute(S_RS_COLUMN_DISPLAY_SIZE, S_NOT_SUPPORTED); 370 } 371 try { 372 elt.setAttribute(S_RS_COLUMN_LABEL, 373 noNull(rsmd.getColumnLabel(i))); 374 } catch (SQLException e) { 375 elt.setAttribute(S_RS_COLUMN_LABEL, S_NOT_SUPPORTED); 376 } 377 try { 378 elt.setAttribute(S_RS_COLUMN_NAME, 379 noNull(rsmd.getColumnName(i))); 380 } catch (SQLException e) { 381 elt.setAttribute(S_RS_COLUMN_NAME, S_NOT_SUPPORTED); 382 } 383 try { 384 elt.setAttribute(S_RS_COLUMN_TYPE, 385 String.valueOf(rsmd.getColumnType(i))); 386 } catch (SQLException e) { 387 elt.setAttribute(S_RS_COLUMN_TYPE, S_NOT_SUPPORTED); 388 } 389 try { 390 elt.setAttribute(S_RS_COLUMN_TYPE_NAME, 391 noNull(rsmd.getColumnTypeName(i))); 392 } catch (SQLException e) { 393 elt.setAttribute(S_RS_COLUMN_TYPE_NAME, S_NOT_SUPPORTED); 394 } 395 try { 396 elt.setAttribute(S_RS_PRECISION, 397 String.valueOf(rsmd.getPrecision(i))); 398 } catch (SQLException e) { 399 elt.setAttribute(S_RS_PRECISION, S_NOT_SUPPORTED); 400 } 401 try { 402 elt.setAttribute(S_RS_SCALE, 403 String.valueOf(rsmd.getScale(i))); 404 } catch (SQLException e) { 405 elt.setAttribute(S_RS_SCALE, S_NOT_SUPPORTED); 406 } 407 try { 408 elt.setAttribute(S_RS_SCHEMA_NAME, 409 noNull(rsmd.getSchemaName(i))); 410 } catch (SQLException e) { 411 elt.setAttribute(S_RS_SCHEMA_NAME, S_NOT_SUPPORTED); 412 } 413 try { 414 elt.setAttribute(S_RS_TABLE_NAME, 415 noNull(rsmd.getTableName(i))); 416 } catch (SQLException e) { 417 elt.setAttribute(S_RS_TABLE_NAME, S_NOT_SUPPORTED); 418 } 419 try { 420 elt.setAttribute(S_RS_AUTO_INCREMENT, 421 String.valueOf(rsmd.isAutoIncrement(i))); 422 } catch (SQLException e) { 423 elt.setAttribute(S_RS_AUTO_INCREMENT, S_NOT_SUPPORTED); 424 } 425 try { 426 elt.setAttribute(S_RS_CASE_SENSITIVE, 427 String.valueOf(rsmd.isCaseSensitive(i))); 428 } catch (SQLException e) { 429 elt.setAttribute(S_RS_CASE_SENSITIVE, S_NOT_SUPPORTED); 430 } 431 try { 432 elt.setAttribute(S_RS_CURRENCY, 433 String.valueOf(rsmd.isCurrency(i))); 434 } catch (SQLException e) { 435 elt.setAttribute(S_RS_CURRENCY, S_NOT_SUPPORTED); 436 } 437 try { 438 elt.setAttribute(S_RS_DEFINITELY_WRITABLE, 439 String.valueOf(rsmd.isDefinitelyWritable(i))); 440 } catch (SQLException e) { 441 elt.setAttribute(S_RS_DEFINITELY_WRITABLE, S_NOT_SUPPORTED); 442 } 443 try { 444 elt.setAttribute(S_RS_NULLABLE, 445 String.valueOf(rsmd.isNullable(i))); 446 } catch (SQLException e) { 447 elt.setAttribute(S_RS_NULLABLE, S_NOT_SUPPORTED); 448 } 449 try { 450 elt.setAttribute(S_RS_READ_ONLY, 451 String.valueOf(rsmd.isReadOnly(i))); 452 } catch (SQLException e) { 453 elt.setAttribute(S_RS_READ_ONLY, S_NOT_SUPPORTED); 454 } 455 try { 456 elt.setAttribute(S_RS_SEARCHABLE, 457 String.valueOf(rsmd.isSearchable(i))); 458 } catch (SQLException e) { 459 elt.setAttribute(S_RS_SEARCHABLE, S_NOT_SUPPORTED); 460 } 461 try { 462 elt.setAttribute(S_RS_SIGNED, 463 String.valueOf(rsmd.isSigned(i))); 464 } catch (SQLException e) { 465 elt.setAttribute(S_RS_SIGNED, S_NOT_SUPPORTED); 466 } 467 try { 468 elt.setAttribute(S_RS_WRITABLE, 469 String.valueOf(rsmd.isWritable(i))); 470 } catch (SQLException e) { 471 elt.setAttribute(S_RS_WRITABLE, S_NOT_SUPPORTED); 472 } 473 elt.setAttribute(S_RS_COLUMN_NO_NULLS, columnNoNulls); 474 elt.setAttribute(S_RS_COLUMN_NULLABLE, columnNullable); 475 elt.setAttribute(S_RS_COLUMN_NULLABLE_UNKNOWN, 476 columnNullableUnknown); 477 ns.addElement(elt); 478 } 479 return ns; 480 } catch (SQLException e) { 481 appendErrorNode(e); 482 } catch (Exception e) { 483 throw new WrappedRuntimeException(e); 484 } 485 finally { 486 if (stmt != null) { 487 try { 488 stmt.close(); 489 } catch (SQLException e) { 490 appendErrorNode(e); 491 } 492 } 493 } 494 return null; 495 } 496 497 540 public static NodeSet getPrimaryKeys(ExpressionContext context, String table) { 541 table = XSLUtil.evaluate(context, table); 542 _errors = null; 543 return getPrimaryKeys(null, null, table, 544 XSLUtil.getContextDocument(context)); 545 } 546 547 570 public static NodeSet getPrimaryKeys(ExpressionContext context, 571 String catalog, 572 String schema, 573 String table) { 574 catalog = XSLUtil.evaluate(context, catalog); 575 schema = XSLUtil.evaluate(context, schema); 576 table = XSLUtil.evaluate(context, table); 577 _errors = null; 578 return getPrimaryKeys(catalog, schema, table, 579 XSLUtil.getContextDocument(context)); 580 } 581 582 594 protected static NodeSet getPrimaryKeys(String catalog, 595 String schema, 596 String table, 597 Document doc) { 598 ResultSet rs = null; 599 600 try { 601 rs = getConnection().getMetaData().getPrimaryKeys(catalog, schema, 602 table); 603 NodeSet ns = new NodeSet(); 604 605 ns.setShouldCacheNodes(true); 606 while (rs.next()) { 607 Element elt = doc.createElement(S_PK_NODE_NAME); 608 609 elt.setAttribute(S_PK_TABLE_CAT, noNull(rs.getString(1))); 610 elt.setAttribute(S_PK_TABLE_SCHEM, noNull(rs.getString(2))); 611 elt.setAttribute(S_PK_TABLE_NAME, noNull(rs.getString(3))); 612 elt.setAttribute(S_PK_COLUMN_NAME, noNull(rs.getString(4))); 613 elt.setAttribute(S_PK_KEY_SEQ, String.valueOf(rs.getShort(5))); 614 elt.setAttribute(S_PK_PK_NAME, noNull(rs.getString(6))); 615 ns.addElement(elt); 616 } 617 return ns; 618 } catch (SQLException e) { 619 appendErrorNode(e); 620 } catch (Exception e) { 621 throw new WrappedRuntimeException(e); 622 } 623 finally { 624 if (rs != null) { 625 try { 626 rs.close(); 627 } catch (SQLException e) { 628 appendErrorNode(e); 629 } 630 } 631 } 632 return null; 633 } 634 635 681 public static NodeSet getImportedKeys(ExpressionContext context, String table) { 682 table = XSLUtil.evaluate(context, table); 683 _errors = null; 684 return getImportedKeys(null, null, table, 685 XSLUtil.getContextDocument(context)); 686 } 687 688 711 public static NodeSet getImportedKeys(ExpressionContext context, 712 String catalog, 713 String schema, 714 String table) { 715 catalog = XSLUtil.evaluate(context, catalog); 716 schema = XSLUtil.evaluate(context, schema); 717 table = XSLUtil.evaluate(context, table); 718 _errors = null; 719 return getImportedKeys(catalog, schema, table, 720 XSLUtil.getContextDocument(context)); 721 } 722 723 735 protected static NodeSet getImportedKeys(String catalog, 736 String schema, 737 String table, 738 Document doc) { 739 ResultSet rs = null; 740 741 try { 742 rs = getConnection().getMetaData().getImportedKeys(catalog, schema, 743 table); 744 NodeSet ns = new NodeSet(); 745 746 ns.setShouldCacheNodes(true); 747 getImportedOrExportedKeys(rs, S_EIK_IK_NODE_NAME, ns, doc); 748 return ns; 749 } catch (SQLException e) { 750 appendErrorNode(e); 751 } catch (Exception e) { 752 throw new WrappedRuntimeException(e); 753 } 754 finally { 755 if (rs != null) { 756 try { 757 rs.close(); 758 } catch (SQLException e) { 759 appendErrorNode(e); 760 } 761 } 762 } 763 return null; 764 } 765 766 812 public static NodeSet getExportedKeys(ExpressionContext context, String table) { 813 table = XSLUtil.evaluate(context, table); 814 _errors = null; 815 return getExportedKeys(null, null, table, 816 XSLUtil.getContextDocument(context)); 817 } 818 819 842 public static NodeSet getExportedKeys(ExpressionContext context, 843 String catalog, 844 String schema, 845 String table) { 846 catalog = XSLUtil.evaluate(context, catalog); 847 schema = XSLUtil.evaluate(context, schema); 848 table = XSLUtil.evaluate(context, table); 849 _errors = null; 850 return getExportedKeys(catalog, schema, table, 851 XSLUtil.getContextDocument(context)); 852 } 853 854 866 protected static NodeSet getExportedKeys(String catalog, 867 String schema, 868 String table, 869 Document doc) { 870 ResultSet rs = null; 871 872 try { 873 rs = getConnection().getMetaData().getExportedKeys(catalog, schema, 874 table); 875 NodeSet ns = new NodeSet(); 876 877 ns.setShouldCacheNodes(true); 878 getImportedOrExportedKeys(rs, S_EIK_EK_NODE_NAME, ns, doc); 879 return ns; 880 } catch (SQLException e) { 881 appendErrorNode(e); 882 } catch (Exception e) { 883 throw new WrappedRuntimeException(e); 884 } 885 finally { 886 if (rs != null) { 887 try { 888 rs.close(); 889 } catch (SQLException e) { 890 appendErrorNode(e); 891 } 892 } 893 } 894 return null; 895 } 896 897 910 protected static void getImportedOrExportedKeys(ResultSet rs, 911 String eltName, 912 NodeSet ns, 913 Document doc) 914 throws Exception { 915 while (rs.next()) { 916 Element elt = doc.createElement(eltName); 917 918 elt.setAttribute(S_EIK_PKTABLE_CAT, noNull(rs.getString(1))); 919 elt.setAttribute(S_EIK_PKTABLE_SCHEM, noNull(rs.getString(2))); 920 elt.setAttribute(S_EIK_PKTABLE_NAME, noNull(rs.getString(3))); 921 elt.setAttribute(S_EIK_PKCOLUMN_NAME, noNull(rs.getString(4))); 922 elt.setAttribute(S_EIK_FKTABLE_CAT, noNull(rs.getString(5))); 923 elt.setAttribute(S_EIK_FKTABLE_SCHEM, noNull(rs.getString(6))); 924 elt.setAttribute(S_EIK_FKTABLE_NAME, noNull(rs.getString(7))); 925 elt.setAttribute(S_EIK_FKCOLUMN_NAME, noNull(rs.getString(8))); 926 elt.setAttribute(S_EIK_KEY_SEQ, String.valueOf(rs.getShort(9))); 927 elt.setAttribute(S_EIK_UPDATE_RULE, String.valueOf(rs.getShort(10))); 928 elt.setAttribute(S_EIK_DELETE_RULE, String.valueOf(rs.getShort(11))); 929 elt.setAttribute(S_EIK_FK_NAME, noNull(rs.getString(12))); 930 elt.setAttribute(S_EIK_PK_NAME, noNull(rs.getString(13))); 931 elt.setAttribute(S_EIK_DEFERRABILITY, 932 String.valueOf(rs.getShort(14))); 933 ns.addElement(elt); 934 } 935 } 936 937 981 public static NodeSet getIndexInfo(ExpressionContext context, String table) { 982 table = XSLUtil.evaluate(context, table); 983 _errors = null; 984 return getIndexInfo(null, null, table, 985 XSLUtil.getContextDocument(context)); 986 } 987 988 1011 public static NodeSet getIndexInfo(ExpressionContext context, 1012 String catalog, 1013 String schema, 1014 String table) { 1015 catalog = XSLUtil.evaluate(context, catalog); 1016 schema = XSLUtil.evaluate(context, schema); 1017 table = XSLUtil.evaluate(context, table); 1018 _errors = null; 1019 return getIndexInfo(catalog, schema, table, 1020 XSLUtil.getContextDocument(context)); 1021 } 1022 1023 1035 protected static NodeSet getIndexInfo(String catalog, 1036 String schema, 1037 String table, 1038 Document doc) { 1039 ResultSet rs = null; 1040 1041 try { 1042 rs = getConnection().getMetaData().getIndexInfo(catalog, schema, 1043 table, false, false); 1044 NodeSet ns = new NodeSet(); 1045 1046 ns.setShouldCacheNodes(true); 1047 while (rs.next()) { 1048 Element elt = doc.createElement(S_II_NODE_NAME); 1049 1050 elt.setAttribute(S_II_TABLE_CAT, noNull(rs.getString(1))); 1051 elt.setAttribute(S_II_TABLE_SCHEM, noNull(rs.getString(2))); 1052 elt.setAttribute(S_II_TABLE_NAME, noNull(rs.getString(3))); 1053 elt.setAttribute(S_II_NON_UNIQUE, 1054 String.valueOf(rs.getBoolean(4))); 1055 elt.setAttribute(S_II_INDEX_QUALIFIER, noNull(rs.getString(5))); 1056 elt.setAttribute(S_II_INDEX_NAME, noNull(rs.getString(6))); 1057 elt.setAttribute(S_II_TYPE, String.valueOf(rs.getShort(7))); 1058 elt.setAttribute(S_II_ORDINAL_POSITION, 1059 String.valueOf(rs.getShort(8))); 1060 elt.setAttribute(S_II_COLUMN_NAME, noNull(rs.getString(9))); 1061 elt.setAttribute(S_II_ASC_OR_DESC, noNull(rs.getString(10))); 1062 elt.setAttribute(S_II_CARDINALITY, noNull(rs.getString(11))); 1063 elt.setAttribute(S_II_PAGES, noNull(rs.getString(12))); 1064 elt.setAttribute(S_II_FILTER_CONDITION, noNull(rs.getString(13))); 1065 ns.addElement(elt); 1066 } 1067 return ns; 1068 } catch (SQLException e) { 1069 appendErrorNode(e); 1070 } catch (Exception e) { 1071 throw new WrappedRuntimeException(e); 1072 } 1073 finally { 1074 if (rs != null) { 1075 try { 1076 rs.close(); 1077 } catch (SQLException e) { 1078 appendErrorNode(e); 1079 } 1080 } 1081 } 1082 return null; 1083 } 1084 1085 1091 protected static void appendErrorNode(Exception e) { 1092 if (e == null) { 1093 return; 1094 } 1095 int errCode = 0; 1096 1097 if (e instanceof SQLException ) { 1098 errCode = ((SQLException ) e).getErrorCode(); 1099 } 1100 Document doc = null; 1101 1102 if (_errors == null) { 1103 _errors = new NodeSet(); 1104 _errors.setShouldCacheNodes(true); 1105 doc = DOMUtil.newDocument(); 1106 } else { 1107 doc = _errors.getRoot() != null 1108 ? _errors.getRoot().getOwnerDocument() 1109 : DOMUtil.newDocument(); 1110 } 1111 try { 1112 Element elt = doc.createElement(S_EXCEPTION_NODE_NAME); 1113 1114 elt.setAttribute(S_EXCEPTION_CLASS_NAME, e.getClass().getName()); 1115 elt.setAttribute(S_EXCEPTION_CODE, String.valueOf(errCode)); 1116 elt.appendChild(doc.createTextNode(e.getMessage())); 1117 _errors.addElement(elt); 1118 } catch (Exception f) { 1119 throw new WrappedRuntimeException(f); 1120 } 1121 } 1122 1123 1129 protected static String noNull(String s) { 1130 return (s == null) ? S_NULL : s; 1131 } 1132} 1133
| Popular Tags
|