KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > pattern > NoNodeTest


1 package net.sf.saxon.pattern;
2 import net.sf.saxon.om.Item;
3 import net.sf.saxon.om.NodeInfo;
4 import net.sf.saxon.type.Type;
5 import net.sf.saxon.type.ItemType;
6 import net.sf.saxon.tinytree.TinyTree;
7
8 /**
9   * NodeTest is an interface that enables a test of whether a node has a particular
10   * name and type. A NoNodeTest matches no nodes.
11   *
12   * @author Michael H. Kay
13   */

14
15 public final class NoNodeTest extends NodeTest {
16
17     private static NoNodeTest instance = new NoNodeTest();
18
19     /**
20     * Get a NoNodeTest instance
21     */

22
23     public static NoNodeTest getInstance() {
24         return instance;
25     }
26
27     public final int getPrimitiveType() {
28         return Type.EMPTY;
29     }
30
31     /**
32      * Get the primitive item type corresponding to this item type. For item(),
33      * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds,
34      * it is the value representing the node kind, for example Type.ELEMENT.
35      * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER.
36      * For other atomic types it is the primitive type as defined in XML Schema,
37      * except that INTEGER is considered to be a primitive type.
38      */

39
40     public ItemType getPrimitiveItemType() {
41         return this;
42     }
43
44     /**
45      * Test whether a given item conforms to this type
46      * @param item The item to be tested
47      * @return true if the item is an instance of this type; false otherwise
48     */

49
50     public boolean matchesItem(Item item) {
51         return false;
52     }
53
54
55     /**
56     * Test whether this node test is satisfied by a given node
57     * @param nodeType The type of node to be matched
58      * @param fingerprint identifies the expanded name of the node to be matched
59      */

60
61     public boolean matches(int nodeType, int fingerprint, int annotation) {
62         return false;
63     }
64
65     /**
66      * Test whether this node test is satisfied by a given node on a TinyTree. The node
67      * must be a document, element, text, comment, or processing instruction node.
68      * This method is provided
69      * so that when navigating a TinyTree a node can be rejected without
70      * actually instantiating a NodeInfo object.
71      *
72      * @param tree the TinyTree containing the node
73      * @param nodeNr the number of the node within the TinyTree
74      * @return true if the node matches the NodeTest, otherwise false
75      */

76
77     public boolean matches(TinyTree tree, int nodeNr) {
78         return false;
79     }
80
81     /**
82      * Test whether this node test is satisfied by a given node. This alternative
83      * method is used in the case of nodes where calculating the fingerprint is expensive,
84      * for example DOM or JDOM nodes.
85      * @param node the node to be matched
86      */

87
88     public boolean matches(NodeInfo node) {
89         return false;
90     }
91
92
93     /**
94     * Determine the default priority of this node test when used on its own as a Pattern
95     */

96
97     public final double getDefaultPriority() {
98         return -0.5;
99     }
100
101     /**
102      * Get a mask indicating which kinds of nodes this NodeTest can match. This is a combination
103      * of bits: 1<<Type.ELEMENT for element nodes, 1<<Type.TEXT for text nodes, and so on.
104      */

105
106     public int getNodeKindMask() {
107         return 0;
108     }
109
110     public String JavaDoc toString() {
111         return "empty()";
112     }
113
114     /**
115       * Returns a hash code value for the object.
116       */

117
118      public int hashCode() {
119          return "NoNodeTest".hashCode();
120      }
121
122
123 }
124
125 //
126
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
127
// you may not use this file except in compliance with the License. You may obtain a copy of the
128
// License at http://www.mozilla.org/MPL/
129
//
130
// Software distributed under the License is distributed on an "AS IS" basis,
131
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
132
// See the License for the specific language governing rights and limitations under the License.
133
//
134
// The Original Code is: all this file.
135
//
136
// The Initial Developer of the Original Code is Michael H. Kay.
137
//
138
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
139
//
140
// Contributor(s): none.
141
//
142
Popular Tags