1 package org.ejen.ext.db; 22 23 import org.ejen.util.XSLUtil; 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.Node ; 27 import org.apache.xalan.extensions.ExpressionContext; 28 import org.apache.xpath.NodeSet; 29 import org.apache.xml.utils.WrappedRuntimeException; 30 31 37 public abstract class TableMetaDataNodeBuilder extends MetaDataNodeBuilder { 38 public static final String S_TABLE_METADATA_NODE_NAME = "metadata"; 39 40 124 public static Node getTableMetaData(ExpressionContext context, String table) { 125 table = XSLUtil.evaluate(context, table); 126 _errors = null; 127 return getTableMetaData(null, null, table, 128 XSLUtil.getContextDocument(context)); 129 } 130 131 153 public static Node getTableMetaData(ExpressionContext context, 154 String catalog, 155 String schema, 156 String table) { 157 catalog = XSLUtil.evaluate(context, catalog); 158 schema = XSLUtil.evaluate(context, schema); 159 table = XSLUtil.evaluate(context, table); 160 _errors = null; 161 return getTableMetaData(catalog, schema, table, 162 XSLUtil.getContextDocument(context)); 163 } 164 165 179 protected static Node getTableMetaData(String catalog, 180 String schema, 181 String table, 182 Document doc) { 183 NodeSet pks = getPrimaryKeys(catalog, schema, table, doc); 184 NodeSet ii = getIndexInfo(catalog, schema, table, doc); 185 NodeSet cls = getResultSetMetaData(table, "*", S_RS_COLUMN_NODE_NAME, 186 doc); 187 188 if (pks == null || ii == null || cls == null) { 189 return null; 190 } 191 try { 192 Element root = doc.createElement(S_TABLE_METADATA_NODE_NAME); 193 194 for (int i = 0; i < pks.getLength(); i++) { 195 root.appendChild(pks.item(i)); 196 } 197 for (int i = 0; i < ii.getLength(); i++) { 198 root.appendChild(ii.item(i)); 199 } 200 for (int i = 0; i < cls.getLength(); i++) { 201 root.appendChild(cls.item(i)); 202 } 203 return root; 204 } catch (Exception e) { 205 throw new WrappedRuntimeException(e); 206 } 207 } 208 } 209 | Popular Tags |