KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > typing > QTypeUnion


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  * Copyright (C) 2003 XQuark Group.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
19  * You can also get it at http://www.gnu.org/licenses/lgpl.html
20  *
21  * For more information on this software, see http://www.xquark.org.
22  */

23
24 package org.xquark.xquery.typing;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.xquark.xquery.parser.XQueryException;
31
32 public class QTypeUnion extends QTypePrime implements QTypeVisitable {
33     private static final String JavaDoc RCSRevision = "$Revision: 1.3 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35
36     List JavaDoc list = null;
37
38     public QTypeUnion(List JavaDoc list) {
39         super(list,UNION);
40         setList(list);
41         subclass = UNION;
42         //primeList = list;
43
occurence = OCC_1_1;
44     }
45     public QTypeUnion(List JavaDoc list, byte occurence) {
46         super(list,UNION);
47         setList(list);
48         subclass = UNION;
49         //primeList = list;
50
this.occurence = occurence;
51     }
52
53     // #############################################################################
54
// VISITOR STUFF
55
// #############################################################################
56

57     public void accept(QTypeVisitor visitor) throws XQueryException {
58         visitor.visit(this);
59     }
60
61     // get/set
62
public List JavaDoc getList() {
63         return list;
64     }
65
66     private void setList(List JavaDoc list) {
67         // if (list == null || list.isEmpty()) throw new TypeException("list of QTypeUnion cannot be null or empty");
68
this.list = new ArrayList JavaDoc();
69         Iterator JavaDoc it = list.iterator();
70         while (it.hasNext()) {
71             QType qtype = (QType) it.next();
72             if (qtype instanceof QTypeUnion)
73                 this.list.addAll(((QTypeUnion) qtype).getList());
74             else
75                 this.list.add(qtype);
76         }
77     }
78
79     // clone
80
public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
81         QTypeUnion newObj = new QTypeUnion(list, occurence);
82         return newObj;
83     }
84     // print
85
public String JavaDoc toSimpleString() {
86         return "QTypeUnion(" + list + ")";
87     }
88
89     public String JavaDoc toString() {
90         return "QTypeUnion(" + list + ")";
91     }
92 }
93
Popular Tags