1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.Map ; 26 27 import org.xquark.extractor.common.SqlWrapperException; 28 29 34 public class TopDownReplacer extends DefaultCompleteVisitor { 35 36 private static final String RCSRevision = "$Revision: 1.4 $"; 37 private static final String RCSName = "$Name: $"; 38 39 Map _replaceMap = null; 40 41 public TopDownReplacer() { 42 } 43 44 public TopDownReplacer(Map replaceMap) { 45 _replaceMap = replaceMap; 46 } 47 48 public void setReplaceMap(Map replaceMap) { 49 _replaceMap = replaceMap; 50 } 51 52 public Map getReplaceMap() { 53 return _replaceMap; 54 } 55 56 public void visit(Expression arg) { 57 Expression replacer = (Expression) _replaceMap.get(arg); 59 60 if (null != replacer) { 61 arg.getFather().replaceChild(arg, replacer); 62 } 64 } 66 67 public void visit(AttributeExpression arg) throws SqlWrapperException { 68 70 Expression replacer = (Expression) _replaceMap.get(arg); 71 72 if (null != replacer) { 73 arg.getFather().replaceChild(arg, replacer); 74 } else { 76 77 Object ti = arg.getTableInstance(); 78 Object tableInstance = null; 79 if (null != ti) { 80 tableInstance = _replaceMap.get(ti); 81 } 82 83 if (null == tableInstance) { 84 } else if (tableInstance instanceof NullPointer) { 85 arg.setTableInstance(null); 86 } else { 87 arg.setTableInstance((RenameRelation) tableInstance); 88 } 89 } 90 } 92 93 public void visit(SortSpecification arg) throws SqlWrapperException { 94 96 AttributeExpression sortExpr = (AttributeExpression) arg.getSortExpression(); 97 sortExpr.accept(this); 98 Expression uderlyingExpr = sortExpr.getUnderlyinExpr(); 99 if (uderlyingExpr instanceof AttributeExpression) { 100 Expression replacer = (Expression) _replaceMap.get(uderlyingExpr); 101 102 if (null != replacer) { 103 sortExpr.setUnderlyingExpr(replacer); 104 } 105 } 106 } 108 } 109 | Popular Tags |