KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > BottomUpTractor


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.algebra;
24
25 import java.util.List JavaDoc;
26
27 import org.xquark.extractor.common.SqlWrapperException;
28
29 /**
30  * Browse an algebra tree from leaf to root stopping at "end node" applying a
31  * subvisitor to {@link org.xquark.extractor.algebra.Relation} nodes.
32  */

33 public class BottomUpTractor extends DefaultAlgebraVisitor {
34
35     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
36     private static final String JavaDoc RCSName = "$Name: $";
37
38     /* process of GoUp end up at "_endNode"*/
39     private Expression _endNode = null;
40
41     private AlgebraVisitor _visitor = null;
42
43     public BottomUpTractor() {
44     }
45
46     public BottomUpTractor(AlgebraVisitor visitor) {
47         setVisitor(visitor);
48     }
49
50     public BottomUpTractor(AlgebraVisitor visitor, Expression endNode) {
51         setEndNode(endNode);
52         setVisitor(visitor);
53     }
54
55     public void setEndNode(Expression endNode) {
56         _endNode = endNode;
57     }
58
59     public Expression getEndNode() {
60         return _endNode;
61     }
62
63     public void setVisitor(AlgebraVisitor visitor) {
64         _visitor = visitor;
65     }
66
67     public AlgebraVisitor getVisitor() {
68         return _visitor;
69     }
70
71     public void visit(Expression arg) throws SqlWrapperException {
72         //Trace.enter(this, "visit(Expression arg)", arg.pprint());
73

74         Expression father = arg.getFather();
75         if (father != null && getEndNode() != arg) {
76             father.accept(this);
77         }
78
79         //Trace.exit(this,"visit(Expression arg)",arg.pprint());
80
}
81
82     public void visit(UnaryAlgebra arg) throws SqlWrapperException {
83         //Trace.enter(this,"UnaryAlgebra(Join arg)",arg.pprint());
84

85         List JavaDoc list = arg.getParameterList();
86
87         if (null != list) {
88             treat(list);
89         }
90
91         visitFather(arg);
92
93         //Trace.exit(this, "UnaryAlgebra(Join arg)", arg.pprint());
94
}
95
96     public void visit(Join arg) throws SqlWrapperException {
97         //Trace.enter(this, "visit(Join arg)", arg.pprint());
98

99         List JavaDoc list = arg.getPredicateList();
100         treat(list);
101         visitFather(arg);
102
103         //Trace.exit(this, "visit(Join arg)", arg.pprint());
104
}
105
106     public void visit(BinOpOuterJoin arg) throws SqlWrapperException {
107         //Trace.enter(this, "visit(BinOpOuterJoin arg)", arg.pprint());
108

109         List JavaDoc list = arg.getPredicateList();
110         treat(list);
111         visitFather(arg);
112
113         //Trace.exit(this, "visit(BinOpOuterJoin arg)", arg.pprint());
114
}
115
116     protected void treat(List JavaDoc list) {
117         //Trace.enter(this, "treat(List list)");
118
Expression expr = null;
119         if (null != list && !list.isEmpty()) {
120             for (int i = 0; i < list.size(); i++) {
121                 expr = (Expression) list.get(i);
122                 expr.accept(_visitor);
123             }
124         }
125         //Trace.exit(this, "treat(List list)");
126
}
127
128     protected void visitFather(Expression arg) {
129         // Trace.enter(this, "visitFather(Expression arg)");
130
Expression father = arg.getFather();
131         if (father != null && getEndNode() != arg) {
132             father.accept(this);
133         }
134         // Trace.exit(this, "visitFather(Expression arg)");
135
}
136 }
137
Popular Tags