1 22 23 package org.xquark.xpath; 24 25 import org.xquark.schema.Type; 26 27 public class StepExprImpl implements StepExpr { 28 29 32 private boolean hasSeparator = false; 33 34 37 private byte axis = Axis.NONE; 38 39 42 private String localName = null; 43 44 47 private String nameSpace = null; 48 49 52 private byte wild = StepExpr.NO_WILDCARD; 53 54 57 private byte kindtest = NodeKind.NONE; 58 59 62 private Type type = null; 63 66 private boolean isTypeNillable = false; 67 68 public StepExprImpl(byte axis, String nameSpace, String localName) { 69 this.axis = axis; 70 this.nameSpace = nameSpace; 71 this.localName = localName; 72 } 73 74 78 public boolean hasSeparator() { 79 return hasSeparator; 80 } 81 82 86 public byte getAxis() { 87 return axis; 88 } 89 90 94 public String getNameSpace() { 95 return nameSpace; 96 } 97 98 102 public String getLocalName() { 103 return localName; 104 } 105 106 110 public byte getWildCardType() { 111 return wild; 112 } 113 114 118 public boolean hasWildcard() { 119 return wild != StepExpr.NO_WILDCARD; 120 } 121 122 126 public boolean isWildcard() { 127 return wild == StepExpr.WILDCARD; 128 } 129 130 134 public boolean isNameSpaceWildcard() { 135 return wild == StepExpr.NAMESPACE_WILDCARD; 136 } 137 138 142 public boolean isLocalNameWildcard() { 143 return wild == StepExpr.LOCALNAME_WILDCARD; 144 } 145 146 150 public byte getKindTest() { 151 return kindtest; 152 } 153 154 158 public org.xquark.schema.Type getType() { 159 return type; 160 } 161 162 166 public boolean isTypeNillable() { 167 return isTypeNillable; 168 } 169 170 173 public String toHashCodeString() { 174 return toString(); 175 } 176 public String toString() { 177 StringBuffer buf = new StringBuffer (); 178 if (axis != Axis.NONE) 179 buf.append('/'); 180 buf.append(Axis.AXISSTRINGS[axis]); 181 switch (kindtest) { 182 case NodeKind.ATTRIBUTE : 183 if (isWildcard()) 186 buf.append('*'); 187 else if (localName != null) { 188 if (nameSpace != null) { 190 buf.append('{'); 191 buf.append(nameSpace); 192 buf.append('}'); 193 } 194 buf.append(localName); 195 } 202 break; 204 case NodeKind.COMMENT : 205 buf.append(NodeKind.NODEKINDSTRINGS[kindtest]); 206 buf.append('('); 207 buf.append(')'); 208 break; 209 case NodeKind.DOCUMENT : 210 buf.append(NodeKind.NODEKINDSTRINGS[kindtest]); 211 buf.append('('); 212 if (localName != null || type != null) { 213 if (isWildcard()) 216 buf.append('*'); 217 else if (localName != null) { 218 if (nameSpace != null) { 219 buf.append('{'); 220 buf.append(nameSpace); 221 buf.append('}'); 222 } 223 buf.append(localName); 224 } 234 } 236 buf.append(')'); 237 break; 238 case NodeKind.ELEMENT : 239 if (isWildcard()) 242 buf.append('*'); 243 else if (localName != null) { 244 if (nameSpace != null) { 245 buf.append('{'); 246 buf.append(nameSpace); 247 buf.append('}'); 248 } 249 buf.append(localName); 250 } 260 break; 262 case NodeKind.NODE : 264 buf.append(NodeKind.NODEKINDSTRINGS[kindtest]); 265 buf.append('('); 266 buf.append(')'); 267 break; 268 case NodeKind.PI : 269 buf.append(NodeKind.NODEKINDSTRINGS[kindtest]); 270 buf.append('('); 271 if (localName != null) 272 buf.append(localName); 273 buf.append(')'); 274 break; 275 case NodeKind.TEXT : 276 buf.append(NodeKind.NODEKINDSTRINGS[kindtest]); 277 buf.append('('); 278 buf.append(')'); 279 break; 280 } 281 return buf.toString(); 282 } 283 284 286 public boolean equals(Object o) 287 { 288 return (o instanceof StepExpr) 289 && (nameSpace == null || nameSpace.equals(((StepExpr)o).getNameSpace())) 290 && localName.equals(((StepExpr)o).getLocalName()) 291 && kindtest == ((StepExpr)o).getKindTest() 292 && (axis == ((StepExpr)o).getAxis()); 295 } 296 297 public static final String NAME_WILDCARD = "*"; 298 public XNode xnode = null; 299 300 public StepExprImpl(byte axis, XNode xnode) { 301 this.axis = axis; 302 this.xnode = xnode; 303 this.localName = xnode.getLocalName(); 304 this.nameSpace = xnode.getNamespace(); 305 this.kindtest = xnode.getType(); 306 } 307 308 public StepExprImpl(XNode xnode) { 309 this.axis = Axis.CHILD; 310 this.xnode = xnode; 311 this.localName = xnode.getLocalName(); 312 this.nameSpace = xnode.getNamespace(); 313 this.kindtest = xnode.getType(); 314 } 315 316 public XNode getXNode() { 317 return xnode; 318 } 319 320 public boolean match(XNode node) { 321 if (node == null) 322 return false; 323 if (isTypeTest()) { return typeMatch(node); 325 } else { 327 if (typeMatch(node) == false) { 328 return false; 329 } 330 if (getNamespace() == null) { 331 if (node.getNamespace() == null) { 332 } else { 334 return false; 335 } 336 } else if (isNamespaceWildcard()) { 337 } else if (node.getNamespace() == null) { 339 return false; 340 } else if (getNamespace().equals(node.getNamespace())) { 341 } else { 343 return false; 344 } 345 346 if (this.getLocalName() == null) { 348 if (node.getLocalName() == null) { 349 } else { 351 return false; 352 } 353 } else if (this.isLocalNameWildcard()) { 354 } else if (node.getLocalName() == null) { 356 return false; 357 } else if (this.getLocalName().equals(node.getLocalName())) { 358 } else { 360 return false; 361 } 362 return true; 363 } 364 } 365 public boolean isTypeTest() 366 { 367 return xnode.getLocalName() == null; 368 } 369 private boolean typeMatch(XNode node) 370 { 371 return ((getTypeTest() == node.getType()) || (getTypeTest() == NodeKind.NODE)); 372 } 373 public byte getTypeTest() 374 { 375 return xnode.getType(); 376 } 377 public String getNamespace() 378 { 379 return xnode.getNamespace(); 380 } 381 public boolean isNamespaceWildcard() 382 { 383 return isNameTest() && (xnode.getNamespace() != null) && xnode.getNamespace().equals(NAME_WILDCARD); 384 } 385 public boolean isNameTest() 386 { 387 return xnode.getLocalName() != null; 388 } 389 390 } 391 | Popular Tags |