View Javadoc
1 /* 2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG) 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 package com.teamkonzept.dom4jb.saxon; 19 20 import javax.xml.transform.TransformerException; 21 22 import com.icl.saxon.om.AxisEnumeration; 23 import com.icl.saxon.om.DocumentInfo; 24 import com.icl.saxon.om.NodeInfo; 25 import com.icl.saxon.output.Outputter; 26 import com.icl.saxon.pattern.NodeTest; 27 28 public class Namespace implements NodeInfo { 29 30 private static final int LOW_20_MASK = 0xfffff; 31 final String prefix; 32 final String namespaceURI; 33 final NodeInfo parent; 34 35 public Namespace( 36 final String prefix, 37 final String namespaceURI, 38 final NodeInfo parent) { 39 this.prefix = prefix == null ? "" : prefix; 40 this.namespaceURI = namespaceURI == null ? "" : namespaceURI; 41 this.parent = parent; 42 } 43 44 /*** 45 * Get the System ID for the node. 46 * @return the System Identifier of the entity in the source document 47 * containing the node, or null if not known. Note this is not the same as 48 * the base URI: the base URI can be modified by xml:base, but the 49 * system ID cannot. 50 */ 51 public String getSystemId() { 52 return parent.getSystemId(); 53 } 54 55 public void setSystemId(final String uri) { 56 parent.setSystemId(uri); 57 } 58 59 /*** 60 * Get the Base URI for the node, that is, the URI used for resolving 61 * a relative URI contained in the node. This will be the same as the 62 * System ID unless xml:base has been used. 63 */ 64 public String getBaseURI() { 65 return getSystemId(); 66 } 67 68 public boolean hasChildNodes() { 69 return false; 70 } 71 72 public String getDisplayName() { 73 return prefix; // ???? 74 } 75 76 public String getStringValue() { 77 return namespaceURI; 78 } 79 80 public String getLocalName() { 81 return prefix; // ???? 82 } 83 84 public String getPrefix() { 85 return ""; 86 } 87 88 public short getNodeType() { 89 return NodeInfo.NAMESPACE; 90 } 91 92 /*** 93 * Get line number 94 * @return the line number of the node in its original source document; 95 * or -1 if not available 96 */ 97 public int getLineNumber() { 98 return -1; 99 } 100 101 /*** 102 * Get name code. The name code is a coded form of the node name: two nodes 103 * with the same name code have the same namespace URI, the same local name, 104 * and the same prefix. By masking the name code with &0xfffff, you get a 105 * fingerprint: two nodes with the same fingerprint have the same local name 106 * and namespace URI. 107 * @see com.icl.saxon.om.NamePool#allocate allocate 108 */ 109 public int getNameCode() { 110 return -1; 111 } 112 113 /*** 114 * Get fingerprint. The fingerprint is a coded form of the expanded name 115 * of the node: two nodes 116 * with the same name code have the same namespace URI and the same 117 * local name. A fingerprint of -1 should be returned for a node with 118 * no name. 119 */ 120 public int getFingerprint() { 121 return getNameCode() & LOW_20_MASK; 122 } 123 124 public void outputNamespaceNodes(final Outputter outputter, 125 final boolean b) 126 throws TransformerException { 127 } 128 129 public void copy(Outputter outputter) throws TransformerException { 130 throw new IllegalArgumentException("Copying Namespace node!"); 131 } 132 133 public String generateId() { 134 final StringBuffer buf = new StringBuffer("j"); 135 buf.append(hashCode()); 136 return buf.toString(); 137 } 138 139 public String getAttributeValue(final int i) { 140 return null; 141 } 142 143 public String getAttributeValue(String s, String s1) { 144 return null; 145 } 146 147 /*** 148 * Get the URI part of the name of this node. This is the URI corresponding 149 * to the prefix, or the URI of the default namespace if appropriate. 150 * @return The URI of the namespace of this node. For an unnamed node, 151 * return null. For a node with an empty prefix, return an empty string. 152 */ 153 public String getURI() { 154 return this.namespaceURI; 155 } 156 157 /*** 158 * Get the NodeInfo object representing the parent of this node 159 */ 160 public NodeInfo getParent() { 161 return parent; 162 } 163 164 /*** 165 * Get the root (document) node 166 * @return the DocumentInfo representing the containing document 167 */ 168 public DocumentInfo getDocumentRoot() { 169 return parent.getDocumentRoot(); 170 } 171 172 /*** 173 * Copy the string-value of this node to a given outputter 174 */ 175 public void copyStringValue(final Outputter out) 176 throws TransformerException { 177 out.writeContent(getStringValue()); 178 } 179 180 /*** 181 * Return an enumeration over the nodes reached by the given axis from 182 * this node 183 * @param nodeType the type(s) of node to be included, 184 * e.g. NodeInfo.ELEMENT, NodeInfo.TEXT. 185 * The value NodeInfo.NODE means include any type of node. 186 * @param nodeTest A pattern to be matched by the returned nodes 187 * @return a NodeEnumeration that scans the nodes reached by 188 * the axis in turn. 189 */ 190 public AxisEnumeration getEnumeration( 191 final byte axisNumber, 192 final NodeTest nodeTest) { 193 // TODO !!!!!!!!!!!!!!!! 194 return null; 195 } 196 197 /*** 198 * Determine the relative position of this node and another node, in 199 * document order. The other node will always be in the same document. 200 * @param other The other node, whose position is to be compared with this 201 * node 202 * @return -1 if this node precedes the other node, +1 if it follows the 203 * other node, or 0 if they are the same node. (In this case, 204 * isSameNode() will always return true, and the two nodes will produce 205 * the same result for generateId()) 206 */ 207 208 public int compareOrder(final NodeInfo other) { 209 return -1; 210 /* 211 NodeWrapper ow = (NodeWrapper)other; 212 213 // are they the same node? 214 if (this.isSameNode(other)) { 215 return 0; 216 } 217 218 // are they siblings (common case) 219 if (this.getParent().isSameNode(other.getParent())) { 220 return this.index - ow.index; 221 } 222 223 // find the depths of both nodes in the tree 224 225 int depth1 = 0; 226 int depth2 = 0; 227 NodeInfo p1 = this; 228 NodeInfo p2 = other; 229 while (p1 != null) { 230 depth1++; 231 p1 = p1.getParent(); 232 } 233 while (p2 != null) { 234 depth2++; 235 p2 = p2.getParent(); 236 } 237 238 // move up one branch of the tree so we have two nodes 239 // on the same level 240 241 p1 = this; 242 while (depth1>depth2) { 243 p1 = p1.getParent(); 244 depth1--; 245 } 246 247 p2 = ow; 248 while (depth2>depth1) { 249 p2 = p2.getParent(); 250 depth2--; 251 } 252 253 // now move up both branches in sync until we find a common parent 254 while (true) { 255 NodeInfo par1 = p1.getParent(); 256 NodeInfo par2 = p2.getParent(); 257 if (par1==null || par2==null) { 258 throw new NullPointerException( 259 "DOM tree compare - internal error"); 260 } 261 if (par1.isSameNode(par2)) { 262 return ((NodeWrapper)p1).index - ((NodeWrapper)p2).index; 263 } 264 p1 = par1; 265 p2 = par2; 266 } 267 */ 268 } 269 270 /*** 271 * Determine whether this is the same node as another node. <br /> 272 * Note: a.isSameNode(b) if and only if generateId(a)==generateId(b) 273 * @return true if this Node object and the supplied Node object represent 274 * the same node in the tree. 275 */ 276 public boolean isSameNode(final NodeInfo other) { 277 if (this == other) { 278 return true; 279 } 280 if (other == null || !(other instanceof Namespace)) { 281 // %REVIEW, hier sollte man vielleicht ein eiheitliches 282 // interface wählen 283 return false; 284 } 285 return equals(other); // this test doesn't work for text nodes 286 } 287 }

This page was automatically generated by Maven