KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > nativequery > expr > TraversingExpressionVisitor


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.nativequery.expr;
22
23 import com.db4o.nativequery.expr.cmp.ArithmeticExpression;
24 import com.db4o.nativequery.expr.cmp.ArrayAccessValue;
25 import com.db4o.nativequery.expr.cmp.ComparisonOperand;
26 import com.db4o.nativequery.expr.cmp.ComparisonOperandVisitor;
27 import com.db4o.nativequery.expr.cmp.ConstValue;
28 import com.db4o.nativequery.expr.cmp.FieldValue;
29 import com.db4o.nativequery.expr.cmp.MethodCallValue;
30 import com.db4o.nativequery.expr.cmp.field.CandidateFieldRoot;
31 import com.db4o.nativequery.expr.cmp.field.PredicateFieldRoot;
32 import com.db4o.nativequery.expr.cmp.field.StaticFieldRoot;
33
34 public class TraversingExpressionVisitor implements ExpressionVisitor, ComparisonOperandVisitor {
35     public void visit(AndExpression expression) {
36         expression.left().accept(this);
37         expression.right().accept(this);
38     }
39
40     public void visit(BoolConstExpression expression) {
41     }
42
43     public void visit(OrExpression expression) {
44         expression.left().accept(this);
45         expression.right().accept(this);
46     }
47
48     public void visit(ComparisonExpression expression) {
49         expression.left().accept(this);
50         expression.right().accept(this);
51     }
52
53     public void visit(NotExpression expression) {
54         expression.expr().accept(this);
55     }
56     
57     public void visit(ArithmeticExpression operand) {
58         operand.left().accept(this);
59         operand.right().accept(this);
60     }
61
62     public void visit(ConstValue operand) {
63     }
64
65     public void visit(FieldValue operand) {
66         operand.parent().accept(this);
67     }
68
69     public void visit(CandidateFieldRoot root) {
70     }
71
72     public void visit(PredicateFieldRoot root) {
73     }
74
75     public void visit(StaticFieldRoot root) {
76     }
77
78     public void visit(ArrayAccessValue operand) {
79         operand.parent().accept(this);
80         operand.index().accept(this);
81     }
82
83     public void visit(MethodCallValue value) {
84         value.parent().accept(this);
85         visitArgs(value);
86     }
87
88     protected void visitArgs(MethodCallValue value) {
89         ComparisonOperand[] args = value.args();
90         for (int i=0; i<args.length; ++i) {
91             args[i].accept(this);
92         }
93     }
94 }
95
Popular Tags