001: package net.sf.saxon.pattern;
002:
003: import net.sf.saxon.om.Item;
004: import net.sf.saxon.om.NodeInfo;
005: import net.sf.saxon.type.Type;
006: import net.sf.saxon.type.ItemType;
007: import net.sf.saxon.tinytree.TinyTree;
008: import net.sf.saxon.expr.XPathContext;
009:
010: /**
011: * NodeTest is an interface that enables a test of whether a node has a particular
012: * name and type. A NoNodeTest matches no nodes.
013: *
014: * @author Michael H. Kay
015: */
016:
017: public final class NoNodeTest extends NodeTest {
018:
019: private static NoNodeTest instance = new NoNodeTest();
020:
021: /**
022: * Get a NoNodeTest instance
023: */
024:
025: public static NoNodeTest getInstance() {
026: return instance;
027: }
028:
029: public final int getPrimitiveType() {
030: return Type.EMPTY;
031: }
032:
033: /**
034: * Get the primitive item type corresponding to this item type. For item(),
035: * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds,
036: * it is the value representing the node kind, for example Type.ELEMENT.
037: * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER.
038: * For other atomic types it is the primitive type as defined in XML Schema,
039: * except that INTEGER is considered to be a primitive type.
040: */
041:
042: public ItemType getPrimitiveItemType() {
043: return this ;
044: }
045:
046: /**
047: * Test whether a given item conforms to this type
048: * @param item The item to be tested
049: * @param context
050: * @return true if the item is an instance of this type; false otherwise
051: */
052:
053: public boolean matchesItem(Item item, XPathContext context) {
054: return false;
055: }
056:
057: /**
058: * Test whether this node test is satisfied by a given node
059: * @param nodeType The type of node to be matched
060: * @param fingerprint identifies the expanded name of the node to be matched
061: */
062:
063: public boolean matches(int nodeType, int fingerprint, int annotation) {
064: return false;
065: }
066:
067: /**
068: * Test whether this node test is satisfied by a given node on a TinyTree. The node
069: * must be a document, element, text, comment, or processing instruction node.
070: * This method is provided
071: * so that when navigating a TinyTree a node can be rejected without
072: * actually instantiating a NodeInfo object.
073: *
074: * @param tree the TinyTree containing the node
075: * @param nodeNr the number of the node within the TinyTree
076: * @return true if the node matches the NodeTest, otherwise false
077: */
078:
079: public boolean matches(TinyTree tree, int nodeNr) {
080: return false;
081: }
082:
083: /**
084: * Test whether this node test is satisfied by a given node. This alternative
085: * method is used in the case of nodes where calculating the fingerprint is expensive,
086: * for example DOM or JDOM nodes.
087: * @param node the node to be matched
088: */
089:
090: public boolean matches(NodeInfo node) {
091: return false;
092: }
093:
094: /**
095: * Determine the default priority of this node test when used on its own as a Pattern
096: */
097:
098: public final double getDefaultPriority() {
099: return -0.5;
100: }
101:
102: /**
103: * Get a mask indicating which kinds of nodes this NodeTest can match. This is a combination
104: * of bits: 1<<Type.ELEMENT for element nodes, 1<<Type.TEXT for text nodes, and so on.
105: */
106:
107: public int getNodeKindMask() {
108: return 0;
109: }
110:
111: public String toString() {
112: return "empty-sequence()";
113: }
114:
115: /**
116: * Returns a hash code value for the object.
117: */
118:
119: public int hashCode() {
120: return "NoNodeTest".hashCode();
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: //
|