1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.List ; 26 import java.util.Map ; 27 28 import org.xquark.extractor.common.SqlWrapperException; 29 import org.xquark.extractor.sql.SqlExpression; 30 31 public class AttributeExpression extends Expression 32 { 33 34 private static final String RCSRevision = "$Revision: 1.5 $"; 35 private static final String RCSName = "$Name: $"; 36 37 protected String _attribute; 38 protected RenameRelation _tableInstance; 39 protected Expression _underlyingExpr; 40 41 protected AttributeExpression() 42 { 43 } 44 50 51 public AttributeExpression(RenameRelation tableInstance, String attribute) 52 { 53 setTableInstance (tableInstance); 54 setAttribute(attribute); 55 } 56 57 synchronized Object clone(Map clonedExprs) throws CloneNotSupportedException 58 { 59 AttributeExpression retVal = (AttributeExpression)super.clone(clonedExprs); 61 Expression clonedExpr = null; 62 63 retVal.setAttribute(getAttribute()); 64 65 if (_tableInstance != null) { 66 clonedExpr = (Expression)clonedExprs.get(_tableInstance); 67 if (null == clonedExpr) { 68 clonedExpr = (Expression)_tableInstance.clone(clonedExprs); 69 } 70 retVal.setTableInstance((RenameRelation)clonedExpr); 71 } 72 73 if (_underlyingExpr != null) { 74 clonedExpr = (Expression)clonedExprs.get(_underlyingExpr); 75 if (null == clonedExpr) { 76 clonedExpr = (Expression)_underlyingExpr.clone(clonedExprs); 77 } 78 retVal.setUnderlyingExpr(clonedExpr); 79 } 80 81 clonedExprs.put(this, retVal); 82 return retVal; 84 } 85 86 public boolean equals (Object o) 87 { 88 if (o == this) 89 return true; 90 if (!(o instanceof AttributeExpression)) 91 return false; 92 AttributeExpression p = (AttributeExpression) o; 93 94 RenameRelation pTi = p.getTableInstance(); 95 96 if (null == getTableInstance() && null == pTi) { 97 } 98 else if (null == getTableInstance() || null == pTi) { 99 return false; 100 } 101 else if ( ! getTableInstance().equals(p.getTableInstance()) ) { 102 return false; 103 } 104 105 if ( ! getName().equalsIgnoreCase(p.getName()) ) 106 return false; 107 return true; 108 } 109 110 public int hashCode() 111 { 112 if (null != _tableInstance) { 113 String str = _tableInstance.getName()+ "." + _attribute; 114 return str.hashCode(); 115 } 116 else { 117 return _attribute.hashCode(); 118 } 119 } 120 121 126 public String getAttribute() 127 { 128 return _attribute; 129 } 130 131 136 public void setAttribute(String aAttribute) 137 { 138 _attribute = aAttribute; 139 } 140 141 146 public RenameRelation getTableInstance() 147 { 148 return _tableInstance; 149 } 150 151 public List getOperands() 152 { 153 return null; 154 } 155 156 161 public void setTableInstance(RenameRelation aTableInstance) 162 { 163 _tableInstance = aTableInstance; 164 } 165 166 public String getName() 167 { 168 return _attribute; 169 } 170 175 public Expression getUnderlyinExpr() 176 { 177 return _underlyingExpr; 178 } 179 180 185 public void setUnderlyingExpr(Expression aUnderlyinExpr) 186 { 187 _underlyingExpr = aUnderlyinExpr; 188 while (_underlyingExpr instanceof AttributeExpression 189 || _underlyingExpr instanceof RenameItem) { 190 if (_underlyingExpr instanceof AttributeExpression) 191 _underlyingExpr = ((AttributeExpression)_underlyingExpr).getUnderlyinExpr(); 192 else 193 _underlyingExpr = ((RenameItem)_underlyingExpr).getOperand(); 194 } 195 } 196 197 public String pprint () 198 { 199 StringBuffer retVal = new StringBuffer (); 200 if (null != _tableInstance) { 201 retVal.append(getTableInstance().getName()); 202 retVal.append("."); 203 } 204 retVal.append(_attribute); 205 return retVal.toString(); 206 } 207 208 public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException 209 { 210 return visitor.visit(this); 211 } 212 213 public void accept (AlgebraVisitor visitor) throws SqlWrapperException 214 { 215 visitor.visit(this); 216 } 217 218 223 public boolean deepEquals(Object o) 224 { 225 if (o instanceof AttributeExpression) 226 { 227 AttributeExpression cast = (AttributeExpression)o; 228 return _attribute.equalsIgnoreCase(cast.getAttribute()) 229 && (_tableInstance.getName().equalsIgnoreCase(cast.getTableInstance().getName()) 230 || _tableInstance.deepEquals(cast.getTableInstance())); } 233 return false; 234 } 235 } 236 | Popular Tags |