KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.pattern;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.om.NodeInfo;
4
5 /**
6   * A NodeTestPattern is a pattern that consists simply of a NodeTest.
7   * @author Michael H. Kay
8   */

9
10 public class NodeTestPattern extends Pattern {
11
12     private NodeTest nodeTest;
13
14     public NodeTestPattern() {}
15
16     public NodeTestPattern(NodeTest test) {
17         nodeTest = test;
18     }
19
20     public void setNodeTest(NodeTest test) {
21         nodeTest = test;
22     }
23
24     /**
25     * Determine whether this Pattern matches the given Node. This is the main external interface
26     * for matching patterns: it sets current() to the node being tested
27     * @param node The NodeInfo representing the Element or other node to be tested against the Pattern
28     * @param context The context in which the match is to take place. Only relevant if the pattern
29     * uses variables, or contains calls on functions such as document() or key(). Not used (and can be
30      * set to null) in the case of patterns that are NodeTests
31     * @return true if the node matches the Pattern, false otherwise
32     */

33
34     public boolean matches(NodeInfo node, XPathContext context) {
35         return nodeTest.matches(node);
36     }
37
38     /**
39     * Get a NodeTest that all the nodes matching this pattern must satisfy
40     */

41
42     public NodeTest getNodeTest() {
43         return nodeTest;
44     }
45
46     /**
47     * Determine the default priority of this node test when used on its own as a Pattern
48     */

49
50     public final double getDefaultPriority() {
51         return nodeTest.getDefaultPriority();
52     }
53
54     /**
55      * Determine the types of nodes to which this pattern applies. Used for optimisation.
56      * For patterns that match nodes of several types, return Type.NODE
57      *
58      * @return the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT
59      */

60
61     public int getNodeKind() {
62         return nodeTest.getPrimitiveType();
63     }
64
65     /**
66      * Determine the name fingerprint of nodes to which this pattern applies. Used for
67      * optimisation.
68      *
69      * @return A fingerprint that the nodes must match, or -1 if it can match multiple fingerprints
70      */

71
72     public int getFingerprint() {
73         return nodeTest.getFingerprint();
74     }
75
76     /**
77      * Display the pattern for diagnostics
78      */

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