1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.List ; 26 27 import org.xquark.extractor.common.SqlWrapperException; 28 29 33 public class BottomUpTractor extends DefaultAlgebraVisitor { 34 35 private static final String RCSRevision = "$Revision: 1.4 $"; 36 private static final String RCSName = "$Name: $"; 37 38 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 74 Expression father = arg.getFather(); 75 if (father != null && getEndNode() != arg) { 76 father.accept(this); 77 } 78 79 } 81 82 public void visit(UnaryAlgebra arg) throws SqlWrapperException { 83 85 List list = arg.getParameterList(); 86 87 if (null != list) { 88 treat(list); 89 } 90 91 visitFather(arg); 92 93 } 95 96 public void visit(Join arg) throws SqlWrapperException { 97 99 List list = arg.getPredicateList(); 100 treat(list); 101 visitFather(arg); 102 103 } 105 106 public void visit(BinOpOuterJoin arg) throws SqlWrapperException { 107 109 List list = arg.getPredicateList(); 110 treat(list); 111 visitFather(arg); 112 113 } 115 116 protected void treat(List list) { 117 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 } 127 128 protected void visitFather(Expression arg) { 129 Expression father = arg.getFather(); 131 if (father != null && getEndNode() != arg) { 132 father.accept(this); 133 } 134 } 136 } 137 | Popular Tags |