1 package net.sf.saxon.tinytree; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.event.Receiver; 4 import net.sf.saxon.om.*; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.type.Type; 7 8 import java.util.ArrayList ; 9 import java.util.HashMap ; 10 import java.util.List ; 11 12 13 17 18 public final class TinyDocumentImpl extends TinyParentNodeImpl 19 implements DocumentInfo { 20 21 private HashMap idTable = null; 22 private HashMap elementList = null; 23 private HashMap entityTable = null; 24 25 26 public TinyDocumentImpl(TinyTree tree) { 27 this.tree = tree; 28 } 29 30 33 34 public TinyTree getTree() { 35 return tree; 36 } 37 38 41 42 public void setConfiguration(Configuration config) { 43 if (config != tree.getConfiguration()) { 44 throw new IllegalArgumentException ( 45 "Configuration of document differs from that of the supporting TinyTree"); 46 } 47 } 48 49 52 53 public Configuration getConfiguration() { 54 return tree.getConfiguration(); 55 } 56 57 60 61 public void setSystemId(String uri) { 62 tree.setSystemId(nodeNr, uri); 63 } 64 65 68 69 public String getSystemId() { 70 return tree.getSystemId(nodeNr); 71 } 72 73 77 78 public String getBaseURI() { 79 return getSystemId(); 80 } 81 82 86 87 public int getLineNumber() { 88 return 0; 89 } 90 91 95 96 public final int getNodeKind() { 97 return Type.DOCUMENT; 98 } 99 100 104 105 public NodeInfo getParent() { 106 return null; 107 } 108 109 113 114 public NodeInfo getRoot() { 115 return this; 116 } 117 118 123 124 public DocumentInfo getDocumentRoot() { 125 return this; 126 } 127 128 132 133 public String generateId() { 134 return "d"+getDocumentNumber(); 135 } 136 137 142 143 AxisIterator getAllElements(int fingerprint) { 144 Integer key = new Integer (fingerprint); 145 if (elementList==null) { 146 elementList = new HashMap (20); 147 } 148 List list = (List )elementList.get(key); 149 if (list==null) { 150 list = getElementList(fingerprint); 151 elementList.put(key, list); 152 } 153 return new ListIterator(list); 154 } 155 156 161 162 List getElementList(int fingerprint) { 163 List list = new ArrayList (tree.getNumberOfNodes()/20); 164 int i = nodeNr+1; 165 while (tree.depth[i] != 0) { 166 if (tree.nodeKind[i]==Type.ELEMENT && 167 (tree.nameCode[i] & 0xfffff) == fingerprint) { 168 list.add(tree.getNode(i)); 169 } 170 i++; 171 } 172 return list; 173 } 174 175 181 182 void registerID(NodeInfo e, String id) { 183 if (idTable==null) { 184 idTable = new HashMap (256); 185 } 186 187 NodeInfo old = (NodeInfo)idTable.get(id); 189 if (old==null) { 190 idTable.put(id, e); 191 } 192 193 } 194 195 201 202 public NodeInfo selectID(String id) { 203 if (idTable==null) return null; return (NodeInfo)idTable.get(id); 205 } 206 207 211 212 void setUnparsedEntity(String name, String uri, String publicId) { 213 if (entityTable==null) { 214 entityTable = new HashMap (20); 215 } 216 String [] ids = new String [2]; 217 ids[0] = uri; 218 ids[1] = publicId; 219 entityTable.put(name, ids); 220 } 221 222 229 230 public String [] getUnparsedEntity(String name) { 231 if (entityTable==null) { 232 return null; 233 } 234 return (String [])entityTable.get(name); 235 } 236 237 240 241 public void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId) throws XPathException { 242 243 out.startDocument(0); 244 245 247 AxisIterator children = iterateAxis(Axis.CHILD); 248 while (true) { 249 NodeInfo n = (NodeInfo)children.next(); 250 if (n == null) { 251 break; 252 } 253 n.copy(out, whichNamespaces, copyAnnotations, locationId); 254 } 255 256 out.endDocument(); 257 } 258 259 public void showSize() { 260 tree.showSize(); 261 } 262 263 } 264 265 | Popular Tags |