KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
26
27 import org.xquark.xquery.typing.TypeException;
28
29 public class Element extends XQueryExpression implements Cloneable JavaDoc {
30
31     private static final String JavaDoc RCSRevision = "$Revision: 1.12 $";
32     private static final String JavaDoc RCSName = "$Name: $";
33
34     // cannot be null
35
protected XQueryExpression startTag = null;
36     
37     protected HashMap localPrefixes = null;
38
39     // false by default
40
protected boolean computed = false;
41     private byte numComputedNS = 0;
42     private byte numComputedAtt = 0;
43     ArrayList attributes = null; // ArrayList of AttributeValuePair
44
ArrayList subExpressions = null; // ArrayList of XQueryExpression
45

46     // #############################################################################
47
// VISITOR STUFF
48
// #############################################################################
49

50     public void accept(ParserVisitor visitor) throws XQueryException {
51         visitor.visit(this);
52     }
53
54     // #############################################################################
55
// CONSTRUCTOR STUFF
56
// #############################################################################
57

58     public Element(XQueryExpression startTag, HashMap localPrefixes, ArrayList attributes, ArrayList subExpressions, XQueryModule parentModule) throws TypeException, XQueryException {
59         setStartTag(startTag);
60         setLocalPrefixes(localPrefixes);
61         setAttributes(attributes);
62         setSubExpressions(subExpressions);
63         setIsComputed(false);
64         setParentModule(parentModule);
65         if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null)
66             accept(parentModule.getStaticContext().getTypeVisitor());
67     }
68
69     public Element(QName startTag, HashMap localPrefixes, ArrayList attributes, ArrayList subExpressions, XQueryModule parentModule) throws TypeException, XQueryException {
70         setStartTag(startTag);
71         setLocalPrefixes(localPrefixes);
72         setAttributes(attributes);
73         setSubExpressions(subExpressions);
74         setIsComputed(false);
75         setParentModule(parentModule);
76         if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null)
77             accept(parentModule.getStaticContext().getTypeVisitor());
78     }
79
80     // #############################################################################
81
// ATTRIBUTE ACCESS STUFF
82
// #############################################################################
83

84     public XQueryExpression getStartTag() {
85         return startTag;
86     }
87     public void setStartTag(XQueryExpression startTag) throws XQueryException {
88         if (startTag == null)
89             throw new XQueryException("startTag of Element cannot be null");
90         this.startTag = startTag;
91         this.startTag.setParentExpression(this);
92         this.startTag.setParentModule(parentModule);
93     }
94
95     public HashMap getLocalPrefixes() {
96         return localPrefixes;
97     }
98     public void setLocalPrefixes(HashMap localPrefixes) {
99         this.localPrefixes = localPrefixes;
100     }
101
102     public ArrayList getAttributes() {
103         return attributes;
104     }
105     public void setAttributes(ArrayList attributes) {
106         this.attributes = attributes;
107         if (this.attributes != null)
108             for (int j = 0; j < this.attributes.size(); j++) {
109                 AttributeValuePair attributeValuePair = (AttributeValuePair) this.attributes.get(j);
110                 attributeValuePair.setParentExpression(this);
111                 attributeValuePair.setParentModule(parentModule);
112             }
113     }
114
115     public ArrayList getSubExpressions() {
116         return subExpressions;
117     }
118     public void setSubExpressions(ArrayList subExpressions) {
119         this.subExpressions = subExpressions;
120         if (this.subExpressions != null)
121             for (int j = 0; j < this.subExpressions.size(); j++) {
122                 XQueryExpression expression = (XQueryExpression) this.subExpressions.get(j);
123                 expression.setParentExpression(this);
124                 expression.setParentModule(parentModule);
125             }
126     }
127
128     public boolean isComputed() {
129         return computed;
130     }
131
132     public void setIsComputed(boolean computed) {
133         this.computed = computed;
134     }
135
136     public byte getComputedAttNum() {
137         return numComputedAtt;
138     }
139     
140     public void setComputedAttNum(byte num) {
141         numComputedAtt = num;
142     }
143     
144     public byte getComputedNSNum() {
145         return numComputedNS;
146     }
147     
148     public void setComputedNSNum(byte num) {
149         numComputedNS = num;
150     }
151
152     public void addSubExpressions(XQueryExpression subExpression) throws XQueryException {
153         subExpressions.add(subExpression);
154         subExpression.setParentExpression(this);
155         subExpression.setParentModule(parentModule);
156     }
157
158     public void addSubExpressions(int index, XQueryExpression subExpression) throws XQueryException {
159         subExpressions.add(index, subExpression);
160         subExpression.setParentExpression(this);
161         subExpression.setParentModule(parentModule);
162     }
163
164     public void addAttributes(AttributeValuePair attribute) throws XQueryException {
165         if (attributes == null)
166             attributes = new ArrayList();
167         attributes.add(attribute);
168         attribute.setParentExpression(this);
169         attribute.setParentModule(parentModule);
170     }
171
172     public void addSubExpressions(int index, AttributeValuePair attribute) throws XQueryException {
173         attributes.add(index, attribute);
174         attribute.setParentExpression(this);
175         attribute.setParentModule(parentModule);
176     }
177
178     public Set getSourceNames() {
179         if (sourceNames != null) return sourceNames;
180         if (subExpressions == null) return null;
181         Set tmplist = null;
182         for (int i = 0; i < subExpressions.size(); i++) {
183             XQueryExpression expressioni = (XQueryExpression) subExpressions.get(i);
184             if (expressioni.getSourceNames() != null && !expressioni.getSourceNames().isEmpty()) {
185                 if (tmplist == null)
186                     tmplist = new HashSet(expressioni.getSourceNames());
187                 else
188                     tmplist.addAll(expressioni.getSourceNames());
189             }
190         }
191         return tmplist;
192     }
193
194     public Set getUrls() {
195         if (urls != null) return urls;
196         if (subExpressions == null) return null;
197         Set tmplist = null;
198         for (int i = 0; i < subExpressions.size(); i++) {
199             XQueryExpression expressioni = (XQueryExpression) subExpressions.get(i);
200             if (expressioni.getUrls() != null && !expressioni.getUrls().isEmpty()) {
201                 if (tmplist == null)
202                     tmplist = new HashSet(expressioni.getUrls());
203                 else
204                     tmplist.addAll(expressioni.getUrls());
205             }
206         }
207         return tmplist;
208     }
209
210     // #############################################################################
211
// CLONE STUFF
212
// #############################################################################
213
public void addParentExpression(XQueryExpression parentExpression) {
214         addParentExpression(parentExpression);
215
216         startTag.addParentExpression(parentExpression);
217         if (this.attributes != null)
218             for (int j = 0; j < this.attributes.size(); j++)
219                  ((AttributeValuePair) this.attributes.get(j)).addParentExpression(parentExpression);
220         if (subExpressions != null)
221             for (int j = 0; j < subExpressions.size(); j++)
222                  ((XQueryExpression) subExpressions.get(j)).addParentExpression(parentExpression);
223     }
224
225
226 }
227
Popular Tags