KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.pattern;
2 import net.sf.saxon.om.NodeInfo;
3 import net.sf.saxon.type.Type;
4 import net.sf.saxon.tinytree.TinyTree;
5
6 /**
7 * An AnyChildNodePattern is the pattern node(), which matches any node except a root node,
8 * an attribute node, or a namespace node: in other words, any node that is the child of another
9 * node.
10 */

11
12 public final class AnyChildNodePattern extends NodeTest {
13
14     /**
15     * Test whether this node test is satisfied by a given node
16     * @param nodeKind The type of node to be matched
17      * @param fingerprint identifies the expanded name of the node to be matched
18      */

19
20     public boolean matches(int nodeKind, int fingerprint, int annotation) {
21         return (nodeKind == Type.ELEMENT ||
22                 nodeKind == Type.TEXT ||
23                 nodeKind == Type.COMMENT ||
24                 nodeKind == Type.PROCESSING_INSTRUCTION);
25     }
26
27     /**
28      * Test whether this node test is satisfied by a given node on a TinyTree. The node
29      * must be a document, element, text, comment, or processing instruction node.
30      * This method is provided
31      * so that when navigating a TinyTree a node can be rejected without
32      * actually instantiating a NodeInfo object.
33      *
34      * @param tree the TinyTree containing the node
35      * @param nodeNr the number of the node within the TinyTree
36      * @return true if the node matches the NodeTest, otherwise false
37      */

38
39     public boolean matches(TinyTree tree, int nodeNr) {
40         int nodeKind = tree.nodeKind[nodeNr];
41         return (nodeKind == Type.ELEMENT ||
42                 nodeKind == Type.TEXT ||
43                 nodeKind == Type.COMMENT ||
44                 nodeKind == Type.PROCESSING_INSTRUCTION);
45     }
46
47     /**
48      * Test whether this node test is satisfied by a given node. This alternative
49      * method is used in the case of nodes where calculating the fingerprint is expensive,
50      * for example DOM or JDOM nodes.
51      * @param node the node to be matched
52      */

53
54     public boolean matches(NodeInfo node) {
55         int nodeKind = node.getNodeKind();
56         return (nodeKind == Type.ELEMENT ||
57                 nodeKind == Type.TEXT ||
58                 nodeKind == Type.COMMENT ||
59                 nodeKind == Type.PROCESSING_INSTRUCTION);
60     }
61
62     /**
63     * Determine the default priority to use if this pattern appears as a match pattern
64     * for a template with no explicit priority attribute.
65     */

66
67     public double getDefaultPriority() {
68         return -0.5;
69     }
70
71     /**
72      * Get a mask indicating which kinds of nodes this NodeTest can match. This is a combination
73      * of bits: 1<<Type.ELEMENT for element nodes, 1<<Type.TEXT for text nodes, and so on.
74      */

75
76     public int getNodeKindMask() {
77         return 1<<Type.ELEMENT | 1<<Type.TEXT | 1<<Type.COMMENT | 1<<Type.PROCESSING_INSTRUCTION;
78     }
79
80     public String JavaDoc toString() {
81         return "node()";
82     }
83
84     /**
85      * Returns a hash code value for the object.
86      */

87
88     public int hashCode() {
89         return "AnyChildNodePattern".hashCode();
90     }
91
92 }
93
94 //
95
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
96
// you may not use this file except in compliance with the License. You may obtain a copy of the
97
// License at http://www.mozilla.org/MPL/
98
//
99
// Software distributed under the License is distributed on an "AS IS" basis,
100
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
101
// See the License for the specific language governing rights and limitations under the License.
102
//
103
// The Original Code is: all this file.
104
//
105
// The Initial Developer of the Original Code is Michael H. Kay.
106
//
107
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
108
//
109
// Contributor(s): none.
110
//
111
Popular Tags