1 16 17 package org.apache.taglibs.standard.lang.jpath.expression; 18 19 import javax.servlet.jsp.PageContext ; 20 21 import org.apache.taglibs.standard.lang.jpath.adapter.IterationContext; 22 23 28 public abstract class SimpleNode implements Node { 29 30 protected Node parent; 31 protected Node[] children; 32 protected int id; 33 protected Parser parser; 34 protected String image; 35 protected int beginColumn; 36 protected int endColumn; 37 protected int beginLine; 38 protected int endLine; 39 protected Token firstToken; 40 protected Token lastToken; 41 protected Object val; 42 43 50 public SimpleNode(int i) { 51 id = i; 52 } 53 54 62 public SimpleNode(Parser p, int i) { 63 64 this(i); 65 66 parser = p; 67 } 68 69 74 public void jjtOpen() {} 75 76 81 public void jjtClose() {} 82 83 90 public void jjtSetParent(Node n) { 91 parent = n; 92 } 93 94 101 public Node jjtGetParent() { 102 return parent; 103 } 104 105 113 public void jjtAddChild(Node n, int i) { 114 115 if (children == null) { 116 children = new Node[i + 1]; 117 } else if (i >= children.length) { 118 Node c[] = new Node[i + 1]; 119 120 System.arraycopy(children, 0, c, 0, children.length); 121 122 children = c; 123 } 124 125 children[i] = n; 126 } 127 128 137 public Node jjtGetChild(int i) { 138 return children[i]; 139 } 140 141 148 public int jjtGetNumChildren() { 149 return (children == null) ? 0 : children.length; 150 } 151 152 162 public String toString() { 163 return ParserTreeConstants.jjtNodeName[id]; 164 } 165 166 179 public String toString(String prefix) { 180 return prefix + toString(); 181 } 182 183 191 public void dump(String prefix) { 192 193 System.out.println(toString(prefix)); 194 195 if (children != null) { 196 for (int i = 0; i < children.length; ++i) { 197 SimpleNode n = (SimpleNode) children[i]; 198 199 if (n != null) { 200 n.dump(prefix + " "); 201 } 202 } 203 } 204 } 205 206 216 public String stringDump(String prefix) { 217 218 String result = prefix + toString() + "\n"; 219 220 System.out.println(toString(prefix)); 221 222 if (children != null) { 223 for (int i = 0; i < children.length; ++i) { 224 SimpleNode n = (SimpleNode) children[i]; 225 226 if (n != null) { 227 result = result + n.stringDump(prefix + " "); 228 } 229 } 230 } 231 232 return result; 233 } 234 235 245 246 256 public String toNormalizedString() { 257 258 String normalized = "toNormalizedString() not implemented in [" 259 + ParserTreeConstants.jjtNodeName[id] + "]"; 260 261 return normalized; 262 } 263 264 275 public String toOriginalString() { 276 277 String result = ""; 278 Token t = firstToken; 279 boolean finished = false; 280 281 while (!finished) { 282 result += getSpecialTokenString(t); 283 284 if (t.image != null) { 285 while (result.length() < t.beginColumn - 1) { 286 result += " "; 287 } 288 289 result += (t.image); 290 } 291 292 if (t == lastToken) { 293 finished = true; 294 } else { 295 t = t.next; 296 } 297 } 298 299 return result; 300 } 301 302 313 public String rootOriginalString() { 314 315 SimpleNode current = this; 316 317 while (current.parent != null) { 318 current = (SimpleNode) current.parent; 319 } 320 321 return current.toOriginalString(); 322 } 323 324 342 public Object evaluate(PageContext pageContext, IterationContext icontext) 343 throws EvaluationException { 344 345 throw new EvaluationException(this, 346 "evaluate not supported in [" 347 + ParserTreeConstants.jjtNodeName[id] + "]"); 348 } 349 350 359 public String getTokenImage(int tokenNumber) { 360 361 String tokenImage = ParserConstants.tokenImage[tokenNumber]; 362 363 return tokenImage.substring(1, tokenImage.length() - 1); 364 } 365 366 375 private String getSpecialTokenString(Token t) { 376 377 String result; 378 379 if (t.specialToken == null) { 380 result = ""; 381 } else { 382 result = getSpecialTokenString(t) + t.image; 383 } 384 385 return result; 386 } 387 388 398 public void validate() throws ValidationException { 399 400 if (children != null) { 401 for (int i = 0; i < children.length; ++i) { 402 SimpleNode n = (SimpleNode) children[i]; 403 404 if (n != null) { 405 n.validate(); 406 } 407 } 408 } 409 } 410 411 423 public Node simplify() { 424 425 if (children != null) { 426 for (int i = 0; i < children.length; ++i) { 427 SimpleNode n = (SimpleNode) children[i]; 428 429 if (n != null) { 430 n = (SimpleNode) n.simplify(); 431 } 432 } 433 } 434 435 return this; 437 } 438 } 439 | Popular Tags |