KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.HashSet JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import org.xquark.xquery.typing.TypeException;
30
31 public class XQueryExpressionSequence extends XQueryExpression {
32     private static final String JavaDoc RCSRevision = "$Revision: 1.10 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     ArrayList JavaDoc subExpressions = null; // ArrayList of XQueryExpression
36

37     // #############################################################################
38
// VISITOR STUFF
39
// #############################################################################
40

41     public void accept(ParserVisitor visitor) throws XQueryException {
42         visitor.visit(this);
43     }
44
45     // #############################################################################
46
// CONSTRUCTOR STUFF
47
// #############################################################################
48

49     public XQueryExpressionSequence(ArrayList JavaDoc subExpressions, XQueryModule parentModule) throws TypeException, XQueryException {
50         setSubExpressions(subExpressions);
51         setParentModule(parentModule);
52         if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null)
53             accept(parentModule.getStaticContext().getTypeVisitor());
54     }
55
56     // #############################################################################
57
// ATTRIBUTE ACCESS STUFF
58
// #############################################################################
59

60     public ArrayList JavaDoc getSubExpressions() {
61         return subExpressions;
62     }
63     public void setSubExpressions(ArrayList JavaDoc subExpressions) throws XQueryException {
64         if (subExpressions == null || subExpressions.isEmpty())
65             throw new XQueryException("subExpressions of XQueryExpressionSequence cannot be null or empty");
66         this.subExpressions = subExpressions;
67         for (int j = 0; j < this.subExpressions.size(); j++) {
68             XQueryExpression expression = (XQueryExpression) this.subExpressions.get(j);
69             expression.setParentExpression(this);
70             expression.setParentModule(parentModule);
71         }
72     }
73
74     public void addSubExpressions(XQueryExpression subExpression) throws XQueryException {
75         subExpressions.add(subExpression);
76         subExpression.setParentExpression(this);
77         subExpression.setParentModule(parentModule);
78     }
79
80     public void addSubExpressions(int index, XQueryExpression subExpression) throws XQueryException {
81         subExpressions.add(index, subExpression);
82         subExpression.setParentExpression(this);
83         subExpression.setParentModule(parentModule);
84     }
85
86     public Set JavaDoc getSourceNames() {
87         if (subExpressions == null)
88             return null;
89         Set JavaDoc tmplist = null;
90         for (int i = 0; i < subExpressions.size(); i++) {
91             XQueryExpression expressioni = (XQueryExpression) subExpressions.get(i);
92             if (expressioni.getSourceNames() != null) {
93                 if (tmplist == null)
94                     tmplist = new HashSet JavaDoc(expressioni.getSourceNames());
95                 else
96                     tmplist.addAll(expressioni.getSourceNames());
97             }
98         }
99         return tmplist;
100     }
101
102     public Set JavaDoc getUrls() {
103         if (subExpressions == null)
104             return null;
105         Set JavaDoc tmplist = null;
106         for (int i = 0; i < subExpressions.size(); i++) {
107             XQueryExpression expressioni = (XQueryExpression) subExpressions.get(i);
108             if (expressioni.getUrls() != null) {
109                 if (tmplist == null)
110                     tmplist = new HashSet JavaDoc(expressioni.getUrls());
111                 else
112                     tmplist.addAll(expressioni.getUrls());
113             }
114         }
115         return tmplist;
116     }
117
118     // #############################################################################
119
// CLONE STUFF
120
// #############################################################################
121
public void addParentExpression(XQueryExpression parentExpression) {
122         addParentExpression(parentExpression);
123         for (int j = 0; j < subExpressions.size(); j++)
124              ((XQueryExpression) subExpressions.get(j)).addParentExpression(parentExpression);
125     }
126
127 }
128
Popular Tags