1 package net.sf.saxon.dom; 2 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.om.DocumentInfo; 5 import net.sf.saxon.om.NamePool; 6 import net.sf.saxon.om.NodeInfo; 7 import net.sf.saxon.type.Type; 8 import org.w3c.dom.Document ; 9 import org.w3c.dom.Node ; 10 11 import java.lang.reflect.Method ; 12 13 16 17 public class DocumentWrapper extends NodeWrapper implements DocumentInfo { 18 19 protected Configuration config; 20 protected String baseURI; 21 protected int documentNumber; 22 protected boolean level3 = false; 23 24 public DocumentWrapper(Document doc, String baseURI, Configuration config) { 25 super(doc, null, 0); 26 node = doc; 27 nodeKind = Type.DOCUMENT; 28 this.baseURI = baseURI; 29 docWrapper = this; 30 31 Method [] methods = doc.getClass().getMethods(); 33 for (int i=0; i<methods.length; i++) { 34 if (methods[i].getName().equals("isSameNode")) { 35 level3 = true; 36 break; 37 } 38 } 39 40 setConfiguration(config); 41 } 42 43 51 52 public NodeWrapper wrap(Node node) { 53 if (node == this.node) { 54 return this; 55 } 56 if (node.getOwnerDocument() == this.node) { 57 return makeWrapper(node, this); 58 } else { 59 throw new IllegalArgumentException ( 60 "DocumentWrapper#wrap: supplied node does not belong to the wrapped DOM document"); 61 } 62 } 63 64 67 68 public void setConfiguration(Configuration config) { 69 this.config = config; 70 documentNumber = config.getDocumentNumberAllocator().allocateDocumentNumber(); 71 } 72 73 76 77 public Configuration getConfiguration() { 78 return config; 79 } 80 81 84 85 public NamePool getNamePool() { 86 return config.getNamePool(); 87 } 88 89 92 93 public int getDocumentNumber() { 94 return documentNumber; 95 } 96 97 106 107 public NodeInfo selectID(String id) { 108 Node el = ((Document )node).getElementById(id); 109 if (el == null) { 110 return null; 111 } 112 return wrap(el); 113 } 114 115 122 123 public boolean isSameNodeInfo(NodeInfo other) { 124 if (!(other instanceof DocumentWrapper)) { 125 return false; 126 } 127 return node == ((DocumentWrapper)other).node; 128 } 129 130 136 137 public String [] getUnparsedEntity(String name) { 138 return null; 139 } 140 141 142 } 143 144 | Popular Tags |