| 1 | package org.apache.velocity.runtime.parser.node; |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2000-2001,2004 The Apache Software Foundation. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | import org.apache.velocity.runtime.parser.Parser; |
| 20 | import org.apache.velocity.context.InternalContextAdapter; |
| 21 | |
| 22 | import org.apache.velocity.exception.MethodInvocationException; |
| 23 | |
| 24 | /** |
| 25 | * Please look at the Parser.jjt file which is |
| 26 | * what controls the generation of this class. |
| 27 | * |
| 28 | * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a> |
| 29 | * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a> |
| 30 | * @version $Id: ASTOrNode.java,v 1.6.8.1 2004/03/03 23:22:59 geirm Exp $ |
| 31 | */ |
| 32 | public class ASTOrNode extends SimpleNode |
| 33 | { |
| 34 | public ASTOrNode(int id) |
| 35 | { |
| 36 | super(id); |
| 37 | } |
| 38 | |
| 39 | public ASTOrNode(Parser p, int id) |
| 40 | { |
| 41 | super(p, id); |
| 42 | } |
| 43 | |
| 44 | /** Accept the visitor. **/ |
| 45 | public Object jjtAccept(ParserVisitor visitor, Object data) |
| 46 | { |
| 47 | return visitor.visit(this, data); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the value of the expression. |
| 52 | * Since the value of the expression is simply the boolean |
| 53 | * result of evaluate(), lets return that. |
| 54 | */ |
| 55 | public Object value(InternalContextAdapter context ) |
| 56 | throws MethodInvocationException |
| 57 | { |
| 58 | return new Boolean( evaluate( context ) ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * the logical or : |
| 63 | * the rule : |
| 64 | * left || null -> left |
| 65 | * null || right -> right |
| 66 | * null || null -> false |
| 67 | * left || right -> left || right |
| 68 | */ |
| 69 | public boolean evaluate( InternalContextAdapter context) |
| 70 | throws MethodInvocationException |
| 71 | { |
| 72 | Node left = jjtGetChild(0); |
| 73 | Node right = jjtGetChild(1); |
| 74 | |
| 75 | /* |
| 76 | * if the left is not null and true, then true |
| 77 | */ |
| 78 | |
| 79 | if (left != null && left.evaluate( context ) ) |
| 80 | return true; |
| 81 | |
| 82 | /* |
| 83 | * same for right |
| 84 | */ |
| 85 | |
| 86 | if ( right != null && right.evaluate( context ) ) |
| 87 | return true; |
| 88 | |
| 89 | return false; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |