Source Code Cross Referenced for TextFragmentValue.java in  » XML » saxonb » net » sf » saxon » value » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » saxonb » net.sf.saxon.value 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.saxon.value;
002:
003:        import net.sf.saxon.Configuration;
004:        import net.sf.saxon.event.Receiver;
005:        import net.sf.saxon.om.*;
006:        import net.sf.saxon.pattern.NodeTest;
007:        import net.sf.saxon.trans.XPathException;
008:        import net.sf.saxon.type.Type;
009:
010:        import javax.xml.transform.SourceLocator;
011:
012:        /**
013:         * This class represents a temporary tree whose root document node owns a single text node. <BR>
014:         */
015:
016:        public final class TextFragmentValue implements  DocumentInfo,
017:                FingerprintedNode, SourceLocator {
018:
019:            private CharSequence text;
020:            private String systemId;
021:            private TextFragmentTextNode textNode = null; // created on demand
022:            private Configuration config;
023:            private int documentNumber;
024:
025:            /**
026:             * Constructor: create a result tree fragment containing a single text node
027:             * @param value a String containing the value
028:             */
029:
030:            public TextFragmentValue(CharSequence value, String systemId) {
031:                this .text = value;
032:                this .systemId = systemId;
033:            }
034:
035:            /**
036:             * Set the configuration (containing the name pool used for all names in this document)
037:             */
038:
039:            public void setConfiguration(Configuration config) {
040:                this .config = config;
041:                documentNumber = -1; // the document number is allocated lazily because it can cause
042:                // contention on the NamePool and is often not needed.
043:            }
044:
045:            /**
046:             * Get the configuration previously set using setConfiguration
047:             * (or the default configuraton allocated automatically)
048:             */
049:
050:            public Configuration getConfiguration() {
051:                return config;
052:            }
053:
054:            /**
055:             * Get the name pool used for the names in this document
056:             */
057:
058:            public NamePool getNamePool() {
059:                return config.getNamePool();
060:            }
061:
062:            /**
063:             * Get the unique document number
064:             */
065:
066:            public int getDocumentNumber() {
067:                if (documentNumber == -1) {
068:                    documentNumber = config.getDocumentNumberAllocator()
069:                            .allocateDocumentNumber();
070:                    // technically this isn't thread-safe; however, TextFragmentValues are invariably used within
071:                    // a single thread
072:                }
073:                return documentNumber;
074:            }
075:
076:            /**
077:             * Return the type of node.
078:             * @return Type.DOCUMENT (always)
079:             */
080:
081:            public final int getNodeKind() {
082:                return Type.DOCUMENT;
083:            }
084:
085:            /**
086:             * Get the String Value
087:             */
088:
089:            public String getStringValue() {
090:                return text.toString();
091:            }
092:
093:            /**
094:             * Get the value of the item as a CharSequence. This is in some cases more efficient than
095:             * the version of the method that returns a String.
096:             */
097:
098:            public CharSequence getStringValueCS() {
099:                return text;
100:            }
101:
102:            /**
103:             * Determine whether this is the same node as another node
104:             * @return true if this Node object and the supplied Node object represent the
105:             * same node in the tree.
106:             */
107:
108:            public boolean isSameNodeInfo(NodeInfo other) {
109:                return this  == other;
110:            }
111:
112:            /**
113:             * Get a character string that uniquely identifies this node
114:             * @return a string.
115:             */
116:
117:            public String generateId() {
118:                return "tt" + getDocumentNumber();
119:            }
120:
121:            /**
122:             * Set the system ID for the entity containing the node.
123:             */
124:
125:            public void setSystemId(String systemId) {
126:                this .systemId = systemId;
127:            }
128:
129:            /**
130:             * Get the system ID for the entity containing the node.
131:             */
132:
133:            public String getSystemId() {
134:                return systemId;
135:            }
136:
137:            /**
138:             * Get the base URI for the node. Default implementation for child nodes gets
139:             * the base URI of the parent node.
140:             */
141:
142:            public String getBaseURI() {
143:                return systemId;
144:            }
145:
146:            /**
147:             * Determine the relative position of this node and another node, in document order.
148:             * The other node will always be in the same document.
149:             * @param other The other node, whose position is to be compared with this node
150:             * @return -1 if this node precedes the other node, +1 if it follows the other
151:             * node, or 0 if they are the same node. (In this case, isSameNode() will always
152:             * return true, and the two nodes will produce the same result for generateId())
153:             */
154:
155:            public int compareOrder(NodeInfo other) {
156:                if (this  == other)
157:                    return 0;
158:                return -1;
159:            }
160:
161:            /**
162:             * Get the name code of the node, used for displaying names
163:             */
164:
165:            public int getNameCode() {
166:                return -1;
167:            }
168:
169:            /**
170:             * Get the fingerprint of the node, used for matching names
171:             */
172:
173:            public int getFingerprint() {
174:                return -1;
175:            }
176:
177:            /**
178:             * Get the prefix part of the name of this node. This is the name before the ":" if any.
179:             * @return the prefix part of the name. For an unnamed node, return "".
180:             */
181:
182:            public String getPrefix() {
183:                return "";
184:            }
185:
186:            /**
187:             * Get the URI part of the name of this node. This is the URI corresponding to the
188:             * prefix, or the URI of the default namespace if appropriate.
189:             * @return The URI of the namespace of this node. For an unnamed node, or for
190:             * an element or attribute in the default namespace, return an empty string.
191:             */
192:
193:            public String getURI() {
194:                return "";
195:            }
196:
197:            /**
198:             * Get the display name of this node. For elements and attributes this is [prefix:]localname.
199:             * For unnamed nodes, it is an empty string.
200:             * @return The display name of this node.
201:             * For a node with no name, return an empty string.
202:             */
203:
204:            public String getDisplayName() {
205:                return "";
206:            }
207:
208:            /**
209:             * Get the local name of this node.
210:             * @return The local name of this node.
211:             * For a node with no name, return "".
212:             */
213:
214:            public String getLocalPart() {
215:                return "";
216:            }
217:
218:            /**
219:             * Determine whether the node has any children.
220:             * @return <code>true</code> if this node has any attributes,
221:             *   <code>false</code> otherwise.
222:             */
223:
224:            public boolean hasChildNodes() {
225:                return !("".equals(text));
226:            }
227:
228:            /**
229:             * Get line number
230:             *
231:             * @return the line number of the node in its original source document; or
232:             *         -1 if not available
233:             */
234:
235:            public int getLineNumber() {
236:                return -1;
237:            }
238:
239:            /**
240:             * Get the type annotation of this node, if any.
241:             * Returns -1 for kinds of nodes that have no annotation, and for elements annotated as
242:             * untyped, and attributes annotated as untypedAtomic.
243:             *
244:             * @return the type annotation of the node.
245:             * @see net.sf.saxon.type.Type
246:             */
247:
248:            public int getTypeAnnotation() {
249:                return -1;
250:            }
251:
252:            /**
253:             * Output all namespace nodes associated with this element. Does nothing if
254:             * the node is not an element.
255:             *
256:             * @param out              The relevant outputter
257:             * @param includeAncestors True if namespaces declared on ancestor
258:             */
259:
260:            public void sendNamespaceDeclarations(Receiver out,
261:                    boolean includeAncestors) {
262:            }
263:
264:            /**
265:             * Get all namespace undeclarations and undeclarations defined on this element.
266:             *
267:             * @param buffer If this is non-null, and the result array fits in this buffer, then the result
268:             *               may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
269:             * @return An array of integers representing the namespace declarations and undeclarations present on
270:             *         this element. For a node other than an element, return null. Otherwise, the returned array is a
271:             *         sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The
272:             *         top half word of each namespace code represents the prefix, the bottom half represents the URI.
273:             *         If the bottom half is zero, then this is a namespace undeclaration rather than a declaration.
274:             *         The XML namespace is never included in the list. If the supplied array is larger than required,
275:             *         then the first unused entry will be set to -1.
276:             *         <p/>
277:             *         <p>For a node other than an element, the method returns null.</p>
278:             */
279:
280:            public int[] getDeclaredNamespaces(int[] buffer) {
281:                return null;
282:            }
283:
284:            /**
285:             * Get the typed value of the item
286:             *
287:             * @return the typed value of the item. In general this will be a sequence
288:             */
289:
290:            public SequenceIterator getTypedValue() {
291:                return SingletonIterator.makeIterator(new UntypedAtomicValue(
292:                        text));
293:            }
294:
295:            /**
296:             * Get the typed value. The result of this method will always be consistent with the method
297:             * {@link net.sf.saxon.om.Item#getTypedValue()}. However, this method is often more convenient and may be
298:             * more efficient, especially in the common case where the value is expected to be a singleton.
299:             *
300:             * @return the typed value. If requireSingleton is set to true, the result will always be an
301:             *         AtomicValue. In other cases it may be a Value representing a sequence whose items are atomic
302:             *         values.
303:             * @since 8.5
304:             */
305:
306:            public Value atomize() {
307:                return new UntypedAtomicValue(text);
308:            }
309:
310:            /**
311:             * Return the public identifier for the current document event.
312:             * <p/>
313:             * <p>The return value is the public identifier of the document
314:             * entity or of the external parsed entity in which the markup that
315:             * triggered the event appears.</p>
316:             *
317:             * @return A string containing the public identifier, or
318:             *         null if none is available.
319:             * @see #getSystemId
320:             */
321:            public String getPublicId() {
322:                return null;
323:            }
324:
325:            /**
326:             * Return the character position where the current document event ends.
327:             * <p/>
328:             * <p><strong>Warning:</strong> The return value from the method
329:             * is intended only as an approximation for the sake of error
330:             * reporting; it is not intended to provide sufficient information
331:             * to edit the character content of the original XML document.</p>
332:             * <p/>
333:             * <p>The return value is an approximation of the column number
334:             * in the document entity or external parsed entity where the
335:             * markup that triggered the event appears.</p>
336:             *
337:             * @return The column number, or -1 if none is available.
338:             * @see #getLineNumber
339:             */
340:            public int getColumnNumber() {
341:                return -1;
342:            }
343:
344:            /**
345:             * Get the value of a given attribute of this node
346:             * @param fingerprint The fingerprint of the attribute name
347:             * @return the attribute value if it exists or null if not
348:             */
349:
350:            public String getAttributeValue(int fingerprint) {
351:                return null;
352:            }
353:
354:            /**
355:             * Return an iteration over the nodes reached by the given axis from this node
356:             * @param axisNumber The axis to be iterated over
357:             * @return a AxisIterator that scans the nodes reached by the axis in turn.
358:             * @see net.sf.saxon.om.Axis
359:             */
360:
361:            public AxisIterator iterateAxis(byte axisNumber) {
362:                switch (axisNumber) {
363:                case Axis.ANCESTOR:
364:                case Axis.ATTRIBUTE:
365:                case Axis.FOLLOWING:
366:                case Axis.FOLLOWING_SIBLING:
367:                case Axis.NAMESPACE:
368:                case Axis.PARENT:
369:                case Axis.PRECEDING:
370:                case Axis.PRECEDING_SIBLING:
371:                case Axis.PRECEDING_OR_ANCESTOR:
372:                    return EmptyIterator.getInstance();
373:
374:                case Axis.SELF:
375:                case Axis.ANCESTOR_OR_SELF:
376:                    return SingletonIterator.makeIterator(this );
377:
378:                case Axis.CHILD:
379:                case Axis.DESCENDANT:
380:                    return SingletonIterator.makeIterator(getTextNode());
381:
382:                case Axis.DESCENDANT_OR_SELF:
383:                    Item[] nodes = { this , getTextNode() };
384:                    return new ArrayIterator(nodes);
385:
386:                default:
387:                    throw new IllegalArgumentException("Unknown axis number "
388:                            + axisNumber);
389:                }
390:            }
391:
392:            /**
393:             * Return an enumeration over the nodes reached by the given axis from this node
394:             * @param axisNumber The axis to be iterated over
395:             * @param nodeTest A pattern to be matched by the returned nodes
396:             * @return a AxisIterator that scans the nodes reached by the axis in turn.
397:             * @see net.sf.saxon.om.Axis
398:             */
399:
400:            public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) {
401:                switch (axisNumber) {
402:                case Axis.ANCESTOR:
403:                case Axis.ATTRIBUTE:
404:                case Axis.FOLLOWING:
405:                case Axis.FOLLOWING_SIBLING:
406:                case Axis.NAMESPACE:
407:                case Axis.PARENT:
408:                case Axis.PRECEDING:
409:                case Axis.PRECEDING_SIBLING:
410:                case Axis.PRECEDING_OR_ANCESTOR:
411:                    return EmptyIterator.getInstance();
412:
413:                case Axis.SELF:
414:                case Axis.ANCESTOR_OR_SELF:
415:                    return SingletonIterator.makeIterator(this );
416:
417:                case Axis.CHILD:
418:                case Axis.DESCENDANT:
419:                    NodeInfo textNode = getTextNode();
420:                    if (nodeTest.matches(textNode)) {
421:                        return SingletonIterator.makeIterator(textNode);
422:                    } else {
423:                        return EmptyIterator.getInstance();
424:                    }
425:
426:                case Axis.DESCENDANT_OR_SELF:
427:                    NodeInfo textNode2 = getTextNode();
428:                    if (nodeTest.matches(textNode2)) {
429:                        Item[] nodes = { this , textNode2 };
430:                        return new ArrayIterator(nodes);
431:                    } else {
432:                        return SingletonIterator.makeIterator(this );
433:                    }
434:
435:                default:
436:                    throw new IllegalArgumentException("Unknown axis number "
437:                            + axisNumber);
438:                }
439:            }
440:
441:            /**
442:             * Find the parent node of this node.
443:             * @return The Node object describing the containing element or root node.
444:             */
445:
446:            public NodeInfo getParent() {
447:                return null;
448:            }
449:
450:            /**
451:             * Get the root node
452:             * @return the NodeInfo representing the root of this tree
453:             */
454:
455:            public NodeInfo getRoot() {
456:                return this ;
457:            }
458:
459:            /**
460:             * Get the root (document) node
461:             * @return the DocumentInfo representing the containing document
462:             */
463:
464:            public DocumentInfo getDocumentRoot() {
465:                return this ;
466:            }
467:
468:            /**
469:             * Copy the result tree fragment value to a given Outputter
470:             */
471:
472:            public void copy(Receiver out, int whichNamespaces,
473:                    boolean copyAnnotations, int locationId)
474:                    throws XPathException {
475:                out.characters(text, 0, 0);
476:            }
477:
478:            /**
479:             * Get the element with a given ID.
480:             * @param id The unique ID of the required element
481:             * @return null (this kind of tree contains no elements)
482:             */
483:
484:            public NodeInfo selectID(String id) {
485:                return null;
486:            }
487:
488:            /**
489:             * Get the unparsed entity with a given name
490:             * @param name the name of the entity
491:             * @return the URI and public ID of the entity if there is one, or null if not
492:             */
493:
494:            public String[] getUnparsedEntity(String name) {
495:                return null;
496:            }
497:
498:            /**
499:             * Make an instance of the text node
500:             */
501:
502:            private TextFragmentTextNode getTextNode() {
503:                if (textNode == null) {
504:                    textNode = new TextFragmentTextNode();
505:                }
506:                return textNode;
507:            }
508:
509:            /**
510:             * Inner class representing the text node; this is created on demand
511:             */
512:
513:            private class TextFragmentTextNode implements  NodeInfo,
514:                    FingerprintedNode, SourceLocator {
515:
516:                /**
517:                 * Set the system ID for the entity containing the node.
518:                 */
519:
520:                public void setSystemId(String systemId) {
521:                }
522:
523:                /**
524:                 * Get the configuration
525:                 */
526:
527:                public Configuration getConfiguration() {
528:                    return config;
529:                }
530:
531:                /**
532:                 * Get the name pool for this node
533:                 * @return the NamePool
534:                 */
535:
536:                public NamePool getNamePool() {
537:                    return config.getNamePool();
538:                }
539:
540:                /**
541:                 * Return the type of node.
542:                 * @return Type.TEXT (always)
543:                 */
544:
545:                public final int getNodeKind() {
546:                    return Type.TEXT;
547:                }
548:
549:                /**
550:                 * Get the String Value
551:                 */
552:
553:                public String getStringValue() {
554:                    return text.toString();
555:                }
556:
557:                /**
558:                 * Get the value of the item as a CharSequence. This is in some cases more efficient than
559:                 * the version of the method that returns a String.
560:                 */
561:
562:                public CharSequence getStringValueCS() {
563:                    return text;
564:                }
565:
566:                /**
567:                 * Determine whether this is the same node as another node
568:                 * @return true if this Node object and the supplied Node object represent the
569:                 * same node in the tree.
570:                 */
571:
572:                public boolean isSameNodeInfo(NodeInfo other) {
573:                    return this  == other;
574:                }
575:
576:                /**
577:                 * Get a character string that uniquely identifies this node
578:                 * @return a string.
579:                 */
580:
581:                public String generateId() {
582:                    return "tt" + getDocumentNumber() + "t1";
583:                }
584:
585:                /**
586:                 * Get the system ID for the entity containing the node.
587:                 */
588:
589:                public String getSystemId() {
590:                    return systemId;
591:                }
592:
593:                /**
594:                 * Get the base URI for the node. Default implementation for child nodes gets
595:                 * the base URI of the parent node.
596:                 */
597:
598:                public String getBaseURI() {
599:                    return systemId;
600:                }
601:
602:                /**
603:                 * Determine the relative position of this node and another node, in document order.
604:                 * The other node will always be in the same document.
605:                 * @param other The other node, whose position is to be compared with this node
606:                 * @return -1 if this node precedes the other node, +1 if it follows the other
607:                 * node, or 0 if they are the same node. (In this case, isSameNode() will always
608:                 * return true, and the two nodes will produce the same result for generateId())
609:                 */
610:
611:                public int compareOrder(NodeInfo other) {
612:                    if (this  == other)
613:                        return 0;
614:                    return +1;
615:                }
616:
617:                /**
618:                 * Get the name code of the node, used for displaying names
619:                 */
620:
621:                public int getNameCode() {
622:                    return -1;
623:                }
624:
625:                /**
626:                 * Get the fingerprint of the node, used for matching names
627:                 */
628:
629:                public int getFingerprint() {
630:                    return -1;
631:                }
632:
633:                /**
634:                 * Get the prefix part of the name of this node. This is the name before the ":" if any.
635:                 * @return the prefix part of the name. For an unnamed node, return "".
636:                 */
637:
638:                public String getPrefix() {
639:                    return "";
640:                }
641:
642:                /**
643:                 * Get the URI part of the name of this node. This is the URI corresponding to the
644:                 * prefix, or the URI of the default namespace if appropriate.
645:                 * @return The URI of the namespace of this node. For an unnamed node, or for
646:                 * an element or attribute in the default namespace, return an empty string.
647:                 */
648:
649:                public String getURI() {
650:                    return "";
651:                }
652:
653:                /**
654:                 * Get the display name of this node. For elements and attributes this is [prefix:]localname.
655:                 * For unnamed nodes, it is an empty string.
656:                 * @return The display name of this node.
657:                 * For a node with no name, return an empty string.
658:                 */
659:
660:                public String getDisplayName() {
661:                    return "";
662:                }
663:
664:                /**
665:                 * Get the local name of this node.
666:                 * @return The local name of this node.
667:                 * For a node with no name, return "".
668:                 */
669:
670:                public String getLocalPart() {
671:                    return "";
672:                }
673:
674:                /**
675:                 * Determine whether the node has any children.
676:                 * @return <code>true</code> if this node has any attributes,
677:                 *   <code>false</code> otherwise.
678:                 */
679:
680:                public boolean hasChildNodes() {
681:                    return false;
682:                }
683:
684:                /**
685:                 * Get the value of a given attribute of this node
686:                 * @param fingerprint The fingerprint of the attribute name
687:                 * @return the attribute value if it exists or null if not
688:                 */
689:
690:                public String getAttributeValue(int fingerprint) {
691:                    return null;
692:                }
693:
694:                /**
695:                 * Get line number
696:                 *
697:                 * @return the line number of the node in its original source document; or
698:                 *         -1 if not available
699:                 */
700:
701:                public int getLineNumber() {
702:                    return -1;
703:                }
704:
705:                /**
706:                 * Get the type annotation of this node, if any.
707:                 * Returns -1 for kinds of nodes that have no annotation, and for elements annotated as
708:                 * untyped, and attributes annotated as untypedAtomic.
709:                 *
710:                 * @return the type annotation of the node.
711:                 * @see net.sf.saxon.type.Type
712:                 */
713:
714:                public int getTypeAnnotation() {
715:                    return -1;
716:                }
717:
718:                /**
719:                 * Get the document number of the document containing this node. For a free-standing
720:                 * orphan node, just return the hashcode.
721:                 */
722:
723:                public int getDocumentNumber() {
724:                    return getDocumentRoot().getDocumentNumber();
725:                }
726:
727:                /**
728:                 * Output all namespace nodes associated with this element. Does nothing if
729:                 * the node is not an element.
730:                 *
731:                 * @param out              The relevant outputter
732:                 * @param includeAncestors True if namespaces declared on ancestor
733:                 */
734:
735:                public void sendNamespaceDeclarations(Receiver out,
736:                        boolean includeAncestors) {
737:                }
738:
739:                /**
740:                 * Get all namespace undeclarations and undeclarations defined on this element.
741:                 *
742:                 * @param buffer If this is non-null, and the result array fits in this buffer, then the result
743:                 *               may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
744:                 * @return An array of integers representing the namespace declarations and undeclarations present on
745:                 *         this element. For a node other than an element, return null. Otherwise, the returned array is a
746:                 *         sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The
747:                 *         top half word of each namespace code represents the prefix, the bottom half represents the URI.
748:                 *         If the bottom half is zero, then this is a namespace undeclaration rather than a declaration.
749:                 *         The XML namespace is never included in the list. If the supplied array is larger than required,
750:                 *         then the first unused entry will be set to -1.
751:                 *         <p/>
752:                 *         <p>For a node other than an element, the method returns null.</p>
753:                 */
754:
755:                public int[] getDeclaredNamespaces(int[] buffer) {
756:                    return null;
757:                }
758:
759:                /**
760:                 * Get the typed value of the item
761:                 *
762:                 * @return the typed value of the item. In general this will be a sequence
763:                 * @throws net.sf.saxon.trans.XPathException
764:                 *          where no typed value is available, e.g. for
765:                 *          an element with complex content
766:                 */
767:
768:                public SequenceIterator getTypedValue() throws XPathException {
769:                    return SingletonIterator
770:                            .makeIterator(new UntypedAtomicValue(text));
771:                }
772:
773:                /**
774:                 * Get the typed value. The result of this method will always be consistent with the method
775:                 * {@link net.sf.saxon.om.Item#getTypedValue()}. However, this method is often more convenient and may be
776:                 * more efficient, especially in the common case where the value is expected to be a singleton.
777:                 *
778:                 * @return the typed value. If requireSingleton is set to true, the result will always be an
779:                 *         AtomicValue. In other cases it may be a Value representing a sequence whose items are atomic
780:                 *         values.
781:                 * @since 8.5
782:                 */
783:
784:                public Value atomize() throws XPathException {
785:                    return new UntypedAtomicValue(text);
786:                }
787:
788:                /**
789:                 * Return the public identifier for the current document event.
790:                 * <p/>
791:                 * <p>The return value is the public identifier of the document
792:                 * entity or of the external parsed entity in which the markup that
793:                 * triggered the event appears.</p>
794:                 *
795:                 * @return A string containing the public identifier, or
796:                 *         null if none is available.
797:                 * @see #getSystemId
798:                 */
799:                public String getPublicId() {
800:                    return null;
801:                }
802:
803:                /**
804:                 * Return the character position where the current document event ends.
805:                 * <p/>
806:                 * <p><strong>Warning:</strong> The return value from the method
807:                 * is intended only as an approximation for the sake of error
808:                 * reporting; it is not intended to provide sufficient information
809:                 * to edit the character content of the original XML document.</p>
810:                 * <p/>
811:                 * <p>The return value is an approximation of the column number
812:                 * in the document entity or external parsed entity where the
813:                 * markup that triggered the event appears.</p>
814:                 *
815:                 * @return The column number, or -1 if none is available.
816:                 * @see #getLineNumber
817:                 */
818:                public int getColumnNumber() {
819:                    return -1;
820:                }
821:
822:                /**
823:                 * Return an enumeration over the nodes reached by the given axis from this node
824:                 * @param axisNumber the axis to be iterated over
825:                 * @return a AxisIterator that scans the nodes reached by the axis in turn.
826:                 */
827:
828:                public AxisIterator iterateAxis(byte axisNumber) {
829:                    switch (axisNumber) {
830:                    case Axis.ANCESTOR:
831:                    case Axis.PARENT:
832:                    case Axis.PRECEDING_OR_ANCESTOR:
833:                        return SingletonIterator
834:                                .makeIterator(TextFragmentValue.this );
835:
836:                    case Axis.ANCESTOR_OR_SELF:
837:                        Item[] nodes = { this , TextFragmentValue.this  };
838:                        return new ArrayIterator(nodes);
839:
840:                    case Axis.ATTRIBUTE:
841:                    case Axis.CHILD:
842:                    case Axis.DESCENDANT:
843:                    case Axis.FOLLOWING:
844:                    case Axis.FOLLOWING_SIBLING:
845:                    case Axis.NAMESPACE:
846:                    case Axis.PRECEDING:
847:                    case Axis.PRECEDING_SIBLING:
848:                        return EmptyIterator.getInstance();
849:
850:                    case Axis.SELF:
851:                    case Axis.DESCENDANT_OR_SELF:
852:                        return SingletonIterator.makeIterator(this );
853:
854:                    default:
855:                        throw new IllegalArgumentException(
856:                                "Unknown axis number " + axisNumber);
857:                    }
858:                }
859:
860:                /**
861:                 * Return an enumeration over the nodes reached by the given axis from this node
862:                 * @param axisNumber the axis to be iterated over
863:                 * @param nodeTest A pattern to be matched by the returned nodes
864:                 * @return a AxisIterator that scans the nodes reached by the axis in turn.
865:                 */
866:
867:                public AxisIterator iterateAxis(byte axisNumber,
868:                        NodeTest nodeTest) {
869:                    switch (axisNumber) {
870:                    case Axis.ANCESTOR:
871:                    case Axis.PARENT:
872:                    case Axis.PRECEDING_OR_ANCESTOR:
873:                        if (nodeTest.matches(TextFragmentValue.this )) {
874:                            return SingletonIterator
875:                                    .makeIterator(TextFragmentValue.this );
876:                        } else {
877:                            return EmptyIterator.getInstance();
878:                        }
879:
880:                    case Axis.ANCESTOR_OR_SELF:
881:                        boolean matchesDoc = nodeTest
882:                                .matches(TextFragmentValue.this );
883:                        boolean matchesText = nodeTest.matches(this );
884:                        if (matchesDoc && matchesText) {
885:                            Item[] nodes = { this , TextFragmentValue.this  };
886:                            return new ArrayIterator(nodes);
887:                        } else if (matchesDoc && !matchesText) {
888:                            return SingletonIterator
889:                                    .makeIterator(TextFragmentValue.this );
890:                        } else if (matchesText && !matchesDoc) {
891:                            return SingletonIterator.makeIterator(this );
892:                        } else {
893:                            return EmptyIterator.getInstance();
894:                        }
895:
896:                    case Axis.ATTRIBUTE:
897:                    case Axis.CHILD:
898:                    case Axis.DESCENDANT:
899:                    case Axis.FOLLOWING:
900:                    case Axis.FOLLOWING_SIBLING:
901:                    case Axis.NAMESPACE:
902:                    case Axis.PRECEDING:
903:                    case Axis.PRECEDING_SIBLING:
904:                        return EmptyIterator.getInstance();
905:
906:                    case Axis.SELF:
907:                    case Axis.DESCENDANT_OR_SELF:
908:                        if (nodeTest.matches(this )) {
909:                            return SingletonIterator.makeIterator(this );
910:                        } else {
911:                            return EmptyIterator.getInstance();
912:                        }
913:
914:                    default:
915:                        throw new IllegalArgumentException(
916:                                "Unknown axis number " + axisNumber);
917:                    }
918:                }
919:
920:                /**
921:                 * Find the parent node of this node.
922:                 * @return The Node object describing the containing element or root node.
923:                 */
924:
925:                public NodeInfo getParent() {
926:                    return TextFragmentValue.this ;
927:                }
928:
929:                /**
930:                 * Get the root node
931:                 * @return the NodeInfo representing the root of this tree
932:                 */
933:
934:                public NodeInfo getRoot() {
935:                    return TextFragmentValue.this ;
936:                }
937:
938:                /**
939:                 * Get the root (document) node
940:                 * @return the DocumentInfo representing the containing document
941:                 */
942:
943:                public DocumentInfo getDocumentRoot() {
944:                    return TextFragmentValue.this ;
945:                }
946:
947:                /**
948:                 * Copy the node to a given Outputter
949:                 */
950:
951:                public void copy(Receiver out, int namespaces,
952:                        boolean copyAnnotations, int locationId)
953:                        throws XPathException {
954:                    out.characters(text, 0, 0);
955:                }
956:
957:            }
958:
959:        }
960:
961:        //
962:        // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
963:        // you may not use this file except in compliance with the License. You may obtain a copy of the
964:        // License at http://www.mozilla.org/MPL/
965:        //
966:        // Software distributed under the License is distributed on an "AS IS" basis,
967:        // WITHOUT WARRANTY OF ANY KIND, either express or implied.
968:        // See the License for the specific language governing rights and limitations under the License.
969:        //
970:        // The Original Code is: all this file.
971:        //
972:        // The Initial Developer of the Original Code is Michael H. Kay.
973:        //
974:        // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
975:        //
976:        // Contributor(s): none.
977:        //
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.