KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
26
27 import org.xquark.extractor.common.SqlWrapperException;
28 import org.xquark.extractor.runtime.IDProvider;
29 import org.xquark.extractor.sql.SqlExpression;
30
31 public final class RenameItem extends UnaryAtomicOp
32 {
33     private static final String JavaDoc RCSRevision = "$Revision: 1.6 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35
36     protected String JavaDoc _name;
37     private static final String JavaDoc ATTRIBUTE_ALIAS_PREFIX = "a";
38
39     public RenameItem(Expression Expr, IDProvider provider)
40     {
41         super(Expr);
42         setName(getUniqueName(provider));
43     }
44     
45     public RenameItem(Expression Expr, String JavaDoc name)
46     {
47         super (Expr);
48         setName(name);
49     }
50
51     public RenameItem(Expression Expr, String JavaDoc name, IDProvider provider)
52     {
53         super (Expr);
54         setName(name, provider);
55     }
56
57     synchronized Object JavaDoc clone(Map JavaDoc clonedExprs) throws CloneNotSupportedException JavaDoc
58     {
59         //Trace.enter(this, "clone(Map clonedExprs)");
60

61         RenameItem retVal = (RenameItem)super.clone(clonedExprs);
62         retVal.setName(getName());
63
64         clonedExprs.put(this, retVal);
65         //Trace.exit(this, "clone(Map clonedExprs)");
66
return retVal;
67     }
68
69     /**
70     Access method for the _name property.
71
72     @return the current value of the _name property
73      */

74     public String JavaDoc getName()
75     {
76         return _name;
77     }
78
79     /**
80     Sets the value of the _name property.
81
82     @param aName the new value of the _name property
83      */

84     public void setName(String JavaDoc aName)
85     {
86         _name = aName;
87     }
88
89     public void setName(String JavaDoc aName, IDProvider provider)
90     {
91         _name = getUniqueName(aName, provider);
92     }
93
94     public boolean replaceChild(Expression oldChild, Expression newChild)
95     {
96         //Trace.enter(this, "replaceChild(Expression oldChild, Expression newChild)");
97

98         boolean retVal = false;
99         if (getOperand() == oldChild) {
100             setOperand(newChild);
101             retVal = true;
102         }
103
104         //Trace.exit(this, "replaceChild(Expression oldChild, Expression newChild)");
105
return retVal;
106     }
107
108     public String JavaDoc pprint ()
109     {
110         return "renameItem(" + getOperand().pprint() + " AS " + getName() + ")";
111     }
112
113     public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException
114     {
115         return visitor.visit(this);
116     }
117
118     public void accept (AlgebraVisitor visitor) throws SqlWrapperException
119     {
120         visitor.visit(this);
121     }
122
123     private String JavaDoc getUniqueName(String JavaDoc name, IDProvider provider)
124     {
125         String JavaDoc retVal = null;
126         if (name.length() > 20)
127             retVal = name.substring(0,19) + "_" + provider.getID();
128         else
129             retVal = name + provider.getID();
130     
131         return retVal;
132     }
133
134     private String JavaDoc getUniqueName(IDProvider provider)
135     {
136         return getUniqueName(ATTRIBUTE_ALIAS_PREFIX, provider);
137     }
138
139     // NOTE; Expression#deepEquals(Object) not overridden cause alias names should
140
// not be considered for expression equality
141
}
142
Popular Tags