| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jexl.parser.SimpleNode |
|
|
| 1 | /* |
|
| 2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
| 3 | * |
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 5 | * you may not use this file except in compliance with the License. |
|
| 6 | * You may obtain a copy of the License at |
|
| 7 | * |
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 9 | * |
|
| 10 | * Unless required by applicable law or agreed to in writing, software |
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 13 | * See the License for the specific language governing permissions and |
|
| 14 | * limitations under the License. |
|
| 15 | */ |
|
| 16 | ||
| 17 | package org.apache.commons.jexl.parser; |
|
| 18 | ||
| 19 | import org.apache.commons.jexl.JexlContext; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * useful interface to node. most autogened by javacc |
|
| 23 | * |
|
| 24 | * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a> |
|
| 25 | * @version $Id: SimpleNode.java,v 1.3 2004/02/28 13:45:21 yoavs Exp $ |
|
| 26 | */ |
|
| 27 | public class SimpleNode implements Node |
|
| 28 | { |
|
| 29 | protected Node parent; |
|
| 30 | protected Node[] children; |
|
| 31 | protected int id; |
|
| 32 | protected Parser parser; |
|
| 33 | ||
| 34 | 1435 | public SimpleNode(int i) |
| 35 | 19550 | { |
| 36 | 20985 | id = i; |
| 37 | 20985 | } |
| 38 | ||
| 39 | public SimpleNode(Parser p, int i) |
|
| 40 | { |
|
| 41 | 20985 | this(i); |
| 42 | 20985 | parser = p; |
| 43 | 20985 | } |
| 44 | ||
| 45 | public void jjtOpen() |
|
| 46 | { |
|
| 47 | 20985 | } |
| 48 | ||
| 49 | public void jjtClose() |
|
| 50 | { |
|
| 51 | 17988 | } |
| 52 | ||
| 53 | public void jjtSetParent(Node n) |
|
| 54 | { |
|
| 55 | 18117 | parent = n; |
| 56 | 18117 | } |
| 57 | ||
| 58 | public Node jjtGetParent() |
|
| 59 | { |
|
| 60 | 0 | return parent; |
| 61 | } |
|
| 62 | ||
| 63 | public void jjtAddChild(Node n, int i) |
|
| 64 | { |
|
| 65 | 18117 | if (children == null) |
| 66 | { |
|
| 67 | 14442 | children = new Node[i + 1]; |
| 68 | } |
|
| 69 | 3675 | else if (i >= children.length) |
| 70 | { |
|
| 71 | 0 | Node c[] = new Node[i + 1]; |
| 72 | 0 | System.arraycopy(children, 0, c, 0, children.length); |
| 73 | 0 | children = c; |
| 74 | } |
|
| 75 | ||
| 76 | 18117 | children[i] = n; |
| 77 | 18117 | } |
| 78 | ||
| 79 | public Node jjtGetChild(int i) |
|
| 80 | { |
|
| 81 | 18105 | return children[i]; |
| 82 | } |
|
| 83 | ||
| 84 | public int jjtGetNumChildren() |
|
| 85 | { |
|
| 86 | 5253 | return (children == null) ? 0 : children.length; |
| 87 | } |
|
| 88 | ||
| 89 | /** Accept the visitor. **/ |
|
| 90 | public Object jjtAccept(ParserVisitor visitor, Object data) |
|
| 91 | { |
|
| 92 | 0 | return visitor.visit(this, data); |
| 93 | } |
|
| 94 | ||
| 95 | /** Accept the visitor. **/ |
|
| 96 | public Object childrenAccept(ParserVisitor visitor, Object data) |
|
| 97 | { |
|
| 98 | 0 | if (children != null) |
| 99 | { |
|
| 100 | 0 | for (int i = 0; i < children.length; ++i) |
| 101 | { |
|
| 102 | 0 | children[i].jjtAccept(visitor, data); |
| 103 | } |
|
| 104 | } |
|
| 105 | 0 | return data; |
| 106 | } |
|
| 107 | ||
| 108 | ||
| 109 | public String toString() |
|
| 110 | { |
|
| 111 | 0 | return ParserTreeConstants.jjtNodeName[id]; |
| 112 | } |
|
| 113 | ||
| 114 | public String toString(String prefix) |
|
| 115 | { |
|
| 116 | 0 | return prefix + toString(); |
| 117 | } |
|
| 118 | ||
| 119 | public void dump(String prefix) |
|
| 120 | { |
|
| 121 | 0 | System.out.println(toString(prefix)); |
| 122 | ||
| 123 | 0 | if (children != null) |
| 124 | { |
|
| 125 | 0 | for (int i = 0; i < children.length; ++i) |
| 126 | { |
|
| 127 | 0 | SimpleNode n = (SimpleNode)children[i]; |
| 128 | ||
| 129 | 0 | if (n != null) |
| 130 | { |
|
| 131 | 0 | n.dump(prefix + " "); |
| 132 | } |
|
| 133 | } |
|
| 134 | } |
|
| 135 | 0 | } |
| 136 | ||
| 137 | /** |
|
| 138 | * basic interpret - just invoke interpret on all children |
|
| 139 | */ |
|
| 140 | public boolean interpret(JexlContext pc) |
|
| 141 | throws Exception |
|
| 142 | { |
|
| 143 | 585 | for (int i=0; i<jjtGetNumChildren();i++) |
| 144 | { |
|
| 145 | 270 | SimpleNode node = (SimpleNode) jjtGetChild(i); |
| 146 | 270 | if (!node.interpret(pc)) |
| 147 | 0 | return false; |
| 148 | } |
|
| 149 | ||
| 150 | 315 | return true; |
| 151 | } |
|
| 152 | ||
| 153 | ||
| 154 | /** |
|
| 155 | * Returns the value of the node. |
|
| 156 | */ |
|
| 157 | public Object value(JexlContext context) |
|
| 158 | throws Exception |
|
| 159 | { |
|
| 160 | 0 | return null; |
| 161 | } |
|
| 162 | ||
| 163 | /** |
|
| 164 | * Sets the value for the node - again, only makes sense for some nodes |
|
| 165 | * but lazyness tempts me to put it here. Keeps things simple. |
|
| 166 | */ |
|
| 167 | public Object setValue(JexlContext context, Object value) |
|
| 168 | throws Exception |
|
| 169 | { |
|
| 170 | 0 | return null; |
| 171 | } |
|
| 172 | ||
| 173 | /** |
|
| 174 | * Used to let a node calcuate it's value.. |
|
| 175 | */ |
|
| 176 | public Object execute(Object o, JexlContext ctx) |
|
| 177 | throws Exception |
|
| 178 | { |
|
| 179 | 0 | return null; |
| 180 | } |
|
| 181 | } |
|
| 182 |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |