KickJava   Java API By Example, From Geeks To Geeks.

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


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

12
13 public final class NamespaceTest extends NodeTest {
14     
15     private NamePool namePool;
16     private short type;
17     private short uriCode;
18     
19     public NamespaceTest(NamePool pool, short nodeType, short uriCode) {
20         namePool = pool;
21         type = nodeType;
22         this.uriCode = uriCode;
23     }
24
25     /**
26     * Test whether this node test is satisfied by a given node
27     */

28
29     public final boolean matches(NodeInfo node) {
30         int fingerprint = node.getFingerprint();
31         if (fingerprint == -1) return false;
32         return type == node.getNodeType() &&
33                uriCode == namePool.getURICode(fingerprint);
34     }
35
36     /**
37     * Test whether this node test is satisfied by a given node
38     * @param nodeType The type of node to be matched
39     * @param fingerprint identifies the expanded name of the node to be matched
40     */

41
42     public boolean matches(short nodeType, int fingerprint) {
43         if (fingerprint == -1) return false;
44         if (nodeType != type) return false;
45         return uriCode == namePool.getURICode(fingerprint);
46     }
47
48     /**
49     * Determine the default priority of this node test when used on its own as a Pattern
50     */

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

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