KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > normalize > AtomizeVisitor


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.normalize;
24
25 import java.util.ArrayList JavaDoc;
26
27 import org.xquark.xquery.parser.*;
28 import org.xquark.xquery.typing.TypeVisitor;
29
30 public class AtomizeVisitor extends DefaultParserVisitor {
31     
32
33     private XQueryExpression resultExpr = null;
34     private TypeVisitor typeVisitor = null;
35     private boolean isSpecial = false;
36     
37     
38     AtomizeVisitor(TypeVisitor typeVisitor) {
39         this.typeVisitor = typeVisitor;
40     }
41     
42     public XQueryExpression getExpression() {
43         isSpecial = false;
44         return resultExpr;
45     }
46     
47     public void isSpecial() {
48         isSpecial= true;
49     }
50     
51 // public void visit(AggregateFunctionCall arg) throws XQueryException;
52

53     public void visit(AttributeValuePair arg) throws XQueryException {
54         arg.getExpression2().accept(this);
55     }
56
57 // public void visit(BinOpANDExpression arg) throws XQueryException;
58
// public void visit(BinOpORExpression arg) throws XQueryException;
59
// public void visit(CaseClauseExpression arg) throws XQueryException;
60
// public void visit(CastTreatExpression arg) throws XQueryException;
61
// public void visit(CData arg) throws XQueryException;
62
// public void visit(ComputedNamespace arg) throws XQueryException;
63
// public void visit(ComputedText arg) throws XQueryException;
64
// public void visit(ContextDeclaration arg) throws XQueryException;
65
// public void visit(Document arg) throws XQueryException;
66

67     public void visit(Element arg) throws XQueryException {
68         if (isSpecial) {
69             resultExpr = new ValueInteger("1",arg.getParentModule());
70             return;
71         }
72         ArrayList JavaDoc list = arg.getSubExpressions();
73         if (list != null) {
74             if (list.size() == 1)
75                 resultExpr = (XQueryExpression)list.get(0);
76             else
77                 resultExpr = new XQueryExpressionSequence(list, arg.getParentModule());
78         } else
79             resultExpr = null;
80     }
81     
82     public void visit(FLWRExpression arg) throws XQueryException {
83         if (isSpecial) {
84             if (!(arg.getReturnClause() instanceof Value))
85                 //arg.setReturnClause((XQueryExpression)arg.getVariables().get(0));
86
arg.setReturnClause(new ValueInteger("1",arg.getParentModule()));
87         } else {
88             arg.getReturnClause().accept(this);
89             arg.setReturnClause(resultExpr);
90         }
91         resultExpr = arg;
92     }
93     
94 // public void visit(FunctionCall arg) throws XQueryException;
95
// public void visit(FunctionDeclaration arg) throws XQueryException;
96
// public void visit(InstanceOfExpression arg) throws XQueryException;
97
// public void visit(InternalFunctionCall arg) throws XQueryException;
98
// public void visit(ITEExpression arg) throws XQueryException;
99
// public void visit(ItemType arg) throws XQueryException;
100
// public void visit(LibraryFunctionCall arg) throws XQueryException;
101
// public void visit(ListOpAFTERExpression arg) throws XQueryException;
102
// public void visit(ListOpArithExpression arg) throws XQueryException;
103
// public void visit(ListOpBEFOREExpression arg) throws XQueryException;
104
// public void visit(ListOpCompExpression arg) throws XQueryException;
105
// public void visit(ListOpEXCEPTExpression arg) throws XQueryException;
106
// public void visit(ListOpINTERSECTExpression arg) throws XQueryException;
107
// public void visit(ListOpUNIONExpression arg) throws XQueryException;
108
// public void visit(LocatedExpression arg) throws XQueryException;
109
// public void visit(ElementTest arg) throws XQueryException;
110
// public void visit(AttributeTest arg) throws XQueryException;
111
// public void visit(NodeTest arg) throws XQueryException;
112
// public void visit(PrimitiveFunctionCall arg) throws XQueryException;
113
// public void visit(QName arg) throws XQueryException;
114
// public void visit(QuantifiedExpression arg) throws XQueryException;
115
// public void visit(RangeExpression arg) throws XQueryException;
116
// public void visit(RootNodeFunctionCall arg) throws XQueryException;
117
// public void visit(SchemaContextPath arg) throws XQueryException;
118
// public void visit(SchemaContextStep arg) throws XQueryException;
119
// public void visit(SequenceType arg) throws XQueryException;
120
// public void visit(SortedExpression arg) throws XQueryException;
121
// public void visit(Step arg) throws XQueryException;
122
// public void visit(TypeSwitchExpression arg) throws XQueryException;
123
// public void visit(UnOpMinusExpression arg) throws XQueryException;
124
// public void visit(ValidateExpression arg) throws XQueryException;
125
// public void visit(Value arg) throws XQueryException;
126
// public void visit(ValueBoolean arg) throws XQueryException;
127
// public void visit(ValueDecimal arg) throws XQueryException;
128
// public void visit(ValueDouble arg) throws XQueryException;
129
// public void visit(ValueFloat arg) throws XQueryException;
130
// public void visit(ValueInteger arg) throws XQueryException;
131
// public void visit(ValueString arg) throws XQueryException;
132
// public void visit(ValueText arg) throws XQueryException;
133
// public void visit(Variable arg) throws XQueryException;
134
// public void visit(XMLComment arg) throws XQueryException;
135
// public void visit(XMLProcessingInstruction arg) throws XQueryException;
136
// public void visit(XQueryBinaryOperatorExpression arg) throws XQueryException;
137
// public void visit(XQueryBooleanOperatorExpression arg) throws XQueryException;
138

139     public void visit(XQueryExpression arg) throws XQueryException {
140         resultExpr = arg;
141     }
142     
143     public void visit(XQueryExpressionSequence arg) throws XQueryException {
144         ArrayList JavaDoc list = arg.getSubExpressions();
145         if (list != null) {
146             if (list.size() == 1) {
147                 ((XQueryExpression)list.get(0)).accept(this);
148             } else {
149                 for (int i=0;i<list.size();i++) {
150                     XQueryExpression expri = (XQueryExpression)list.get(i);
151                     expri.accept(this);
152                     if (resultExpr != null)
153                         list.set(i,resultExpr);
154                     else {
155                         list.remove(i);
156                         i--;
157                     }
158                 }
159                 if (list.size() == 0)
160                     resultExpr = null;
161                 else if (list.size() == 1)
162                     resultExpr = (XQueryExpression)list.get(0);
163                 else
164                     resultExpr = arg;
165             }
166         }
167     }
168 // public void visit(XQueryListBinaryOperatorExpression arg) throws XQueryException;
169
// public void visit(XQueryListUnaryOperatorExpression arg) throws XQueryException;
170
// public void visit(XQueryUnaryOperatorExpression arg) throws XQueryException;
171
// public void visit(XQueryModule arg) throws XQueryException;
172
// public void visit(XQueryVoid arg) throws XQueryException;
173

174     // primitive functions
175

176 // public void visit(FunctionABS arg) throws XQueryException ;
177
// public void visit(FunctionAVG arg) throws XQueryException ;
178
// public void visit(FunctionCEILING arg) throws XQueryException;
179
// public void visit(FunctionCOLLECTION arg) throws XQueryException;
180
// public void visit(FunctionCONCAT arg) throws XQueryException;
181
// public void visit(FunctionCONTAINS arg) throws XQueryException;
182
// public void visit(FunctionCOUNT arg) throws XQueryException;
183
// public void visit(FunctionCURRENT_DATE arg) throws XQueryException;
184
// public void visit(FunctionCURRENT_DATETIME arg) throws XQueryException;
185
// public void visit(FunctionCURRENT_TIME arg) throws XQueryException;
186
// public void visit(FunctionDATA arg) throws XQueryException;
187
// public void visit(FunctionDATE arg) throws XQueryException;
188
// public void visit(FunctionDATETIME arg) throws XQueryException;
189
// public void visit(FunctionDECIMAL arg) throws XQueryException;
190
// public void visit(FunctionDISTINCT_VALUES arg) throws XQueryException;
191
// public void visit(FunctionDOC arg) throws XQueryException;
192
// public void visit(FunctionDOUBLE arg) throws XQueryException;
193
// public void visit(FunctionEMPTY arg) throws XQueryException;
194
// public void visit(FunctionENDS_WITH arg) throws XQueryException;
195
// public void visit(FunctionEXISTS arg) throws XQueryException;
196
// public void visit(FunctionGET_MONTH_FROM_DATE arg) throws XQueryException;
197
// public void visit(FunctionGET_YEAR_FROM_DATE arg) throws XQueryException;
198
// public void visit(FunctionFALSE arg) throws XQueryException;
199
// public void visit(FunctionFLOOR arg) throws XQueryException;
200
// public void visit(FunctionINTEGER arg) throws XQueryException;
201
// public void visit(FunctionLOCAL_NAME arg) throws XQueryException;
202
// public void visit(FunctionLOWER_CASE arg) throws XQueryException;
203
// public void visit(FunctionMATCHES arg) throws XQueryException;
204
// public void visit(FunctionMAX arg) throws XQueryException;
205
// public void visit(FunctionMIN arg) throws XQueryException;
206
// public void visit(FunctionNAMESPACE_URI arg) throws XQueryException;
207
// public void visit(FunctionNOT arg) throws XQueryException;
208
// public void visit(FunctionNUMBER arg) throws XQueryException;
209
// public void visit(FunctionROUND arg) throws XQueryException;
210
// public void visit(FunctionSTARTS_WITH arg) throws XQueryException;
211
// public void visit(FunctionSTRING arg) throws XQueryException;
212
// public void visit(FunctionSTRING_LENGTH arg) throws XQueryException;
213
// public void visit(FunctionSUBSTRING arg) throws XQueryException;
214
// public void visit(FunctionSUM arg) throws XQueryException;
215
// public void visit(FunctionTIME arg) throws XQueryException;
216
// public void visit(FunctionTRUE arg) throws XQueryException;
217
// public void visit(FunctionUPPER_CASE arg) throws XQueryException;
218
// public void visit(FunctionDEEP_EQUALS arg) throws XQueryException;
219
}
220
Popular Tags