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