KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > parser > SortedExpression


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.xquery.parser;
24
25 import java.util.ArrayList JavaDoc;
26
27 import org.xquark.xquery.typing.TypeException;
28
29 public class SortedExpression extends XQueryListUnaryOperatorExpression implements Cloneable JavaDoc {
30     private static final String JavaDoc RCSRevision = "$Revision: 1.9 $";
31     private static final String JavaDoc RCSName = "$Name: $";
32
33     // cannot be null or empty
34
protected ArrayList JavaDoc sortClauses = null;
35
36     // W3C WD 16 August 2002
37
protected boolean stable = false; // by default, implementation-defined
38

39     // #############################################################################
40
// CONSTRUCTOR STUFF
41
// #############################################################################
42
public SortedExpression(XQueryExpression expression, ArrayList JavaDoc sortClauses, boolean stable, XQueryModule parentModule) throws TypeException, XQueryException {
43         super(expression);
44
45         // W3C WD 16 August 2002
46
setStable(stable);
47         setSortClauses(sortClauses);
48
49         setParentModule(parentModule);
50         if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null)
51             accept(parentModule.getStaticContext().getTypeVisitor());
52     }
53
54     // #############################################################################
55
// VISITOR STUFF
56
// #############################################################################
57
public void accept(ParserVisitor visitor) throws XQueryException {
58         visitor.visit(this);
59     }
60
61     // #############################################################################
62
// ATTRIBUTE ACCESS STUFF
63
// #############################################################################
64
public void setParentModule(XQueryModule parentUnit) {
65         if (parentUnit == null) {
66             return;
67         }
68
69         this.parentModule = parentUnit;
70         super.setParentModule(parentUnit);
71
72         for (int i = 0; i < sortClauses.size(); i++)
73              ((XQueryExpression) sortClauses.get(i)).setParentModule(parentUnit);
74     }
75
76     public ArrayList JavaDoc getSortClauses() {
77         return sortClauses;
78     }
79
80     public void setSortClauses(ArrayList JavaDoc sortClauses) throws XQueryException {
81         // cannot be null or empty
82
if ((sortClauses == null) || sortClauses.isEmpty()) {
83             throw new XQueryException("sortClauses of SortedExpression cannot be null or empty");
84         }
85
86         this.sortClauses = sortClauses;
87
88         for (int i = 0; i < this.sortClauses.size(); i++) {
89             XQueryExpression expr = (XQueryExpression) this.sortClauses.get(i);
90             expr.setParentModule(parentModule);
91             expr.setParentExpression(this);
92         }
93     }
94
95     // W3C WD 16 August 2002
96
public void setStable(boolean stable) {
97         this.stable = stable;
98     }
99
100     public boolean getStable() {
101         return stable;
102     }
103
104     // #############################################################################
105
// CLONE STUFF
106
// #############################################################################
107
public void addParentExpression(XQueryExpression parentExpression) {
108         addParentExpression(parentExpression);
109         expression.addParentExpression(parentExpression);
110
111         for (int i = 0; i < sortClauses.size(); i++)
112              ((XQueryExpression) sortClauses.get(i)).addParentExpression(parentExpression);
113     }
114
115 }
116
Popular Tags