KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > xml > impl > XsEUnionImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.xs.xml.impl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22
23 import org.apache.ws.jaxme.xs.xml.*;
24 import org.xml.sax.SAXException JavaDoc;
25
26
27 /** <p>Implementation of <code>xs:union</code>, following the
28  * specification below:
29  * <pre>
30  * &lt;xs:element name="union" id="union"&gt;
31  * &lt;xs:complexType&gt;
32  * &lt;xs:annotation&gt;
33  * &lt;xs:documentation
34  * source="http://www.w3.org/TR/xmlschema-2/#element-union"&gt;
35  * memberTypes attribute must be non-empty or there must be
36  * at least one simpleType child
37  * &lt;/xs:documentation&gt;
38  * &lt;/xs:annotation&gt;
39  * &lt;xs:complexContent&gt;
40  * &lt;xs:extension base="xs:annotated"&gt;
41  * &lt;xs:sequence&gt;
42  * &lt;xs:element name="simpleType" type="xs:localSimpleType"
43  * minOccurs="0" maxOccurs="unbounded"/&gt;
44  * &lt;/xs:sequence&gt;
45  * &lt;xs:attribute name="memberTypes" use="optional"&gt;
46  * &lt;xs:simpleType&gt;
47  * &lt;xs:list itemType="xs:QName"/&gt;
48  * &lt;/xs:simpleType&gt;
49  * &lt;/xs:attribute&gt;
50  * &lt;/xs:extension&gt;
51  * &lt;/xs:complexContent&gt;
52  * &lt;/xs:complexType&gt;
53  * &lt;/xs:element&gt;
54  * </pre></p>
55  *
56  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
57  */

58 public class XsEUnionImpl extends XsTAnnotatedImpl implements XsEUnion {
59   public List JavaDoc simpleTypes;
60   public List JavaDoc memberTypes;
61
62   protected XsEUnionImpl(XsObject pParent) {
63     super(pParent);
64   }
65
66   public XsTLocalSimpleType createSimpleType() {
67     XsTLocalSimpleType simpleType = getObjectFactory().newXsTLocalSimpleType(this);
68     if (simpleTypes == null) {
69       simpleTypes = new ArrayList JavaDoc();
70     }
71     simpleTypes.add(simpleType);
72     return simpleType;
73   }
74
75   public XsTLocalSimpleType[] getSimpleTypes() {
76     if (simpleTypes == null) {
77       return new XsTLocalSimpleType[0];
78     }
79     return (XsTLocalSimpleType[]) simpleTypes.toArray(new XsTLocalSimpleType[simpleTypes.size()]);
80   }
81
82   public void setMemberTypes(XsQName[] pTypes) {
83     if (pTypes == null) {
84       memberTypes = null;
85     } else {
86       memberTypes = new ArrayList JavaDoc();
87       for (int i = 0; i < pTypes.length; i++) {
88         memberTypes.add(pTypes[i]);
89       }
90     }
91   }
92
93   public void setMemberTypes(String JavaDoc pTypes) throws SAXException JavaDoc {
94     if (pTypes == null) {
95       setMemberTypes((XsQName[]) null);
96     } else {
97       List JavaDoc myMemberTypes = new ArrayList JavaDoc();
98       for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(pTypes); st.hasMoreTokens(); ) {
99         String JavaDoc s = st.nextToken();
100         XsQName qName = asXsQName(s);
101         myMemberTypes.add(qName);
102       }
103       setMemberTypes((XsQName[]) myMemberTypes.toArray(new XsQName[myMemberTypes.size()]));
104     }
105   }
106
107   public XsQName[] getMemberTypes() {
108     if (memberTypes == null) {
109       return null;
110     }
111     return (XsQName[]) memberTypes.toArray(new XsQName[memberTypes.size()]);
112   }
113 }
114
Popular Tags