1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.Collection ; 26 27 import org.xquark.extractor.xfunctions.XFunction; 28 29 36 public class RenameAttributeExpressionVisitor extends DefaultCompleteVisitor { 37 38 private Collection _relations; 39 private RenameRelation _substitution; 40 private boolean _blockOnRenameItems = false; 41 private boolean _exclude = false; 42 43 public RenameAttributeExpressionVisitor() {} 44 45 public RenameAttributeExpressionVisitor(Collection renameRelations, RenameRelation substitution) { 46 reinit(renameRelations, substitution); 47 } 48 49 public void reinit(Collection renameRelations, RenameRelation substitution, 50 boolean blockOnRenameItems, boolean exclude) { 51 _relations = renameRelations; 52 _substitution = substitution; 53 _blockOnRenameItems = blockOnRenameItems; 54 _exclude = exclude; 55 } 56 public void reinit(Collection renameRelations, RenameRelation substitution) { 57 reinit(renameRelations, substitution, false, false); 58 } 59 60 public void reinit(RenameRelation substitution, boolean blockOnRenameItems) { 61 reinit(null, substitution, blockOnRenameItems, false); 62 } 63 64 public void reinit(RenameRelation substitution) { 65 reinit(substitution, false); 66 } 67 68 public Expression getVisitedExpression() { 69 return expr; 70 } 71 72 public void visit(AttributeExpression arg) { 73 if (_relations == null || (_relations.contains(arg.getTableInstance()) == !_exclude)) 74 arg.setTableInstance(_substitution); 75 expr = arg; 76 } 77 78 public void visit(RenameItem arg) { 79 if (_blockOnRenameItems) { 80 AttributeExpression attExpr = new AttributeExpression(_substitution, arg.getName()); 81 attExpr.setUnderlyingExpr(arg.getOperand()); 82 arg._father.replaceChild(arg, attExpr); 83 expr = attExpr; 84 } 85 else { 86 super.visit((UnaryAtomicOp)arg); 87 expr = arg; 88 } 89 } 90 91 public void visit(RenameRelation arg) { expr = arg;} 92 93 public void visit(BinaryAtomicOp arg){ 94 super.visit(arg); 95 expr = arg; 96 } 97 98 public void visit(UnaryAtomicOp arg) { 99 super.visit(arg); 100 expr = arg; 101 } 102 103 public void visit(XFunction arg) { 104 super.visit(arg); 105 expr = arg; 106 } 107 } 108 | Popular Tags |