1 package net.sf.saxon.tree; 2 import net.sf.saxon.event.LocationCopier; 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 14 15 16 public class ElementImpl extends ParentNodeImpl { 17 18 private static final AttributeCollectionImpl emptyAtts = new AttributeCollectionImpl(null); 19 20 protected int nameCode; 21 protected DocumentImpl root; 22 23 26 27 public ElementImpl() {} 28 29 32 33 public void setNameCode(int nameCode) { 34 this.nameCode = nameCode; 35 } 36 37 46 47 public void initialise(int nameCode, AttributeCollectionImpl atts, NodeInfo parent, 48 String baseURI, int lineNumber, int sequenceNumber) { 49 this.nameCode = nameCode; 50 this.parent = (ParentNodeImpl)parent; 51 this.sequence = sequenceNumber; 52 this.root = (DocumentImpl)parent.getDocumentRoot(); 53 root.setLineNumber(sequenceNumber, lineNumber); 54 root.setSystemId(sequenceNumber, baseURI); 55 } 56 57 62 63 public void setSystemId(String uri) { 64 root.setSystemId(sequence, uri); 65 } 66 67 70 71 public NodeInfo getRoot() { 72 return root; 73 } 74 75 78 79 public DocumentInfo getDocumentRoot() { 80 return root; 81 } 82 83 86 87 public final String getSystemId() { 88 return ((DocumentImpl)getDocumentRoot()).getSystemId(sequence); 89 } 90 91 95 96 public String getBaseURI() { 97 return Navigator.getBaseURI(this); 98 } 99 100 103 104 public void setLineNumber(int line) { 105 ((DocumentImpl)getDocumentRoot()).setLineNumber(sequence, line); 106 } 107 108 111 112 public int getLineNumber() { 113 return ((DocumentImpl)getDocumentRoot()).getLineNumber(sequence); 114 } 115 116 117 120 121 public int getNameCode() { 122 return nameCode; 123 } 124 125 129 130 public String generateId() { 131 return getDocumentRoot().generateId() + 'e' + sequence; 132 } 133 134 138 139 public void sendNamespaceDeclarations(Receiver out, boolean includeAncestors) throws XPathException { 140 141 144 if (includeAncestors) { 145 if (!(parent instanceof DocumentInfo)) { 146 parent.sendNamespaceDeclarations(out, true); 147 } 148 } 149 } 150 151 166 167 public int[] getDeclaredNamespaces(int[] buffer) { 168 return EMPTY_NAMESPACE_LIST; 169 } 170 171 172 176 177 public final int getNodeKind() { 178 return Type.ELEMENT; 179 } 180 181 187 188 public AttributeCollection getAttributeList() { 189 return emptyAtts; 190 } 191 192 201 202 206 207 213 214 public void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId) throws XPathException { 215 216 int typeCode = (copyAnnotations ? getTypeAnnotation() : -1); 217 if (locationId == 0 && out instanceof LocationCopier) { 218 out.setSystemId(getSystemId()); 219 ((LocationCopier)out).setLineNumber(getLineNumber()); 220 } 221 out.startElement(getNameCode(), typeCode, locationId, 0); 222 223 225 if (whichNamespaces != NO_NAMESPACES) { 226 sendNamespaceDeclarations(out, whichNamespaces==ALL_NAMESPACES); 227 } 228 229 231 int childNamespaces = (whichNamespaces==NO_NAMESPACES ? NO_NAMESPACES : LOCAL_NAMESPACES); 232 NodeImpl next = (NodeImpl)getFirstChild(); 233 while (next!=null) { 234 next.copy(out, childNamespaces, copyAnnotations, locationId); 235 next = (NodeImpl)next.getNextSibling(); 236 } 237 238 out.endElement(); 239 } 240 241 } 242 243 | Popular Tags |