1 package net.sf.saxon.om; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.Err; 4 import net.sf.saxon.event.Receiver; 5 import net.sf.saxon.pattern.NodeTest; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.type.SchemaType; 8 import net.sf.saxon.type.Type; 9 import net.sf.saxon.value.UntypedAtomicValue; 10 import net.sf.saxon.value.Value; 11 12 18 19 public final class Orphan implements NodeInfo, FingerprintedNode { 20 21 private short kind; 22 private int nameCode = -1; 23 private CharSequence stringValue; 24 private int typeAnnotation = -1; 25 private Configuration config; 26 private String systemId; 27 28 public Orphan(Configuration config) { 29 this.config = config; 30 } 31 32 public void setNodeKind(short kind) { 33 this.kind = kind; 34 } 35 36 public void setNameCode(int nameCode) { 37 this.nameCode = nameCode; 38 } 39 40 public void setStringValue(CharSequence stringValue) { 41 this.stringValue = stringValue; 42 } 43 44 public void setTypeAnnotation(int typeAnnotation) { 45 this.typeAnnotation = typeAnnotation; 46 } 47 48 public void setSystemId(String systemId) { 49 this.systemId = systemId; 50 } 51 52 56 57 public int getNodeKind() { 58 return kind; 59 } 60 61 64 65 public SequenceIterator getTypedValue() throws XPathException { 66 if (typeAnnotation == -1) { 67 return SingletonIterator.makeIterator( 68 new UntypedAtomicValue(stringValue)); 69 } else { 70 SchemaType stype = config.getSchemaType(typeAnnotation); 71 if (stype == null) { 72 String typeName = config.getNamePool().getDisplayName(typeAnnotation); 73 throw new IllegalStateException ("Unknown type annotation " + 74 Err.wrap(typeName) + " in standalone node"); 75 } else { 76 return stype.getTypedValue(this); 77 } 78 } 79 } 80 81 91 92 public Value atomize() throws XPathException { 93 if (typeAnnotation == -1) { 94 return new UntypedAtomicValue(stringValue); 95 } else { 96 SchemaType stype = config.getSchemaType(typeAnnotation); 97 if (stype == null) { 98 String typeName = config.getNamePool().getDisplayName(typeAnnotation); 99 throw new IllegalStateException ("Unknown type annotation " + 100 Err.wrap(typeName) + " in standalone node"); 101 } else { 102 return stype.atomize(this); 103 } 104 } 105 } 106 107 110 111 public Configuration getConfiguration() { 112 return config; 113 } 114 115 118 119 public NamePool getNamePool() { 120 return config.getNamePool(); 121 } 122 123 126 127 public int getTypeAnnotation() { 128 return typeAnnotation; 129 } 130 131 137 138 public boolean isSameNodeInfo(NodeInfo other) { 139 return this==other; 140 } 141 142 148 149 public String getSystemId() { 150 return systemId; 151 } 152 153 157 158 public String getBaseURI() { 159 if (kind == Type.PROCESSING_INSTRUCTION) { 160 return systemId; 161 } else { 162 return null; 163 } 164 } 165 166 170 171 public int getLineNumber() { 172 return -1; 173 } 174 175 183 184 public int compareOrder(NodeInfo other) { 185 186 if (this.isSameNodeInfo(other)) { 188 return 0; 189 } 190 return (this.hashCode() < other.hashCode() ? -1 : +1); 191 } 192 193 197 198 public String getStringValue() { 199 return stringValue.toString(); 200 } 201 202 206 207 public CharSequence getStringValueCS() { 208 return stringValue; 209 } 210 211 219 220 public int getNameCode() { 221 return nameCode; 222 } 223 224 230 231 public int getFingerprint() { 232 if (nameCode == -1) { 233 return -1; 234 } else { 235 return getNameCode()&0xfffff; 236 } 237 } 238 239 243 244 public String getLocalPart() { 245 if (nameCode == -1) { 246 return ""; 247 } else { 248 return config.getNamePool().getLocalName(nameCode); 249 } 250 } 251 252 258 259 public String getURI() { 260 if (nameCode == -1) { 261 return ""; 262 } else { 263 return config.getNamePool().getURI(nameCode); 264 } 265 } 266 267 273 274 public String getPrefix() { 275 if (nameCode == -1) { 276 return ""; 277 } else { 278 return config.getNamePool().getPrefix(nameCode); 279 } 280 } 281 282 288 289 public String getDisplayName() { 290 if (nameCode == -1) { 291 return ""; 292 } else { 293 return config.getNamePool().getDisplayName(nameCode); 294 } 295 } 296 297 301 302 public NodeInfo getParent() { 303 return null; 304 } 305 306 311 312 public AxisIterator iterateAxis(byte axisNumber) { 313 switch (axisNumber) { 314 case Axis.ANCESTOR_OR_SELF: 315 case Axis.DESCENDANT_OR_SELF: 316 case Axis.SELF: 317 return SingletonIterator.makeIterator(this); 318 case Axis.ANCESTOR: 319 case Axis.ATTRIBUTE: 320 case Axis.CHILD: 321 case Axis.DESCENDANT: 322 case Axis.FOLLOWING: 323 case Axis.FOLLOWING_SIBLING: 324 case Axis.NAMESPACE: 325 case Axis.PARENT: 326 case Axis.PRECEDING: 327 case Axis.PRECEDING_SIBLING: 328 case Axis.PRECEDING_OR_ANCESTOR: 329 return EmptyIterator.getInstance(); 330 default: 331 throw new IllegalArgumentException ("Unknown axis number " + axisNumber); 332 } 333 } 334 335 336 342 343 public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) { 344 switch (axisNumber) { 345 case Axis.ANCESTOR_OR_SELF: 346 case Axis.DESCENDANT_OR_SELF: 347 case Axis.SELF: 348 if (nodeTest.matches(this)) { 349 return SingletonIterator.makeIterator(this); 350 } else { 351 return EmptyIterator.getInstance(); 352 } 353 case Axis.ANCESTOR: 354 case Axis.ATTRIBUTE: 355 case Axis.CHILD: 356 case Axis.DESCENDANT: 357 case Axis.FOLLOWING: 358 case Axis.FOLLOWING_SIBLING: 359 case Axis.NAMESPACE: 360 case Axis.PARENT: 361 case Axis.PRECEDING: 362 case Axis.PRECEDING_SIBLING: 363 case Axis.PRECEDING_OR_ANCESTOR: 364 return EmptyIterator.getInstance(); 365 default: 366 throw new IllegalArgumentException ("Unknown axis number " + axisNumber); 367 } 368 } 369 370 375 376 public String getAttributeValue(int fingerprint) { 377 return null; 378 } 379 380 384 385 public NodeInfo getRoot() { 386 return this; 387 } 388 389 394 395 public DocumentInfo getDocumentRoot() { 396 return null; 397 } 398 399 403 404 public boolean hasChildNodes() { 405 return false; 406 } 407 408 415 416 public String generateId() { 417 return "Q" + hashCode(); 418 } 419 420 424 425 public int getDocumentNumber() { 426 return hashCode() & 0xffffff; 427 } 429 430 433 434 public void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId) throws XPathException { 435 Navigator.copy(this, out, config.getNamePool(), whichNamespaces, copyAnnotations, locationId); 436 } 437 438 444 445 public void sendNamespaceDeclarations(Receiver out, boolean includeAncestors) { 446 } 447 448 463 464 public int[] getDeclaredNamespaces(int[] buffer) { 465 return null; 466 } 467 468 } 469 470 | Popular Tags |