KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.SqlExpression;
29
30 public final class SortSpecification extends Expression {
31
32     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     private Expression _sortExpression;
36     private int _sortDirection;
37
38     /**
39      * @param sortExpression
40      * @param sortDirection
41      * @roseuid 3AB8681D0255
42      */

43     public SortSpecification(Expression sortExpression, int sortDirection) {
44         setSortExpression(sortExpression);
45         _sortDirection = sortDirection;
46     }
47
48     // synchronized Object clone(Map clonedExprs) throws CloneNotSupportedException
49
// {
50
// Trace.enter(this, "clone(Map clonedExprs)");
51
// SortSpecification retVal = (SortSpecification)super.clone();
52
// retVal.setSortExpression((getSortExpression() == null) ? null : (Expression)getSortExpression().clone ());
53
// clonedExpr.put(this, retVal);Trace.exit(this, "clone(Map clonedExprs)");return retVal;
54
// return retVal;
55
// }
56

57     synchronized Object JavaDoc clone(Map JavaDoc clonedExprs) throws CloneNotSupportedException JavaDoc {
58         //Trace.enter(this, "clone(Map clonedExprs)");
59

60         SortSpecification retVal = (SortSpecification) super.clone(clonedExprs);
61         retVal.setSortExpression((getSortExpression() == null) ? null : (Expression) getSortExpression().clone(clonedExprs));
62         clonedExprs.put(this, retVal);
63         //Trace.exit(this, "clone(Map clonedExprs)");
64
return retVal;
65     }
66
67     /**
68      * Access method for the _sortExpression property.
69      *
70      * @return the current value of the _sortExpression property
71      */

72     public Expression getSortExpression() {
73         return _sortExpression;
74     }
75
76     public java.util.List JavaDoc getOperands() {
77         return null;
78     }
79
80     /**
81      * Sets the value of the _sortExpression property.
82      *
83      * @param aSortExpression the new value of the _sortExpression property
84      */

85     public void setSortExpression(Expression aSortExpression) {
86         //sortExpression = aSortExpression;
87
_sortExpression = aSortExpression;
88         _sortExpression.setFather(this);
89     }
90
91     /**
92      * @return int
93      * @roseuid 3AB8687203DD
94      */

95     public int getSortDirection() {
96         return _sortDirection;
97     }
98
99     /**
100      * @param sortDirection
101      * @roseuid 3B27597200D3
102      */

103     public void setSortDirection(int sortDirection) {
104         _sortDirection = sortDirection;
105     }
106
107     public boolean replaceChild(Expression oldChild, Expression newChild) {
108         //Trace.enter(this, "replaceChild(Expression oldChild, Expression newChild)");
109

110         boolean retVal = false;
111         if (getSortExpression() == oldChild) {
112             setSortExpression(newChild);
113             retVal = true;
114         }
115
116         //Trace.exit(this, "replaceChild(Expression oldChild, Expression newChild)");
117
return retVal;
118     }
119
120     public String JavaDoc pprint() {
121         String JavaDoc retVal = null;
122         if (getSortDirection() == ASCENDING_ORDER) {
123             return getSortExpression().pprint() + " ASC";
124         } else {
125             return getSortExpression().pprint() + " DESC";
126         }
127     }
128
129     public SqlExpression accept(GenSqlVisitor visitor) throws SqlWrapperException {
130         return visitor.visit(this);
131     }
132
133     public void accept(AlgebraVisitor visitor) throws SqlWrapperException {
134         visitor.visit(this);
135     }
136
137     /**
138      * @see Expression#deepEquals(Object)
139      */

140     public boolean deepEquals(Object JavaDoc o) {
141         if (o instanceof SortSpecification) {
142             SortSpecification cast = (SortSpecification) o;
143             return _sortDirection == cast.getSortDirection() && _sortExpression.deepEquals(cast.getSortExpression());
144         }
145         return false;
146     }
147 }
148
Popular Tags