KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2004 XQuark Group.
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.xpath.Axis;
28 import org.xquark.xquery.typing.TypeException;
29
30 public class SchemaContextPath extends XQueryExpression implements Cloneable JavaDoc {
31
32     private static final String JavaDoc RCSRevision = "$Revision: 1.8 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     // cannot be null or empty
36
protected ArrayList JavaDoc steps = null;
37
38     // #############################################################################
39
// VISITOR STUFF
40
// #############################################################################
41

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

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

62     public SchemaContextStep getStep(int num) {
63         if (num >= steps.size())
64             return null;
65         return (SchemaContextStep) steps.get(num);
66     }
67 // public SchemaContextStep getGlobalContext() {
68
// return ((SchemaContextStep)steps.get(0)).getExpression();
69
// }
70
public ArrayList JavaDoc getSteps() {
71         return steps;
72     }
73     public void setSteps(ArrayList JavaDoc steps) throws XQueryException {
74         // cannot be null or empty
75
if (steps == null || steps.isEmpty())
76             throw new XQueryException("steps of SchemaContextPath cannot be null or empty");
77         this.steps = steps;
78         for (int i = 0; i < this.steps.size(); i++) {
79             SchemaContextStep step = (SchemaContextStep) this.steps.get(i);
80             step.setParentExpression(this);
81             step.setParentModule(parentModule);
82         }
83     }
84
85     public void addStep(SchemaContextStep step) throws XQueryException {
86         if (step == null)
87             return;
88         if (steps == null)
89             steps = new ArrayList JavaDoc(1);
90         steps.add(step);
91         setSteps(steps);
92     }
93
94     public void addSteps(ArrayList JavaDoc steps) throws XQueryException {
95         if (steps == null || steps.isEmpty())
96             return;
97         if (this.steps == null || this.steps.isEmpty()) {
98             setSteps(steps);
99             return;
100         }
101         this.steps.addAll(steps);
102         setSteps(this.steps);
103     }
104
105     public void addStepsAt(int index, ArrayList JavaDoc steps) throws XQueryException {
106         if (steps == null || steps.isEmpty())
107             return;
108         if (this.steps == null || this.steps.isEmpty()) {
109             setSteps(steps);
110             return;
111         }
112         this.steps.addAll(index, steps);
113         setSteps(this.steps);
114     }
115
116     public boolean isRelativeExpression() {
117         Step step0 = (Step)steps.get(0);
118         if (step0.getAxis() == Axis.NONE && !step0.hasSeparator())
119             return false;
120         return true;
121     }
122
123     // #############################################################################
124
// CLONE STUFF
125
// #############################################################################
126
public void addParentExpression(XQueryExpression parentExpression) {
127         addParentExpression(parentExpression);
128         for (int i = 0; i < steps.size(); i++)
129              ((SchemaContextStep) steps.get(i)).addParentExpression(parentExpression);
130     }
131
132 }
133
Popular Tags