KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > exp > parser > ASTAnd


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. 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,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.exp.parser;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import org.apache.cayenne.exp.Expression;
26 import org.apache.cayenne.util.ConversionUtil;
27
28 /**
29  * "And" expression.
30  *
31  * @since 1.1
32  * @author Andrus Adamchik
33  */

34 public class ASTAnd extends AggregateConditionNode {
35     /**
36      * Constructor used by expression parser. Do not invoke directly.
37      */

38     ASTAnd(int id) {
39         super(id);
40     }
41
42     public ASTAnd() {
43         super(ExpressionParserTreeConstants.JJTAND);
44     }
45
46     public ASTAnd(Object JavaDoc[] nodes) {
47         super(ExpressionParserTreeConstants.JJTAND);
48         int len = nodes.length;
49         for (int i = 0; i < len; i++) {
50             jjtAddChild((Node) nodes[i], i);
51         }
52     }
53
54     public ASTAnd(Collection JavaDoc nodes) {
55         super(ExpressionParserTreeConstants.JJTAND);
56         int len = nodes.size();
57         Iterator JavaDoc it = nodes.iterator();
58         for (int i = 0; i < len; i++) {
59             jjtAddChild((Node) it.next(), i);
60         }
61     }
62
63     protected Object JavaDoc evaluateNode(Object JavaDoc o) throws Exception JavaDoc {
64         int len = jjtGetNumChildren();
65         if (len == 0) {
66             return Boolean.FALSE;
67         }
68
69         for (int i = 0; i < len; i++) {
70             if (!ConversionUtil.toBoolean(evaluateChild(i, o))) {
71                 return Boolean.FALSE;
72             }
73         }
74
75         return Boolean.TRUE;
76     }
77
78     /**
79      * Creates a copy of this expression node, without copying children.
80      */

81     public Expression shallowCopy() {
82         return new ASTAnd(id);
83     }
84
85     public int getType() {
86         return Expression.AND;
87     }
88
89     public void jjtClose() {
90         super.jjtClose();
91         flattenTree();
92     }
93
94     protected String JavaDoc getExpressionOperator(int index) {
95         return "and";
96     }
97 }
98
Popular Tags