1 16 17 package org.apache.commons.jexl.parser; 18 19 import org.apache.commons.jexl.JexlContext; 20 21 27 public class SimpleNode implements Node { 28 29 protected Node parent; 30 31 32 protected Node[] children; 33 34 35 protected int id; 36 37 38 protected Parser parser; 39 40 45 public SimpleNode(int i) { 46 id = i; 47 } 48 49 55 public SimpleNode(Parser p, int i) { 56 this(i); 57 parser = p; 58 } 59 60 63 public void jjtOpen() { 64 } 65 66 69 public void jjtClose() { 70 } 71 72 73 public void jjtSetParent(Node n) { 74 parent = n; 75 } 76 77 78 public Node jjtGetParent() { 79 return parent; 80 } 81 82 83 public void jjtAddChild(Node n, int i) { 84 if (children == null) { 85 children = new Node[i + 1]; 86 } else if (i >= children.length) { 87 Node[] c = new Node[i + 1]; 88 System.arraycopy(children, 0, c, 0, children.length); 89 children = c; 90 } 91 92 children[i] = n; 93 } 94 95 96 public Node jjtGetChild(int i) { 97 return children[i]; 98 } 99 100 101 public int jjtGetNumChildren() { 102 return (children == null) ? 0 : children.length; 103 } 104 105 113 public Object jjtAccept(ParserVisitor visitor, Object data) { 114 return visitor.visit(this, data); 115 } 116 117 125 public Object childrenAccept(ParserVisitor visitor, Object data) { 126 if (children != null) { 127 for (int i = 0; i < children.length; ++i) { 128 children[i].jjtAccept(visitor, data); 129 } 130 } 131 return data; 132 } 133 134 138 public String toString() { 139 return ParserTreeConstants.jjtNodeName[id]; 140 } 141 142 147 public String toString(String prefix) { 148 return prefix + toString(); 149 } 150 151 155 public void dump(String prefix) { 156 System.out.println(toString(prefix)); 157 158 if (children != null) { 159 for (int i = 0; i < children.length; ++i) { 160 SimpleNode n = (SimpleNode) children[i]; 161 162 if (n != null) { 163 n.dump(prefix + " "); 164 } 165 } 166 } 167 } 168 169 175 public boolean interpret(JexlContext pc) throws Exception { 176 for (int i = 0; i < jjtGetNumChildren(); i++) { 177 SimpleNode node = (SimpleNode) jjtGetChild(i); 178 if (!node.interpret(pc)) { 179 return false; 180 } 181 } 182 183 return true; 184 } 185 186 193 public Object value(JexlContext context) throws Exception { 194 return null; 195 } 196 197 206 public Object setValue(JexlContext context, Object value) throws Exception { 207 return null; 208 } 209 210 217 public Object execute(Object o, JexlContext ctx) throws Exception { 218 return null; 219 } 220 } 221 | Popular Tags |