KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > value > TextFragmentValue


1 package net.sf.saxon.value;
2 import net.sf.saxon.Configuration;
3 import net.sf.saxon.event.Receiver;
4 import net.sf.saxon.om.*;
5 import net.sf.saxon.pattern.NodeTest;
6 import net.sf.saxon.trans.XPathException;
7 import net.sf.saxon.type.Type;
8
9 import javax.xml.transform.SourceLocator JavaDoc;
10
11 /**
12 * This class represents a temporary tree whose root document node owns a single text node. <BR>
13 */

14
15 public final class TextFragmentValue implements DocumentInfo, FingerprintedNode, SourceLocator JavaDoc {
16
17     private CharSequence JavaDoc text;
18     private String JavaDoc systemId;
19     private TextFragmentTextNode textNode = null; // created on demand
20
private Configuration config;
21     private int documentNumber;
22
23     /**
24     * Constructor: create a result tree fragment containing a single text node
25     * @param value a String containing the value
26     */

27
28     public TextFragmentValue(CharSequence JavaDoc value, String JavaDoc systemId) {
29         this.text = value;
30         this.systemId = systemId;
31     }
32
33     /**
34     * Set the configuration (containing the name pool used for all names in this document)
35     */

36
37     public void setConfiguration(Configuration config) {
38         this.config = config;
39         documentNumber = -1; // the document number is allocated lazily because it can cause
40
// contention on the NamePool and is often not needed.
41
}
42
43     /**
44      * Get the configuration previously set using setConfiguration
45      * (or the default configuraton allocated automatically)
46      */

47
48     public Configuration getConfiguration() {
49         return config;
50     }
51
52     /**
53     * Get the name pool used for the names in this document
54     */

55
56     public NamePool getNamePool() {
57         return config.getNamePool();
58     }
59
60     /**
61     * Get the unique document number
62     */

63
64     public int getDocumentNumber() {
65         if (documentNumber == -1) {
66             documentNumber = config.getDocumentNumberAllocator().allocateDocumentNumber();
67             // technically this isn't thread-safe; however, TextFragmentValues are invariably used within
68
// a single thread
69
}
70         return documentNumber;
71     }
72
73     /**
74     * Return the type of node.
75     * @return Type.DOCUMENT (always)
76     */

77
78     public final int getNodeKind() {
79         return Type.DOCUMENT;
80     }
81
82     /**
83     * Get the String Value
84     */

85
86     public String JavaDoc getStringValue() {
87         return text.toString();
88     }
89
90     /**
91      * Get the value of the item as a CharSequence. This is in some cases more efficient than
92      * the version of the method that returns a String.
93      */

94
95     public CharSequence JavaDoc getStringValueCS() {
96         return text;
97     }
98
99     /**
100     * Determine whether this is the same node as another node
101     * @return true if this Node object and the supplied Node object represent the
102     * same node in the tree.
103     */

104
105     public boolean isSameNodeInfo(NodeInfo other) {
106         return this==other;
107     }
108
109     /**
110     * Get a character string that uniquely identifies this node
111     * @return a string.
112     */

113
114     public String JavaDoc generateId() {
115         return "tt" + getDocumentNumber();
116     }
117
118     /**
119     * Set the system ID for the entity containing the node.
120     */

121
122     public void setSystemId(String JavaDoc systemId) {
123         this.systemId = systemId;
124     }
125
126     /**
127     * Get the system ID for the entity containing the node.
128     */

129
130     public String JavaDoc getSystemId() {
131         return systemId;
132     }
133
134     /**
135     * Get the base URI for the node. Default implementation for child nodes gets
136     * the base URI of the parent node.
137     */

138
139     public String JavaDoc getBaseURI() {
140         return systemId;
141     }
142
143     /**
144     * Determine the relative position of this node and another node, in document order.
145     * The other node will always be in the same document.
146     * @param other The other node, whose position is to be compared with this node
147     * @return -1 if this node precedes the other node, +1 if it follows the other
148     * node, or 0 if they are the same node. (In this case, isSameNode() will always
149     * return true, and the two nodes will produce the same result for generateId())
150     */

151
152     public int compareOrder(NodeInfo other) {
153         if (this==other) return 0;
154         return -1;
155     }
156
157     /**
158     * Get the name code of the node, used for displaying names
159     */

160
161     public int getNameCode() {
162         return -1;
163     }
164
165     /**
166     * Get the fingerprint of the node, used for matching names
167     */

168
169     public int getFingerprint() {
170         return -1;
171     }
172
173
174     /**
175     * Get the prefix part of the name of this node. This is the name before the ":" if any.
176     * @return the prefix part of the name. For an unnamed node, return "".
177     */

178
179     public String JavaDoc getPrefix() {
180         return "";
181     }
182
183     /**
184     * Get the URI part of the name of this node. This is the URI corresponding to the
185     * prefix, or the URI of the default namespace if appropriate.
186     * @return The URI of the namespace of this node. For an unnamed node, or for
187     * an element or attribute in the default namespace, return an empty string.
188     */

189
190     public String JavaDoc getURI() {
191         return "";
192     }
193
194     /**
195     * Get the display name of this node. For elements and attributes this is [prefix:]localname.
196     * For unnamed nodes, it is an empty string.
197     * @return The display name of this node.
198     * For a node with no name, return an empty string.
199     */

200
201     public String JavaDoc getDisplayName() {
202         return "";
203     }
204
205     /**
206     * Get the local name of this node.
207     * @return The local name of this node.
208     * For a node with no name, return "".
209     */

210
211     public String JavaDoc getLocalPart() {
212         return "";
213     }
214
215     /**
216     * Determine whether the node has any children.
217     * @return <code>true</code> if this node has any attributes,
218     * <code>false</code> otherwise.
219     */

220
221     public boolean hasChildNodes() {
222         return !("".equals(text));
223     }
224
225     /**
226      * Get line number
227      *
228      * @return the line number of the node in its original source document; or
229      * -1 if not available
230      */

231
232     public int getLineNumber() {
233         return -1;
234     }
235
236     /**
237      * Get the type annotation of this node, if any.
238      * Returns -1 for kinds of nodes that have no annotation, and for elements annotated as
239      * untyped, and attributes annotated as untypedAtomic.
240      *
241      * @return the type annotation of the node.
242      * @see net.sf.saxon.type.Type
243      */

244
245     public int getTypeAnnotation() {
246         return -1;
247     }
248
249     /**
250      * Output all namespace nodes associated with this element. Does nothing if
251      * the node is not an element.
252      *
253      * @param out The relevant outputter
254      * @param includeAncestors True if namespaces declared on ancestor
255      */

256
257     public void sendNamespaceDeclarations(Receiver out, boolean includeAncestors) {
258     }
259
260     /**
261      * Get all namespace undeclarations and undeclarations defined on this element.
262      *
263      * @param buffer If this is non-null, and the result array fits in this buffer, then the result
264      * may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
265      * @return An array of integers representing the namespace declarations and undeclarations present on
266      * this element. For a node other than an element, return null. Otherwise, the returned array is a
267      * sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The
268      * top half word of each namespace code represents the prefix, the bottom half represents the URI.
269      * If the bottom half is zero, then this is a namespace undeclaration rather than a declaration.
270      * The XML namespace is never included in the list. If the supplied array is larger than required,
271      * then the first unused entry will be set to -1.
272      * <p/>
273      * <p>For a node other than an element, the method returns null.</p>
274      */

275
276     public int[] getDeclaredNamespaces(int[] buffer) {
277         return null;
278     }
279
280     /**
281      * Get the typed value of the item
282      *
283      * @return the typed value of the item. In general this will be a sequence
284      */

285
286     public SequenceIterator getTypedValue() {
287         return SingletonIterator.makeIterator(new UntypedAtomicValue(text));
288     }
289
290     /**
291      * Get the typed value. The result of this method will always be consistent with the method
292      * {@link net.sf.saxon.om.Item#getTypedValue()}. However, this method is often more convenient and may be
293      * more efficient, especially in the common case where the value is expected to be a singleton.
294      *
295      * @return the typed value. If requireSingleton is set to true, the result will always be an
296      * AtomicValue. In other cases it may be a Value representing a sequence whose items are atomic
297      * values.
298      * @since 8.5
299      */

300
301     public Value atomize() {
302         return new UntypedAtomicValue(text);
303     }
304
305     /**
306      * Return the public identifier for the current document event.
307      * <p/>
308      * <p>The return value is the public identifier of the document
309      * entity or of the external parsed entity in which the markup that
310      * triggered the event appears.</p>
311      *
312      * @return A string containing the public identifier, or
313      * null if none is available.
314      * @see #getSystemId
315      */

316     public String JavaDoc getPublicId() {
317         return null;
318     }
319
320     /**
321      * Return the character position where the current document event ends.
322      * <p/>
323      * <p><strong>Warning:</strong> The return value from the method
324      * is intended only as an approximation for the sake of error
325      * reporting; it is not intended to provide sufficient information
326      * to edit the character content of the original XML document.</p>
327      * <p/>
328      * <p>The return value is an approximation of the column number
329      * in the document entity or external parsed entity where the
330      * markup that triggered the event appears.</p>
331      *
332      * @return The column number, or -1 if none is available.
333      * @see #getLineNumber
334      */

335     public int getColumnNumber() {
336         return -1;
337     }
338
339    /**
340     * Get the value of a given attribute of this node
341     * @param fingerprint The fingerprint of the attribute name
342     * @return the attribute value if it exists or null if not
343     */

344
345     public String JavaDoc getAttributeValue(int fingerprint) {
346         return null;
347     }
348
349     /**
350     * Return an iteration over the nodes reached by the given axis from this node
351     * @param axisNumber The axis to be iterated over
352     * @return a AxisIterator that scans the nodes reached by the axis in turn.
353     * @see net.sf.saxon.om.Axis
354     */

355
356     public AxisIterator iterateAxis(byte axisNumber) {
357         switch (axisNumber) {
358             case Axis.ANCESTOR:
359             case Axis.ATTRIBUTE:
360             case Axis.FOLLOWING:
361             case Axis.FOLLOWING_SIBLING:
362             case Axis.NAMESPACE:
363             case Axis.PARENT:
364             case Axis.PRECEDING:
365             case Axis.PRECEDING_SIBLING:
366             case Axis.PRECEDING_OR_ANCESTOR:
367                 return EmptyIterator.getInstance();
368
369             case Axis.SELF:
370             case Axis.ANCESTOR_OR_SELF:
371                 return SingletonIterator.makeIterator(this);
372
373             case Axis.CHILD:
374             case Axis.DESCENDANT:
375                 return SingletonIterator.makeIterator(getTextNode());
376
377             case Axis.DESCENDANT_OR_SELF:
378                 Item[] nodes = {this, getTextNode()};
379                 return new ArrayIterator(nodes);
380
381             default:
382                  throw new IllegalArgumentException JavaDoc("Unknown axis number " + axisNumber);
383         }
384     }
385
386     /**
387     * Return an enumeration over the nodes reached by the given axis from this node
388     * @param axisNumber The axis to be iterated over
389     * @param nodeTest A pattern to be matched by the returned nodes
390     * @return a AxisIterator that scans the nodes reached by the axis in turn.
391     * @see net.sf.saxon.om.Axis
392     */

393
394     public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) {
395         switch (axisNumber) {
396             case Axis.ANCESTOR:
397             case Axis.ATTRIBUTE:
398             case Axis.FOLLOWING:
399             case Axis.FOLLOWING_SIBLING:
400             case Axis.NAMESPACE:
401             case Axis.PARENT:
402             case Axis.PRECEDING:
403             case Axis.PRECEDING_SIBLING:
404             case Axis.PRECEDING_OR_ANCESTOR:
405                 return EmptyIterator.getInstance();
406
407             case Axis.SELF:
408             case Axis.ANCESTOR_OR_SELF:
409                 return SingletonIterator.makeIterator(this);
410
411             case Axis.CHILD:
412             case Axis.DESCENDANT:
413                 NodeInfo textNode = getTextNode();
414                 if (nodeTest.matches(textNode)) {
415                     return SingletonIterator.makeIterator(textNode);
416                 } else {
417                     return EmptyIterator.getInstance();
418                 }
419
420             case Axis.DESCENDANT_OR_SELF:
421                 NodeInfo textNode2 = getTextNode();
422                 if (nodeTest.matches(textNode2)) {
423                     Item[] nodes = {this, textNode2};
424                     return new ArrayIterator(nodes);
425                 } else {
426                     return SingletonIterator.makeIterator(this);
427                 }
428
429             default:
430                  throw new IllegalArgumentException JavaDoc("Unknown axis number " + axisNumber);
431         }
432     }
433
434     /**
435      * Find the parent node of this node.
436      * @return The Node object describing the containing element or root node.
437      */

438
439     public NodeInfo getParent() {
440         return null;
441     }
442
443     /**
444     * Get the root node
445     * @return the NodeInfo representing the root of this tree
446     */

447
448     public NodeInfo getRoot() {
449         return this;
450     }
451
452     /**
453     * Get the root (document) node
454     * @return the DocumentInfo representing the containing document
455     */

456
457     public DocumentInfo getDocumentRoot() {
458         return this;
459     }
460
461     /**
462     * Copy the result tree fragment value to a given Outputter
463     */

464
465     public void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId)
466     throws XPathException {
467         out.characters(text, 0, 0);
468     }
469
470     /**
471     * Get the element with a given ID.
472     * @param id The unique ID of the required element
473     * @return null (this kind of tree contains no elements)
474     */

475
476     public NodeInfo selectID(String JavaDoc id) {
477         return null;
478     }
479
480     /**
481     * Get the unparsed entity with a given name
482     * @param name the name of the entity
483     * @return the URI and public ID of the entity if there is one, or null if not
484     */

485
486     public String JavaDoc[] getUnparsedEntity(String JavaDoc name) {
487         return null;
488     }
489
490
491     /**
492     * Make an instance of the text node
493     */

494
495     private TextFragmentTextNode getTextNode() {
496         if (textNode==null) {
497             textNode = new TextFragmentTextNode();
498         }
499         return textNode;
500     }
501
502     /**
503     * Inner class representing the text node; this is created on demand
504     */

505
506     private class TextFragmentTextNode implements NodeInfo, FingerprintedNode, SourceLocator JavaDoc {
507
508         /**
509         * Set the system ID for the entity containing the node.
510         */

511
512         public void setSystemId(String JavaDoc systemId) {}
513
514         /**
515          * Get the configuration
516          */

517
518         public Configuration getConfiguration() {
519             return config;
520         }
521
522         /**
523          * Get the name pool for this node
524          * @return the NamePool
525          */

526
527         public NamePool getNamePool() {
528             return config.getNamePool();
529         }
530
531         /**
532         * Return the type of node.
533         * @return Type.TEXT (always)
534         */

535
536         public final int getNodeKind() {
537             return Type.TEXT;
538         }
539
540         /**
541         * Get the String Value
542         */

543
544         public String JavaDoc getStringValue() {
545             return text.toString();
546         }
547
548         /**
549          * Get the value of the item as a CharSequence. This is in some cases more efficient than
550          * the version of the method that returns a String.
551          */

552
553         public CharSequence JavaDoc getStringValueCS() {
554             return text;
555         }
556
557         /**
558         * Determine whether this is the same node as another node
559         * @return true if this Node object and the supplied Node object represent the
560         * same node in the tree.
561         */

562
563         public boolean isSameNodeInfo(NodeInfo other) {
564             return this==other;
565         }
566
567         /**
568         * Get a character string that uniquely identifies this node
569         * @return a string.
570         */

571
572         public String JavaDoc generateId() {
573             return "tt" + getDocumentNumber() + "t1";
574         }
575
576         /**
577         * Get the system ID for the entity containing the node.
578         */

579
580         public String JavaDoc getSystemId() {
581             return systemId;
582         }
583
584         /**
585         * Get the base URI for the node. Default implementation for child nodes gets
586         * the base URI of the parent node.
587         */

588
589         public String JavaDoc getBaseURI() {
590             return systemId;
591         }
592
593         /**
594         * Determine the relative position of this node and another node, in document order.
595         * The other node will always be in the same document.
596         * @param other The other node, whose position is to be compared with this node
597         * @return -1 if this node precedes the other node, +1 if it follows the other
598         * node, or 0 if they are the same node. (In this case, isSameNode() will always
599         * return true, and the two nodes will produce the same result for generateId())
600         */

601
602         public int compareOrder(NodeInfo other) {
603             if (this==other) return 0;
604             return +1;
605         }
606
607         /**
608         * Get the name code of the node, used for displaying names
609         */

610
611         public int getNameCode() {
612             return -1;
613         }
614
615         /**
616         * Get the fingerprint of the node, used for matching names
617         */

618
619         public int getFingerprint() {
620             return -1;
621         }
622
623
624         /**
625         * Get the prefix part of the name of this node. This is the name before the ":" if any.
626         * @return the prefix part of the name. For an unnamed node, return "".
627         */

628
629         public String JavaDoc getPrefix() {
630             return "";
631         }
632
633         /**
634         * Get the URI part of the name of this node. This is the URI corresponding to the
635         * prefix, or the URI of the default namespace if appropriate.
636         * @return The URI of the namespace of this node. For an unnamed node, or for
637         * an element or attribute in the default namespace, return an empty string.
638         */

639
640         public String JavaDoc getURI() {
641             return "";
642         }
643
644         /**
645         * Get the display name of this node. For elements and attributes this is [prefix:]localname.
646         * For unnamed nodes, it is an empty string.
647         * @return The display name of this node.
648         * For a node with no name, return an empty string.
649         */

650
651         public String JavaDoc getDisplayName() {
652             return "";
653         }
654
655         /**
656         * Get the local name of this node.
657         * @return The local name of this node.
658         * For a node with no name, return "".
659         */

660
661         public String JavaDoc getLocalPart() {
662             return "";
663         }
664
665         /**
666         * Determine whether the node has any children.
667         * @return <code>true</code> if this node has any attributes,
668         * <code>false</code> otherwise.
669         */

670
671         public boolean hasChildNodes() {
672             return false;
673         }
674
675         /**
676         * Get the value of a given attribute of this node
677         * @param fingerprint The fingerprint of the attribute name
678         * @return the attribute value if it exists or null if not
679         */

680
681         public String JavaDoc getAttributeValue(int fingerprint) {
682             return null;
683         }
684
685         /**
686          * Get line number
687          *
688          * @return the line number of the node in its original source document; or
689          * -1 if not available
690          */

691
692         public int getLineNumber() {
693             return -1;
694         }
695
696         /**
697          * Get the type annotation of this node, if any.
698          * Returns -1 for kinds of nodes that have no annotation, and for elements annotated as
699          * untyped, and attributes annotated as untypedAtomic.
700          *
701          * @return the type annotation of the node.
702          * @see net.sf.saxon.type.Type
703          */

704
705         public int getTypeAnnotation() {
706             return -1;
707         }
708
709         /**
710          * Get the document number of the document containing this node. For a free-standing
711          * orphan node, just return the hashcode.
712          */

713
714         public int getDocumentNumber() {
715             return getDocumentRoot().getDocumentNumber();
716         }
717
718         /**
719          * Output all namespace nodes associated with this element. Does nothing if
720          * the node is not an element.
721          *
722          * @param out The relevant outputter
723          * @param includeAncestors True if namespaces declared on ancestor
724          */

725
726         public void sendNamespaceDeclarations(Receiver out, boolean includeAncestors) {
727         }
728
729         /**
730          * Get all namespace undeclarations and undeclarations defined on this element.
731          *
732          * @param buffer If this is non-null, and the result array fits in this buffer, then the result
733          * may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
734          * @return An array of integers representing the namespace declarations and undeclarations present on
735          * this element. For a node other than an element, return null. Otherwise, the returned array is a
736          * sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The
737          * top half word of each namespace code represents the prefix, the bottom half represents the URI.
738          * If the bottom half is zero, then this is a namespace undeclaration rather than a declaration.
739          * The XML namespace is never included in the list. If the supplied array is larger than required,
740          * then the first unused entry will be set to -1.
741          * <p/>
742          * <p>For a node other than an element, the method returns null.</p>
743          */

744
745         public int[] getDeclaredNamespaces(int[] buffer) {
746             return null;
747         }
748
749         /**
750          * Get the typed value of the item
751          *
752          * @return the typed value of the item. In general this will be a sequence
753          * @throws net.sf.saxon.trans.XPathException
754          * where no typed value is available, e.g. for
755          * an element with complex content
756          */

757
758         public SequenceIterator getTypedValue() throws XPathException {
759             return SingletonIterator.makeIterator(new UntypedAtomicValue(text));
760         }
761
762         /**
763          * Get the typed value. The result of this method will always be consistent with the method
764          * {@link net.sf.saxon.om.Item#getTypedValue()}. However, this method is often more convenient and may be
765          * more efficient, especially in the common case where the value is expected to be a singleton.
766          *
767          * @return the typed value. If requireSingleton is set to true, the result will always be an
768          * AtomicValue. In other cases it may be a Value representing a sequence whose items are atomic
769          * values.
770          * @since 8.5
771          */

772
773         public Value atomize() throws XPathException {
774             return new UntypedAtomicValue(text);
775         }
776
777         /**
778          * Return the public identifier for the current document event.
779          * <p/>
780          * <p>The return value is the public identifier of the document
781          * entity or of the external parsed entity in which the markup that
782          * triggered the event appears.</p>
783          *
784          * @return A string containing the public identifier, or
785          * null if none is available.
786          * @see #getSystemId
787          */

788         public String JavaDoc getPublicId() {
789             return null;
790         }
791
792         /**
793          * Return the character position where the current document event ends.
794          * <p/>
795          * <p><strong>Warning:</strong> The return value from the method
796          * is intended only as an approximation for the sake of error
797          * reporting; it is not intended to provide sufficient information
798          * to edit the character content of the original XML document.</p>
799          * <p/>
800          * <p>The return value is an approximation of the column number
801          * in the document entity or external parsed entity where the
802          * markup that triggered the event appears.</p>
803          *
804          * @return The column number, or -1 if none is available.
805          * @see #getLineNumber
806          */

807         public int getColumnNumber() {
808             return -1;
809         }
810
811         /**
812          * Return an enumeration over the nodes reached by the given axis from this node
813          * @param axisNumber the axis to be iterated over
814          * @return a AxisIterator that scans the nodes reached by the axis in turn.
815          */

816
817          public AxisIterator iterateAxis(byte axisNumber) {
818              switch (axisNumber) {
819                  case Axis.ANCESTOR:
820                  case Axis.PARENT:
821                  case Axis.PRECEDING_OR_ANCESTOR:
822                      return SingletonIterator.makeIterator(TextFragmentValue.this);
823
824                  case Axis.ANCESTOR_OR_SELF:
825                      Item[] nodes = {this, TextFragmentValue.this};
826                      return new ArrayIterator(nodes);
827
828                  case Axis.ATTRIBUTE:
829                  case Axis.CHILD:
830                  case Axis.DESCENDANT:
831                  case Axis.FOLLOWING:
832                  case Axis.FOLLOWING_SIBLING:
833                  case Axis.NAMESPACE:
834                  case Axis.PRECEDING:
835                  case Axis.PRECEDING_SIBLING:
836                      return EmptyIterator.getInstance();
837
838                  case Axis.SELF:
839                  case Axis.DESCENDANT_OR_SELF:
840                      return SingletonIterator.makeIterator(this);
841
842                  default:
843                       throw new IllegalArgumentException JavaDoc("Unknown axis number " + axisNumber);
844              }
845          }
846
847
848         /**
849         * Return an enumeration over the nodes reached by the given axis from this node
850         * @param axisNumber the axis to be iterated over
851         * @param nodeTest A pattern to be matched by the returned nodes
852         * @return a AxisIterator that scans the nodes reached by the axis in turn.
853         */

854
855         public AxisIterator iterateAxis( byte axisNumber, NodeTest nodeTest) {
856             switch (axisNumber) {
857                 case Axis.ANCESTOR:
858                 case Axis.PARENT:
859                 case Axis.PRECEDING_OR_ANCESTOR:
860                     if (nodeTest.matches(TextFragmentValue.this)) {
861                         return SingletonIterator.makeIterator(TextFragmentValue.this);
862                     } else {
863                         return EmptyIterator.getInstance();
864                     }
865
866                 case Axis.ANCESTOR_OR_SELF:
867                     boolean matchesDoc = nodeTest.matches(TextFragmentValue.this);
868                     boolean matchesText = nodeTest.matches(this);
869                     if (matchesDoc && matchesText) {
870                         Item[] nodes = {this, TextFragmentValue.this};
871                         return new ArrayIterator(nodes);
872                     } else if (matchesDoc && !matchesText) {
873                         return SingletonIterator.makeIterator(TextFragmentValue.this);
874                     } else if (matchesText && !matchesDoc) {
875                         return SingletonIterator.makeIterator(this);
876                     } else {
877                         return EmptyIterator.getInstance();
878                     }
879
880                 case Axis.ATTRIBUTE:
881                 case Axis.CHILD:
882                 case Axis.DESCENDANT:
883                 case Axis.FOLLOWING:
884                 case Axis.FOLLOWING_SIBLING:
885                 case Axis.NAMESPACE:
886                 case Axis.PRECEDING:
887                 case Axis.PRECEDING_SIBLING:
888                     return EmptyIterator.getInstance();
889
890                 case Axis.SELF:
891                 case Axis.DESCENDANT_OR_SELF:
892                     if (nodeTest.matches(this)) {
893                         return SingletonIterator.makeIterator(this);
894                     } else {
895                         return EmptyIterator.getInstance();
896                     }
897
898                 default:
899                      throw new IllegalArgumentException JavaDoc("Unknown axis number " + axisNumber);
900             }
901         }
902
903         /**
904          * Find the parent node of this node.
905          * @return The Node object describing the containing element or root node.
906          */

907
908         public NodeInfo getParent() {
909             return TextFragmentValue.this;
910         }
911
912         /**
913         * Get the root node
914         * @return the NodeInfo representing the root of this tree
915         */

916
917         public NodeInfo getRoot() {
918             return TextFragmentValue.this;
919         }
920
921         /**
922         * Get the root (document) node
923         * @return the DocumentInfo representing the containing document
924         */

925
926         public DocumentInfo getDocumentRoot() {
927             return TextFragmentValue.this;
928         }
929
930         /**
931         * Copy the node to a given Outputter
932         */

933
934         public void copy(Receiver out, int namespaces, boolean copyAnnotations, int locationId)
935         throws XPathException {
936             out.characters(text, 0, 0);
937         }
938
939     }
940
941 }
942
943 //
944
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
945
// you may not use this file except in compliance with the License. You may obtain a copy of the
946
// License at http://www.mozilla.org/MPL/
947
//
948
// Software distributed under the License is distributed on an "AS IS" basis,
949
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
950
// See the License for the specific language governing rights and limitations under the License.
951
//
952
// The Original Code is: all this file.
953
//
954
// The Initial Developer of the Original Code is Michael H. Kay.
955
//
956
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
957
//
958
// Contributor(s): none.
959
//
960

961
Popular Tags