KickJava   Java API By Example, From Geeks To Geeks.

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


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 TypeSwitchExpression extends XQueryBinaryOperatorExpression implements Cloneable JavaDoc {
30
31     private static final String JavaDoc RCSRevision = "$Revision: 1.9 $";
32     private static final String JavaDoc RCSName = "$Name: $";
33
34     // cannot be null
35
protected HashMap cases = null;
36     // can be null
37
protected Variable defaultVariable = null;
38
39     // #############################################################################
40
// VISITOR STUFF
41
// #############################################################################
42

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

51     public TypeSwitchExpression(XQueryExpression switchExpression, HashMap cases, Variable defaultVariable, XQueryExpression defaultExpression, XQueryModule parentModule) throws TypeException, XQueryException {
52         super(switchExpression, defaultExpression);
53         setCases(cases);
54         setDefaultVariable(defaultVariable);
55         setParentModule(parentModule);
56         if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null)
57             accept(parentModule.getStaticContext().getTypeVisitor());
58     }
59
60     // #############################################################################
61
// ATTRIBUTE ACCESS STUFF
62
// #############################################################################
63

64     public void setParentModule(XQueryModule parentUnit) {
65         if (parentUnit == null)
66             return;
67         this.parentModule = parentUnit;
68         super.setParentModule(parentUnit);
69         Set entries = cases.entrySet();
70         Iterator it = entries.iterator();
71         while (it.hasNext()) {
72             Map.Entry entry = (Map.Entry) it.next();
73             ((QName) entry.getKey()).setParentModule(parentUnit);
74             ((XQueryExpression) entry.getValue()).setParentModule(parentUnit);
75         }
76         if (defaultVariable != null)
77             defaultVariable.setParentModule(parentUnit);
78     }
79
80     public HashMap getCases() {
81         return cases;
82     }
83
84     public void setCases(HashMap cases) throws XQueryException {
85         // cannot be null
86
if (cases == null)
87             throw new XQueryException("Cases of TypeSwitchExpression cannot be null.");
88         this.cases = cases;
89         Set entries = cases.entrySet();
90         Iterator it = entries.iterator();
91         while (it.hasNext()) {
92             Map.Entry entry = (Map.Entry) it.next();
93             QName qname = (QName) entry.getKey();
94             qname.setParentModule(parentModule);
95             qname.setParentExpression(this);
96             XQueryExpression expr = (XQueryExpression) entry.getValue();
97             expr.setParentModule(parentModule);
98             expr.setParentExpression(this);
99         }
100     }
101
102     public Variable getDefaultVariable() {
103         return defaultVariable;
104     }
105
106     public void setDefaultVariable(Variable defaultVariable) throws XQueryException {
107         this.defaultVariable = defaultVariable;
108         if (defaultVariable != null) {
109             this.defaultVariable.setParentModule(parentModule);
110             this.defaultVariable.setParentExpression(this);
111         }
112     }
113
114     // #############################################################################
115
// CLONE STUFF
116
// #############################################################################
117
public void addParentExpression(XQueryExpression parentExpression) {
118         addParentExpression(parentExpression);
119         if (defaultVariable != null)
120             defaultVariable.addParentExpression(parentExpression);
121         Set entries = cases.entrySet();
122         Iterator it = entries.iterator();
123         while (it.hasNext()) {
124             Map.Entry entry = (Map.Entry) it.next();
125             ((QName) entry.getKey()).addParentExpression(parentExpression);
126             ((XQueryExpression) entry.getValue()).addParentExpression(parentExpression);
127         }
128     }
129
130 }
131
Popular Tags