KickJava   Java API By Example, From Geeks To Geeks.

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


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
29
30
31 public class SetVariablePathsVisitor extends DefaultParserVisitor {
32     
33     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35     
36         
37     public SetVariablePathsVisitor() {}
38            
39     public void visit(Element arg) throws XQueryException {
40         if (arg.getStartTag() != null) {
41             arg.getStartTag().accept(this);
42         }
43         if (arg.getAttributes() != null) {
44             for (int i = 0; i < arg.getAttributes().size(); i++) {
45                 ((AttributeValuePair)arg.getAttributes().get(i)).accept(this);
46             }
47         }
48         if (arg.getSubExpressions() != null) {
49             for (int j = 0; j < arg.getSubExpressions().size(); j++) {
50                 ((XQueryExpression)arg.getSubExpressions().get(j)).accept(this);
51             }
52         }
53     }
54         
55     public void visit(FunctionCall arg) throws XQueryException {
56         if (arg.getArguments() != null) {
57             for (int i = 0; i < arg.getArguments().size(); i++) {
58                 ((XQueryExpression)arg.getArguments().get(i)).accept(this);
59             }
60         }
61     }
62     
63     public void visit(FLWRExpression arg) throws XQueryException {
64         ArrayList JavaDoc list = arg.getVariables();
65         for (int i=0;i<list.size();i++) {
66             XQueryExpression expri = ((Variable)list.get(i)).getExpression();
67             if (expri instanceof FLWRExpression)
68                 expri.accept(this);
69         }
70         list = arg.getOrderBy();
71         if (list != null)
72             for (int i=0;i<list.size();i++)
73                 ((XQueryExpression)list.get(i)).accept(this);
74         if (arg.getReturnClause() instanceof FLWRExpression)
75             arg.getReturnClause().accept(this);
76     }
77
78     public void visit(LocatedExpression arg) throws XQueryException {
79         if (arg.getExpression() instanceof Variable) {
80             ((Variable)arg.getExpression()).addSubPath(arg);
81         }
82     }
83     
84     public void visit(Variable arg) throws XQueryException {
85         arg.addSubPath(arg);
86     }
87     
88     public void visit(ITEExpression arg) throws XQueryException {
89         arg.getIfExpression().accept(this);
90         arg.getThenExpression().accept(this);
91         arg.getElseExpression().accept(this);
92     }
93
94     public void visit(XQueryBinaryOperatorExpression arg) throws XQueryException {
95         if (arg.getExpression1() != null) {
96             arg.getExpression1().accept(this);
97         }
98         if (arg.getExpression2() != null) {
99             arg.getExpression2().accept(this);
100         }
101     }
102     
103     
104     //public void visit(XQueryExpression arg) throws XQueryException {}
105

106     
107     public void visit(XQueryExpressionSequence arg) throws XQueryException {
108         for (int i = 0; i < arg.getSubExpressions().size(); i++) {
109             ((XQueryExpression)arg.getSubExpressions().get(i)).accept(this);
110         }
111     }
112     
113     public void visit(XQueryUnaryOperatorExpression arg) throws XQueryException {
114         if (arg.getExpression() != null) {
115             arg.getExpression().accept(this);
116         }
117     }
118     
119     
120 }
121
Popular Tags