1 package net.sf.saxon.pattern; 2 import net.sf.saxon.om.NamePool; 3 import net.sf.saxon.om.NodeInfo; 4 import net.sf.saxon.type.ItemType; 5 import net.sf.saxon.tinytree.TinyTree; 6 7 13 14 public final class NamespaceTest extends NodeTest { 15 16 private NamePool namePool; 17 private int nodeKind; 18 private short uriCode; 19 private String uri; 20 21 public NamespaceTest(NamePool pool, int nodeKind, String uri) { 22 namePool = pool; 23 this.nodeKind = nodeKind; 24 this.uri = uri; 25 this.uriCode = pool.allocateCodeForURI(uri); 26 } 27 28 33 34 public boolean matches(int nodeType, int fingerprint, int annotation) { 35 if (fingerprint == -1) return false; 36 if (nodeType != nodeKind) return false; 37 return uriCode == namePool.getURICode(fingerprint); 38 } 39 40 50 51 public boolean matches(TinyTree tree, int nodeNr) { 52 int fingerprint = tree.getNameCode(nodeNr) & NamePool.FP_MASK; 53 if (fingerprint == -1) return false; 54 if (tree.getNodeKind(nodeNr) != nodeKind) return false; 55 return uriCode == namePool.getURICode(fingerprint); 56 } 57 58 64 65 public boolean matches(NodeInfo node) { 66 return node.getNodeKind()==nodeKind && node.getURI().equals(uri); 67 } 68 69 72 73 public final double getDefaultPriority() { 74 return -0.25; 75 } 76 77 82 83 public int getPrimitiveType() { 84 return nodeKind; 85 } 86 87 99 100 public ItemType getSuperType() { 101 return NodeKindTest.makeNodeKindTest(nodeKind); 102 } 103 104 108 109 public int getNodeKindMask() { 110 return 1<<nodeKind; 111 } 112 113 public String toString() { 114 return '{' + namePool.getURIFromURICode(uriCode) + "}:*"; 115 } 116 117 120 121 public int hashCode() { 122 return uriCode << 5 + nodeKind; 123 } 124 125 } 126 127 | Popular Tags |