Debian Codegraph @

net/sf/saxon/value/TextFragmentValue.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.value;
9
10 import net.sf.saxon.Configuration;
11 import net.sf.saxon.event.Receiver;
12 import net.sf.saxon.expr.parser.Location;
13 import net.sf.saxon.om.*;
14 import net.sf.saxon.pattern.NodeTest;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.tree.iter.*;
17 import net.sf.saxon.tree.util.FastStringBuffer;
18 import net.sf.saxon.tree.util.Navigator;
19 import net.sf.saxon.type.SchemaType;
20 import net.sf.saxon.type.Type;
21 import net.sf.saxon.type.Untyped;
22
23 import javax.xml.transform.SourceLocator;
24 import java.util.Collections;
25 import java.util.Iterator;
26
27 /**
28 * This class represents a temporary tree whose root document node owns a single text node. <BR>
29 */
30
31 public final class TextFragmentValue implements NodeInfo, SourceLocator {
32
33 private CharSequence text;
34 private String baseURI;
35 private String documentURI;
36 private GenericTreeInfo treeInfo;
37 private TextFragmentTextNode textNode = null; // created on demand
38
39
40 /**
41 * Constructor: create a result tree fragment containing a single text node
42 *
43 * @param value a String containing the value
44 * @param baseURI the base URI of the document node
45 */
46
47 public TextFragmentValue(Configuration config, CharSequence value, String baseURI) {
48 this.text = value;
49 this.baseURI = baseURI;
50 this.treeInfo = new GenericTreeInfo(config);
51 this.treeInfo.setRootNode(this);
52 }
53
54 /**
55 * Get information about the tree to which this NodeInfo belongs
56 *
57 * @return the TreeInfo
58 * @since 9.7
59 */
60 public TreeInfo getTreeInfo() {
61 return treeInfo;
62 }
63
64 /**
65 * Get the NodeInfo object representing the document node at the root of the tree
66 *
67 * @return the document node
68 */
69
70 public NodeInfo getRootNode() {
71 return this;
72 }
73
74 /**
75 * Ask whether the document contains any nodes whose type annotation is anything other than
76 * UNTYPED
77 *
78 * @return true if the document contains elements whose type is other than UNTYPED
79 */
80 public boolean isTyped() {
81 return false;
82 }
83
84 /**
85 * Return the type of node.
86 *
87 * @return Type.DOCUMENT (always)
88 */
89
90 public final int getNodeKind() {
91 return Type.DOCUMENT;
92 }
93
94 /**
95 * Get the String Value
96 */
97
98 public String getStringValue() {
99 return text.toString();
100 }
101
102 /**
103 * Get the value of the item as a CharSequence. This is in some cases more efficient than
104 * the version of the method that returns a String.
105 */
106
107 public CharSequence getStringValueCS() {
108 return text;
109 }
110
111 /**
112 * Determine whether this is the same node as another node
113 *
114 * @return true if this Node object and the supplied Node object represent the
115 * same node in the tree.
116 */
117
118 public boolean equals(Object other) {
119 return this == other;
120 }
121
122 /**
123 * Ask whether this NodeInfo implementation holds a fingerprint identifying the name of the
124 * node in the NamePool. If the answer is true, then the {@link #getFingerprint} method must
125 * return the fingerprint of the node. If the answer is false, then the {@link #getFingerprint}
126 * method should throw an {@code UnsupportedOperationException}. In the case of unnamed nodes
127 * such as text nodes, the result can be either true (in which case getFingerprint() should
128 * return -1) or false (in which case getFingerprint may throw an exception).
129 *
130 * @return true if the implementation of this node provides fingerprints.
131 * @since 9.8; previously Saxon relied on using <code>FingerprintedNode</code> as a marker interface.
132 */
133 @Override
134 public boolean hasFingerprint() {
135 return true;
136 }
137
138 /**
139 * Get a character string that uniquely identifies this node
140 *
141 * @param buffer the buffer to contain the generated ID
142 */
143
144 public void generateId(/*@NotNull*/ FastStringBuffer buffer) {
145 buffer.append("tt");
146 buffer.append(Long.toString(treeInfo.getDocumentNumber()));
147 }
148
149 /**
150 * Set the system ID (that is, the document URI property) for the document node.
151 *
152 * @throws UnsupportedOperationException (always). This kind of tree does not have a document URI.
153 */
154
155 public void setSystemId(String systemId) {
156 documentURI = systemId;
157 }
158
159 /**
160 * Get the system ID (the document URI) of the document node.
161 */
162
163 public String getSystemId() {
164 return documentURI;
165 }
166
167 /**
168 * Get the base URI for the document node.
169 */
170
171 public String getBaseURI() {
172 return baseURI;
173 }
174
175 /**
176 * Determine the relative position of this node and another node, in document order.
177 * The other node will always be in the same document.
178 *
179 * @param other The other node, whose position is to be compared with this node
180 * @return -1 if this node precedes the other node, +1 if it follows the other
181 * node, or 0 if they are the same node. (In this case, isSameNode() will always
182 * return true, and the two nodes will produce the same result for generateId())
183 */
184
185 public int compareOrder(NodeInfo other) {
186 if (this == other) {
187 return 0;
188 }
189 return -1;
190 }
191
192 /**
193 * Get the fingerprint of the node, used for matching names
194 */
195
196 public int getFingerprint() {
197 return -1;
198 }
199
200 /**
201 * Get the prefix part of the name of this node. This is the name before the ":" if any.
202 *
203 * @return the prefix part of the name. For an unnamed node, return "".
204 */
205
206 /*@NotNull*/
207 public String getPrefix() {
208 return "";
209 }
210
211 /**
212 * Get the URI part of the name of this node. This is the URI corresponding to the
213 * prefix, or the URI of the default namespace if appropriate.
214 *
215 * @return The URI of the namespace of this node. For an unnamed node, or for
216 * an element or attribute in the default namespace, return an empty string.
217 */
218
219 /*@NotNull*/
220 public String getURI() {
221 return "";
222 }
223
224 /**
225 * Get the display name of this node. For elements and attributes this is [prefix:]localname.
226 * For unnamed nodes, it is an empty string.
227 *
228 * @return The display name of this node.
229 * For a node with no name, return an empty string.
230 */
231
232 /*@NotNull*/
233 public String getDisplayName() {
234 return "";
235 }
236
237 /**
238 * Get the local name of this node.
239 *
240 * @return The local name of this node.
241 * For a node with no name, return "".
242 */
243
244 /*@NotNull*/
245 public String getLocalPart() {
246 return "";
247 }
248
249 /**
250 * Determine whether the node has any children.
251 *
252 * @return <code>true</code> if this node has any attributes,
253 * <code>false</code> otherwise.
254 */
255
256 public boolean hasChildNodes() {
257 return text.length() != 0;
258 }
259
260 /**
261 * Get an immutable copy of this Location object. By default Location objects may be mutable, so they
262 * should not be saved for later use. The result of this operation holds the same location information,
263 * but in an immutable form.
264 */
265 public Location saveLocation() {
266 return this;
267 }
268
269 /**
270 * Get the type annotation of this node, if any. The type annotation is represented as
271 * SchemaType object.
272 * <p>Types derived from a DTD are not reflected in the result of this method.</p>
273 *
274 * @return For element and attribute nodes: the type annotation derived from schema
275 * validation (defaulting to xs:untyped and xs:untypedAtomic in the absence of schema
276 * validation). For comments, text nodes, processing instructions, and namespaces: null.
277 * For document nodes, either xs:untyped if the document has not been validated, or
278 * xs:anyType if it has.
279 * @since 9.4
280 */
281 public SchemaType getSchemaType() {
282 return Untyped.getInstance();
283 }
284
285 /**
286 * Get all namespace undeclarations and undeclarations defined on this element.
287 *
288 * @param buffer If this is non-null, and the result array fits in this buffer, then the result
289 * may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
290 * @return An array of integers representing the namespace declarations and undeclarations present on
291 * this element. For a node other than an element, return null. Otherwise, the returned array is a
292 * sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The
293 * top half word of each namespace code represents the prefix, the bottom half represents the URI.
294 * If the bottom half is zero, then this is a namespace undeclaration rather than a declaration.
295 * The XML namespace is never included in the list. If the supplied array is larger than required,
296 * then the first unused entry will be set to -1.
297 * <p>For a node other than an element, the method returns null.</p>
298 */
299
300 /*@Nullable*/
301 public NamespaceBinding[] getDeclaredNamespaces(NamespaceBinding[] buffer) {
302 return null;
303 }
304
305 /**
306 * Get the typed value.
307 *
308 * @return the typed value. If requireSingleton is set to true, the result will always be an
309 * AtomicValue. In other cases it may be a Value representing a sequence whose items are atomic
310 * values.
311 * @since 8.5
312 */
313
314 /*@NotNull*/
315 public AtomicSequence atomize() {
316 return new UntypedAtomicValue(text);
317 }
318
319 /**
320 * Get the string value of a given attribute of this node
321 *
322 * @param uri the namespace URI of the attribute name. Supply the empty string for an attribute
323 * that is in no namespace
324 * @param local the local part of the attribute name.
325 * @return the attribute value if it exists, or null if it does not exist. Always returns null
326 * if this node is not an element.
327 * @since 9.4
328 */
329 public String getAttributeValue(/*@NotNull*/ String uri, /*@NotNull*/ String local) {
330 return null;
331 }
332
333 /**
334 * Return an iteration over the nodes reached by the given axis from this node
335 *
336 * @param axisNumber The axis to be iterated over
337 * @return a AxisIterator that scans the nodes reached by the axis in turn.
338 * @see net.sf.saxon.om.AxisInfo
339 */
340
341 /*@NotNull*/
342 public AxisIterator iterateAxis(byte axisNumber) {
343 switch (axisNumber) {
344 case AxisInfo.ANCESTOR:
345 case AxisInfo.ATTRIBUTE:
346 case AxisInfo.FOLLOWING:
347 case AxisInfo.FOLLOWING_SIBLING:
348 case AxisInfo.NAMESPACE:
349 case AxisInfo.PARENT:
350 case AxisInfo.PRECEDING:
351 case AxisInfo.PRECEDING_SIBLING:
352 case AxisInfo.PRECEDING_OR_ANCESTOR:
353 return EmptyIterator.OfNodes.THE_INSTANCE;
354
355 case AxisInfo.SELF:
356 case AxisInfo.ANCESTOR_OR_SELF:
357 return SingleNodeIterator.makeIterator(this);
358
359 case AxisInfo.CHILD:
360 case AxisInfo.DESCENDANT:
361 return SingleNodeIterator.makeIterator(getTextNode());
362
363 case AxisInfo.DESCENDANT_OR_SELF:
364 NodeInfo[] nodes = {this, getTextNode()};
365 return new ArrayIterator.OfNodes(nodes);
366
367 default:
368 throw new IllegalArgumentException("Unknown axis number " + axisNumber);
369 }
370 }
371
372 /**
373 * Return an enumeration over the nodes reached by the given axis from this node
374 *
375 * @param axisNumber The axis to be iterated over
376 * @param nodeTest A pattern to be matched by the returned nodes
377 * @return a AxisIterator that scans the nodes reached by the axis in turn.
378 * @see net.sf.saxon.om.AxisInfo
379 */
380
381 /*@NotNull*/
382 public AxisIterator iterateAxis(byte axisNumber, /*@NotNull*/ NodeTest nodeTest) {
383 switch (axisNumber) {
384 case AxisInfo.ANCESTOR:
385 case AxisInfo.ATTRIBUTE:
386 case AxisInfo.FOLLOWING:
387 case AxisInfo.FOLLOWING_SIBLING:
388 case AxisInfo.NAMESPACE:
389 case AxisInfo.PARENT:
390 case AxisInfo.PRECEDING:
391 case AxisInfo.PRECEDING_SIBLING:
392 case AxisInfo.PRECEDING_OR_ANCESTOR:
393 return EmptyIterator.OfNodes.THE_INSTANCE;
394
395 case AxisInfo.SELF:
396 case AxisInfo.ANCESTOR_OR_SELF:
397 return Navigator.filteredSingleton(this, nodeTest);
398
399 case AxisInfo.CHILD:
400 case AxisInfo.DESCENDANT:
401 return Navigator.filteredSingleton(getTextNode(), nodeTest);
402
403 case AxisInfo.DESCENDANT_OR_SELF:
404 boolean b1 = nodeTest.matchesNode(this);
405 NodeInfo textNode2 = getTextNode();
406 boolean b2 = nodeTest.matchesNode(textNode2);
407 if (b1) {
408 if (b2) {
409 NodeInfo[] pair = {this, textNode2};
410 return new ArrayIterator.OfNodes(pair);
411 } else {
412 return SingleNodeIterator.makeIterator(this);
413 }
414 } else {
415 if (b2) {
416 return SingleNodeIterator.makeIterator(textNode2);
417 } else {
418 return EmptyIterator.OfNodes.THE_INSTANCE;
419 }
420 }
421
422 default:
423 throw new IllegalArgumentException("Unknown axis number " + axisNumber);
424 }
425 }
426
427 /**
428 * Find the parent node of this node.
429 *
430 * @return The Node object describing the containing element or root node.
431 */
432
433 /*@Nullable*/
434 public NodeInfo getParent() {
435 return null;
436 }
437
438 /**
439 * Get the root node
440 *
441 * @return the NodeInfo representing the root of this tree
442 */
443
444 /*@NotNull*/
445 public NodeInfo getRoot() {
446 return this;
447 }
448
449 /**
450 * Copy the result tree fragment value to a given Outputter
451 */
452
453 public void copy(/*@NotNull*/ Receiver out, int copyOptions, Location locationId)
454 throws XPathException {
455 out.characters(text, locationId, 0);
456 }
457
458 /**
459 * Get the element with a given ID.
460 *
461 * @param id The unique ID of the required element
462 * @param getParent True if, in the case of an element of type xs:ID, we want its parent
463 * @return null (this kind of tree contains no elements)
464 */
465
466 /*@Nullable*/
467 public NodeInfo selectID(String id, boolean getParent) {
468 return null;
469 }
470
471 /**
472 * Get the list of unparsed entities defined in this document
473 *
474 * @return an Iterator, whose items are of type String, containing the names of all
475 * unparsed entities defined in this document. If there are no unparsed entities or if the
476 * information is not available then an empty iterator is returned
477 */
478
479 public Iterator<String> getUnparsedEntityNames() {
480 return Collections.emptyIterator();
481 }
482
483 /**
484 * Get the unparsed entity with a given name
485 *
486 * @param name the name of the entity
487 * @return the URI and public ID of the entity if there is one, or null if not
488 */
489
490 /*@Nullable*/
491 public String[] getUnparsedEntity(String name) {
492 return null;
493 }
494
495 /**
496 * Make an instance of the text node
497 * @return the new or existing instance
498 */
499
500 /*@Nullable*/
501 private TextFragmentTextNode getTextNode() {
502 if (textNode == null) {
503 textNode = new TextFragmentTextNode();
504 }
505 return textNode;
506 }
507
508 /**
509 * Inner class representing the text node; this is created on demand
510 */
511
512 private class TextFragmentTextNode implements NodeInfo, SourceLocator {
513
514 /**
515 * Ask whether this NodeInfo implementation holds a fingerprint identifying the name of the
516 * node in the NamePool. If the answer is true, then the {@link #getFingerprint} method must
517 * return the fingerprint of the node. If the answer is false, then the {@link #getFingerprint}
518 * method should throw an {@code UnsupportedOperationException}. In the case of unnamed nodes
519 * such as text nodes, the result can be either true (in which case getFingerprint() should
520 * return -1) or false (in which case getFingerprint may throw an exception).
521 *
522 * @return true if the implementation of this node provides fingerprints.
523 * @since 9.8; previously Saxon relied on using <code>FingerprintedNode</code> as a marker interface.
524 */
525 @Override
526 public boolean hasFingerprint() {
527 return true;
528 }
529
530 /**
531 * Get information about the tree to which this NodeInfo belongs
532 *
533 * @return the TreeInfo
534 * @since 9.7
535 */
536 public TreeInfo getTreeInfo() {
537 return treeInfo;
538 }
539
540 /**
541 * Set the system ID for the entity containing the node.
542 */
543
544 public void setSystemId(String systemId) {
545 }
546
547 /**
548 * Return the type of node.
549 *
550 * @return Type.TEXT (always)
551 */
552
553 public final int getNodeKind() {
554 return Type.TEXT;
555 }
556
557 /**
558 * Get the String Value
559 */
560
561 public String getStringValue() {
562 return text.toString();
563 }
564
565 /**
566 * Get the value of the item as a CharSequence. This is in some cases more efficient than
567 * the version of the method that returns a String.
568 */
569
570 public CharSequence getStringValueCS() {
571 return text;
572 }
573
574 /**
575 * Determine whether this is the same node as another node
576 *
577 * @return true if this Node object and the supplied Node object represent the
578 * same node in the tree.
579 */
580
581 public boolean equals(NodeInfo other) {
582 return this == other;
583 }
584
585 /**
586 * Get a character string that uniquely identifies this node
587 */
588
589 public void generateId(/*@NotNull*/ FastStringBuffer buffer) {
590 buffer.append("tt");
591 buffer.append(Long.toString(treeInfo.getDocumentNumber()));
592 buffer.append("t1");
593 }
594
595 /**
596 * Get the system ID for the entity containing the node.
597 */
598
599 /*@Nullable*/
600 public String getSystemId() {
601 return null;
602 }
603
604 /**
605 * Get the base URI for the node. Default implementation for child nodes gets
606 * the base URI of the parent node.
607 */
608
609 public String getBaseURI() {
610 return baseURI;
611 }
612
613 /**
614 * Determine the relative position of this node and another node, in document order.
615 * The other node will always be in the same document.
616 *
617 * @param other The other node, whose position is to be compared with this node
618 * @return -1 if this node precedes the other node, +1 if it follows the other
619 * node, or 0 if they are the same node. (In this case, isSameNode() will always
620 * return true, and the two nodes will produce the same result for generateId())
621 */
622
623 public int compareOrder(NodeInfo other) {
624 if (this == other) {
625 return 0;
626 }
627 return +1;
628 }
629
630 /**
631 * Get the fingerprint of the node, used for matching names
632 */
633
634 public int getFingerprint() {
635 return -1;
636 }
637
638
639 /**
640 * Get the prefix part of the name of this node. This is the name before the ":" if any.
641 *
642 * @return the prefix part of the name. For an unnamed node, return "".
643 */
644
645 /*@NotNull*/
646 public String getPrefix() {
647 return "";
648 }
649
650 /**
651 * Get the URI part of the name of this node. This is the URI corresponding to the
652 * prefix, or the URI of the default namespace if appropriate.
653 *
654 * @return The URI of the namespace of this node. For an unnamed node, or for
655 * an element or attribute in the default namespace, return an empty string.
656 */
657
658 /*@NotNull*/
659 public String getURI() {
660 return "";
661 }
662
663 /**
664 * Get the display name of this node. For elements and attributes this is [prefix:]localname.
665 * For unnamed nodes, it is an empty string.
666 *
667 * @return The display name of this node.
668 * For a node with no name, return an empty string.
669 */
670
671 /*@NotNull*/
672 public String getDisplayName() {
673 return "";
674 }
675
676 /**
677 * Get the local name of this node.
678 *
679 * @return The local name of this node.
680 * For a node with no name, return "".
681 */
682
683 /*@NotNull*/
684 public String getLocalPart() {
685 return "";
686 }
687
688 /**
689 * Determine whether the node has any children.
690 *
691 * @return <code>true</code> if this node has any attributes,
692 * <code>false</code> otherwise.
693 */
694
695 public boolean hasChildNodes() {
696 return false;
697 }
698
699 /**
700 * Get the string value of a given attribute of this node
701 *
702 * @param uri the namespace URI of the attribute name. Supply the empty string for an attribute
703 * that is in no namespace
704 * @param local the local part of the attribute name.
705 * @return the attribute value if it exists, or null if it does not exist. Always returns null
706 * if this node is not an element.
707 * @since 9.4
708 */
709 public String getAttributeValue(/*@NotNull*/ String uri, /*@NotNull*/ String local) {
710 return null;
711 }
712
713 /**
714 * Get an immutable copy of this Location object. By default Location objects may be mutable, so they
715 * should not be saved for later use. The result of this operation holds the same location information,
716 * but in an immutable form.
717 */
718 public Location saveLocation() {
719 return this;
720 }
721
722 /**
723 * Get the type annotation of this node, if any. The type annotation is represented as
724 * SchemaType object.
725 * <p>Types derived from a DTD are not reflected in the result of this method.</p>
726 *
727 * @return For element and attribute nodes: the type annotation derived from schema
728 * validation (defaulting to xs:untyped and xs:untypedAtomic in the absence of schema
729 * validation). For comments, text nodes, processing instructions, and namespaces: null.
730 * For document nodes, either xs:untyped if the document has not been validated, or
731 * xs:anyType if it has.
732 * @since 9.4
733 */
734 public SchemaType getSchemaType() {
735 return null;
736 }
737
738 /**
739 * Get all namespace undeclarations and undeclarations defined on this element.
740 *
741 * @param buffer If this is non-null, and the result array fits in this buffer, then the result
742 * may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
743 * @return An array of integers representing the namespace declarations and undeclarations present on
744 * this element. For a node other than an element, return null. Otherwise, the returned array is a
745 * sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The
746 * top half word of each namespace code represents the prefix, the bottom half represents the URI.
747 * If the bottom half is zero, then this is a namespace undeclaration rather than a declaration.
748 * The XML namespace is never included in the list. If the supplied array is larger than required,
749 * then the first unused entry will be set to -1.
750 * <p>For a node other than an element, the method returns null.</p>
751 */
752
753 /*@Nullable*/
754 public NamespaceBinding[] getDeclaredNamespaces(NamespaceBinding[] buffer) {
755 return null;
756 }
757
758 /**
759 * Get the typed value.
760 *
761 * @return the typed value. If requireSingleton is set to true, the result will always be an
762 * AtomicValue. In other cases it may be a Value representing a sequence whose items are atomic
763 * values.
764 * @since 8.5
765 */
766
767 /*@NotNull*/
768 public AtomicSequence atomize() throws XPathException {
769 return new UntypedAtomicValue(text);
770 }
771
772 /**
773 * Return an enumeration over the nodes reached by the given axis from this node
774 *
775 * @param axisNumber the axis to be iterated over
776 * @return a AxisIterator that scans the nodes reached by the axis in turn.
777 */
778
779 /*@NotNull*/
780 public AxisIterator iterateAxis(byte axisNumber) {
781 switch (axisNumber) {
782 case AxisInfo.ANCESTOR:
783 case AxisInfo.PARENT:
784 case AxisInfo.PRECEDING_OR_ANCESTOR:
785 return SingleNodeIterator.makeIterator(TextFragmentValue.this);
786
787 case AxisInfo.ANCESTOR_OR_SELF:
788 NodeInfo[] nodes = {this, TextFragmentValue.this};
789 return new ArrayIterator.OfNodes(nodes);
790
791 case AxisInfo.ATTRIBUTE:
792 case AxisInfo.CHILD:
793 case AxisInfo.DESCENDANT:
794 case AxisInfo.FOLLOWING:
795 case AxisInfo.FOLLOWING_SIBLING:
796 case AxisInfo.NAMESPACE:
797 case AxisInfo.PRECEDING:
798 case AxisInfo.PRECEDING_SIBLING:
799 return EmptyIterator.OfNodes.THE_INSTANCE;
800
801 case AxisInfo.SELF:
802 case AxisInfo.DESCENDANT_OR_SELF:
803 return SingleNodeIterator.makeIterator(this);
804
805 default:
806 throw new IllegalArgumentException("Unknown axis number " + axisNumber);
807 }
808 }
809
810
811 /**
812 * Return an enumeration over the nodes reached by the given axis from this node
813 *
814 * @param axisNumber the axis to be iterated over
815 * @param nodeTest A pattern to be matched by the returned nodes
816 * @return a AxisIterator that scans the nodes reached by the axis in turn.
817 */
818
819 /*@NotNull*/
820 public AxisIterator iterateAxis(byte axisNumber, /*@NotNull*/ NodeTest nodeTest) {
821 switch (axisNumber) {
822 case AxisInfo.ANCESTOR:
823 case AxisInfo.PARENT:
824 case AxisInfo.PRECEDING_OR_ANCESTOR:
825 return Navigator.filteredSingleton(TextFragmentValue.this, nodeTest);
826
827 case AxisInfo.ANCESTOR_OR_SELF:
828 boolean matchesDoc = nodeTest.matchesNode(TextFragmentValue.this);
829 boolean matchesText = nodeTest.matchesNode(this);
830 if (matchesDoc && matchesText) {
831 NodeInfo[] nodes = {this, TextFragmentValue.this};
832 return new ArrayIterator.OfNodes(nodes);
833 } else if (matchesDoc /* && !matchesText */) {
834 return SingleNodeIterator.makeIterator(TextFragmentValue.this);
835 } else if (matchesText /* && !matchesDoc */) {
836 return SingleNodeIterator.makeIterator(this);
837 } else {
838 return EmptyIterator.OfNodes.THE_INSTANCE;
839 }
840
841 case AxisInfo.ATTRIBUTE:
842 case AxisInfo.CHILD:
843 case AxisInfo.DESCENDANT:
844 case AxisInfo.FOLLOWING:
845 case AxisInfo.FOLLOWING_SIBLING:
846 case AxisInfo.NAMESPACE:
847 case AxisInfo.PRECEDING:
848 case AxisInfo.PRECEDING_SIBLING:
849 return EmptyIterator.OfNodes.THE_INSTANCE;
850
851 case AxisInfo.SELF:
852 case AxisInfo.DESCENDANT_OR_SELF:
853 return Navigator.filteredSingleton(this, nodeTest);
854
855 default:
856 throw new IllegalArgumentException("Unknown axis number " + axisNumber);
857 }
858 }
859
860 /**
861 * Find the parent node of this node.
862 *
863 * @return The Node object describing the containing element or root node.
864 */
865
866 /*@NotNull*/
867 public NodeInfo getParent() {
868 return TextFragmentValue.this;
869 }
870
871 /**
872 * Get the root node
873 *
874 * @return the NodeInfo representing the root of this tree
875 */
876
877 /*@NotNull*/
878 public NodeInfo getRoot() {
879 return TextFragmentValue.this;
880 }
881
882 /**
883 * Copy the node to a given Outputter
884 */
885
886 public void copy(/*@NotNull*/ Receiver out, int copyOptions, Location locationId)
887 throws XPathException {
888 out.characters(text, locationId, 0);
889 }
890 }
891
892 }
893