1 28 29 package com.caucho.xpath.pattern; 30 31 import com.caucho.xpath.ExprEnvironment; 32 import com.caucho.xpath.XPathException; 33 34 import org.w3c.dom.Node ; 35 36 40 public class NSNamePattern extends AbstractPattern { 41 private NSNamePattern _match; 42 43 private String _namespace; 44 private String _local; 45 private int _nodeType; 46 47 55 public NSNamePattern(AbstractPattern parent, String namespace, String local, 56 int nodeType) 57 { 58 super(parent); 59 60 _nodeType = nodeType; 61 62 if (namespace != null) 63 _namespace = namespace.intern(); 64 else 65 _namespace = ""; 66 67 _local = local.intern(); 68 } 69 70 73 public double getPriority() 74 { 75 return 0; 76 } 77 78 86 public boolean match(Node node, ExprEnvironment env) 87 throws XPathException 88 { 89 if (node == null) 90 return false; 91 92 if (node.getNodeType() != _nodeType) 93 return false; 94 95 String uri = node.getNamespaceURI(); 96 if (uri == null || ! node.getNamespaceURI().equals(_namespace)) 97 return false; 98 99 else if (! node.getLocalName().equals(_local)) 100 return false; 101 102 else if (_parent != null && ! _parent.match(node, env)) 103 return false; 104 105 return true; 106 } 107 108 111 public AbstractPattern copyPosition() 112 { 113 if (_match == null) { 114 AbstractPattern parent = null; 115 116 if (_parent != null) 117 parent = _parent.copyPosition(); 118 119 _match = new NSNamePattern(parent, _namespace, _local, _nodeType); 120 } 121 122 return _match; 123 } 124 125 128 public boolean equals(Object b) 129 { 130 if (! (b instanceof NSNamePattern)) 131 return false; 132 133 NSNamePattern bPattern = (NSNamePattern) b; 134 135 return (_nodeType == bPattern._nodeType && 136 _local.equals(bPattern._local) && 137 _namespace.equals(bPattern._namespace) && 138 (_parent == bPattern._parent || 139 (_parent != null && _parent.equals(bPattern._parent)))); 140 } 141 142 public String toString() 143 { 144 return _parent + "{" + _namespace + "}" + _local; 145 } 146 } 147 | Popular Tags |