1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.dom; 21 22 import com.sun.org.apache.xalan.internal.xsltc.DOM; 23 import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM; 24 import com.sun.org.apache.xalan.internal.xsltc.StripFilter; 25 import com.sun.org.apache.xalan.internal.xsltc.TransletException; 26 import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable; 27 import com.sun.org.apache.xml.internal.dtm.DTM; 28 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; 29 import com.sun.org.apache.xml.internal.serializer.SerializationHandler; 30 31 import org.w3c.dom.Node ; 32 import org.w3c.dom.NodeList ; 33 34 38 public final class DOMAdapter implements DOM { 39 40 private DOMEnhancedForDTM _enhancedDOM; 42 43 private DOM _dom; 44 45 private String [] _namesArray; 46 private String [] _urisArray; 47 private int[] _typesArray; 48 private String [] _namespaceArray; 49 50 private short[] _mapping = null; 52 private int[] _reverse = null; 53 private short[] _NSmapping = null; 54 private short[] _NSreverse = null; 55 56 private StripFilter _filter = null; 57 58 private int _multiDOMMask; 59 60 public DOMAdapter(DOM dom, 61 String [] namesArray, 62 String [] urisArray, 63 int[] typesArray, 64 String [] namespaceArray) { 65 if (dom instanceof DOMEnhancedForDTM){ 66 _enhancedDOM = (DOMEnhancedForDTM) dom; 67 } 68 69 _dom = dom; 70 _namesArray = namesArray; 71 _urisArray = urisArray; 72 _typesArray = typesArray; 73 _namespaceArray = namespaceArray; 74 } 75 76 public void setupMapping(String [] names, String [] urisArray, 77 int[] typesArray, String [] namespaces) { 78 _namesArray = names; 79 _urisArray = urisArray; 80 _typesArray = typesArray; 81 _namespaceArray = namespaces; 82 } 83 84 public String [] getNamesArray() { 85 return _namesArray; 86 } 87 88 public String [] getUrisArray() { 89 return _urisArray; 90 } 91 92 public int[] getTypesArray() { 93 return _typesArray; 94 } 95 96 public String [] getNamespaceArray() { 97 return _namespaceArray; 98 } 99 100 public DOM getDOMImpl() { 101 return _dom; 102 } 103 104 private short[] getMapping() { 105 if (_mapping == null) { 106 if (_enhancedDOM != null) { 107 _mapping = _enhancedDOM.getMapping(_namesArray, _urisArray, 108 _typesArray); 109 } 110 } 111 return _mapping; 112 } 113 114 private int[] getReverse() { 115 if (_reverse == null) { 116 if (_enhancedDOM != null) { 117 _reverse = _enhancedDOM.getReverseMapping(_namesArray, 118 _urisArray, 119 _typesArray); 120 } 121 } 122 return _reverse; 123 } 124 125 private short[] getNSMapping() { 126 if (_NSmapping == null) { 127 if (_enhancedDOM != null) { 128 _NSmapping = _enhancedDOM.getNamespaceMapping(_namespaceArray); 129 } 130 } 131 return _NSmapping; 132 } 133 134 private short[] getNSReverse() { 135 if (_NSreverse == null) { 136 if (_enhancedDOM != null) { 137 _NSreverse = _enhancedDOM 138 .getReverseNamespaceMapping(_namespaceArray); 139 } 140 } 141 return _NSreverse; 142 } 143 144 147 public DTMAxisIterator getIterator() { 148 return _dom.getIterator(); 149 } 150 151 public String getStringValue() { 152 return _dom.getStringValue(); 153 } 154 155 public DTMAxisIterator getChildren(final int node) { 156 if (_enhancedDOM != null) { 157 return _enhancedDOM.getChildren(node); 158 } 159 else { 160 DTMAxisIterator iterator = _dom.getChildren(node); 161 return iterator.setStartNode(node); 162 } 163 } 164 165 public void setFilter(StripFilter filter) { 166 _filter = filter; 167 } 168 169 public DTMAxisIterator getTypedChildren(final int type) { 170 final int[] reverse = getReverse(); 171 172 if (_enhancedDOM != null) { 173 return _enhancedDOM.getTypedChildren(reverse[type]); 174 } 175 else { 176 return _dom.getTypedChildren(type); 177 } 178 } 179 180 public DTMAxisIterator getNamespaceAxisIterator(final int axis, 181 final int ns) { 182 return _dom.getNamespaceAxisIterator(axis, getNSReverse()[ns]); 183 } 184 185 public DTMAxisIterator getAxisIterator(final int axis) { 186 if (_enhancedDOM != null) { 187 return _enhancedDOM.getAxisIterator(axis); 188 } 189 else { 190 return _dom.getAxisIterator(axis); 191 } 192 } 193 194 public DTMAxisIterator getTypedAxisIterator(final int axis, 195 final int type) { 196 final int[] reverse = getReverse(); 197 if (_enhancedDOM != null) { 198 return _enhancedDOM.getTypedAxisIterator(axis, reverse[type]); 199 } else { 200 return _dom.getTypedAxisIterator(axis, type); 201 } 202 } 203 204 public int getMultiDOMMask() { 205 return _multiDOMMask; 206 } 207 208 public void setMultiDOMMask(int mask) { 209 _multiDOMMask = mask; 210 } 211 212 public DTMAxisIterator getNthDescendant(int type, int n, 213 boolean includeself) { 214 return _dom.getNthDescendant(getReverse()[type], n, includeself); 215 } 216 217 public DTMAxisIterator getNodeValueIterator(DTMAxisIterator iterator, 218 int type, String value, 219 boolean op) { 220 return _dom.getNodeValueIterator(iterator, type, value, op); 221 } 222 223 public DTMAxisIterator orderNodes(DTMAxisIterator source, int node) { 224 return _dom.orderNodes(source, node); 225 } 226 227 public int getExpandedTypeID(final int node) { 228 if (_enhancedDOM != null) { 229 return getMapping()[_enhancedDOM.getExpandedTypeID2(node)]; 230 } 231 else { 232 return getMapping()[_dom.getExpandedTypeID(node)]; 233 } 234 } 235 236 public int getNamespaceType(final int node) { 237 return getNSMapping()[_dom.getNSType(node)]; 238 } 239 240 public int getNSType(int node) { 241 return _dom.getNSType(node); 242 } 243 244 public int getParent(final int node) { 245 return _dom.getParent(node); 246 } 247 248 public int getAttributeNode(final int type, final int element) { 249 return _dom.getAttributeNode(getReverse()[type], element); 250 } 251 252 public String getNodeName(final int node) { 253 if (node == DTM.NULL) { 254 return ""; 255 } 256 return _dom.getNodeName(node); 257 } 258 259 public String getNodeNameX(final int node) 260 { 261 if (node == DTM.NULL) { 262 return ""; 263 } 264 return _dom.getNodeNameX(node); 265 } 266 267 public String getNamespaceName(final int node) 268 { 269 if (node == DTM.NULL) { 270 return ""; 271 } 272 return _dom.getNamespaceName(node); 273 } 274 275 public String getStringValueX(final int node) 276 { 277 if (_enhancedDOM != null) { 278 return _enhancedDOM.getStringValueX(node); 279 } 280 else { 281 if (node == DTM.NULL) { 282 return ""; 283 } 284 return _dom.getStringValueX(node); 285 } 286 } 287 288 public void copy(final int node, SerializationHandler handler) 289 throws TransletException 290 { 291 _dom.copy(node, handler); 292 } 293 294 public void copy(DTMAxisIterator nodes,SerializationHandler handler) 295 throws TransletException 296 { 297 _dom.copy(nodes, handler); 298 } 299 300 public String shallowCopy(final int node, SerializationHandler handler) 301 throws TransletException 302 { 303 if (_enhancedDOM != null) { 304 return _enhancedDOM.shallowCopy(node, handler); 305 } 306 else { 307 return _dom.shallowCopy(node, handler); 308 } 309 } 310 311 public boolean lessThan(final int node1, final int node2) 312 { 313 return _dom.lessThan(node1, node2); 314 } 315 316 public void characters(final int textNode, SerializationHandler handler) 317 throws TransletException 318 { 319 if (_enhancedDOM != null) { 320 _enhancedDOM.characters(textNode, handler); 321 } 322 else { 323 _dom.characters(textNode, handler); 324 } 325 } 326 327 public Node makeNode(int index) 328 { 329 return _dom.makeNode(index); 330 } 331 332 public Node makeNode(DTMAxisIterator iter) 333 { 334 return _dom.makeNode(iter); 335 } 336 337 public NodeList makeNodeList(int index) 338 { 339 return _dom.makeNodeList(index); 340 } 341 342 public NodeList makeNodeList(DTMAxisIterator iter) 343 { 344 return _dom.makeNodeList(iter); 345 } 346 347 public String getLanguage(int node) 348 { 349 return _dom.getLanguage(node); 350 } 351 352 public int getSize() 353 { 354 return _dom.getSize(); 355 } 356 357 public void setDocumentURI(String uri) 358 { 359 if (_enhancedDOM != null) { 360 _enhancedDOM.setDocumentURI(uri); 361 } 362 } 363 364 public String getDocumentURI() 365 { 366 if (_enhancedDOM != null) { 367 return _enhancedDOM.getDocumentURI(); 368 } 369 else { 370 return ""; 371 } 372 } 373 374 public String getDocumentURI(int node) 375 { 376 return _dom.getDocumentURI(node); 377 } 378 379 public int getDocument() 380 { 381 return _dom.getDocument(); 382 } 383 384 public boolean isElement(final int node) 385 { 386 return(_dom.isElement(node)); 387 } 388 389 public boolean isAttribute(final int node) 390 { 391 return(_dom.isAttribute(node)); 392 } 393 394 public int getNodeIdent(int nodeHandle) 395 { 396 return _dom.getNodeIdent(nodeHandle); 397 } 398 399 public int getNodeHandle(int nodeId) 400 { 401 return _dom.getNodeHandle(nodeId); 402 } 403 404 407 public DOM getResultTreeFrag(int initSize, int rtfType) 408 { 409 if (_enhancedDOM != null) { 410 return _enhancedDOM.getResultTreeFrag(initSize, rtfType); 411 } 412 else { 413 return _dom.getResultTreeFrag(initSize, rtfType); 414 } 415 } 416 417 420 public DOM getResultTreeFrag(int initSize, int rtfType, 421 boolean addToManager) 422 { 423 if (_enhancedDOM != null) { 424 return _enhancedDOM.getResultTreeFrag(initSize, rtfType, 425 addToManager); 426 } 427 else { 428 return _dom.getResultTreeFrag(initSize, rtfType, addToManager); 429 } 430 } 431 432 433 436 public SerializationHandler getOutputDomBuilder() 437 { 438 return _dom.getOutputDomBuilder(); 439 } 440 441 public String lookupNamespace(int node, String prefix) 442 throws TransletException 443 { 444 return _dom.lookupNamespace(node, prefix); 445 } 446 447 public String getUnparsedEntityURI(String entity) { 448 return _dom.getUnparsedEntityURI(entity); 449 } 450 451 public Hashtable getElementsWithIDs() { 452 return _dom.getElementsWithIDs(); 453 } 454 } 455 | Popular Tags |