KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > pattern > NodeTypeTest


1 package com.icl.saxon.pattern;
2 import com.icl.saxon.om.NodeInfo;
3 import com.icl.saxon.expr.XPathException;
4
5 /**
6   * NodeTest is an interface that enables a test of whether a node has a particular
7   * name and type. A NodeTypeTest matches the node type only.
8   *
9   * @author <A HREF="mailto:mhkay@iclway.co.uk>Michael H. Kay</A>
10   */

11
12 public class NodeTypeTest extends NodeTest {
13     
14     private short type;
15     
16     public NodeTypeTest(short nodeType) {
17         type = nodeType;
18         switch (nodeType) {
19             case NodeInfo.ROOT:
20                 originalText = "/";
21                 break;
22             case NodeInfo.ELEMENT:
23             case NodeInfo.ATTRIBUTE:
24                 originalText = "*";
25                 break;
26             case NodeInfo.COMMENT:
27                 originalText = "comment()";
28                 break;
29             case NodeInfo.TEXT:
30                 originalText = "text()";
31                 break;
32             case NodeInfo.PI:
33                 originalText = "processing-instruction()";
34                 break;
35             case NodeInfo.NAMESPACE:
36                 originalText = "namespace()";
37                 break;
38         }
39     }
40
41     /**
42     * Test whether this node test is satisfied by a given node
43     */

44
45     public final boolean matches(NodeInfo node) {
46         return type==node.getNodeType();
47     }
48
49     /**
50     * Test whether this node test is satisfied by a given node
51     * @param nodeType The type of node to be matched
52     * @param fingerprint identifies the expanded name of the node to be matched
53     */

54
55     public boolean matches(short nodeType, int fingerprint) {
56         return (type == nodeType);
57     }
58
59     /**
60     * Determine the default priority of this node test when used on its own as a Pattern
61     */

62
63     public final double getDefaultPriority() {
64         return -0.5;
65     }
66
67     /**
68     * Determine the types of nodes to which this pattern applies. Used for optimisation.
69     * @return the type of node matched by this pattern. e.g. NodeInfo.ELEMENT or NodeInfo.TEXT
70     */

71
72     public short getNodeType() {
73         return type;
74     }
75
76 }
77
78 //
79
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
80
// you may not use this file except in compliance with the License. You may obtain a copy of the
81
// License at http://www.mozilla.org/MPL/
82
//
83
// Software distributed under the License is distributed on an "AS IS" basis,
84
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
85
// See the License for the specific language governing rights and limitations under the License.
86
//
87
// The Original Code is: all this file.
88
//
89
// The Initial Developer of the Original Code is
90
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
91
//
92
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
93
//
94
// Contributor(s): none.
95
//
96
Popular Tags