KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
20 import org.apache.ws.jaxme.xs.xml.*;
21 import org.xml.sax.SAXException JavaDoc;
22
23
24 /** <p>Implementation of <code>xs:list</code>, following
25  * the specification below:
26  * <pre>
27  * &lt;xs:element name="list" id="list"&gt;
28  * &lt;xs:complexType&gt;
29  * &lt;xs:annotation&gt;
30  * &lt;xs:documentation
31  * source="http://www.w3.org/TR/xmlschema-2/#element-list"&gt;
32  * itemType attribute and simpleType child are mutually
33  * exclusive, but one or other is required
34  * &lt;/xs:documentation&gt;
35  * &lt;/xs:annotation&gt;
36  * &lt;xs:complexContent&gt;
37  * &lt;xs:extension base="xs:annotated"&gt;
38  * &lt;xs:sequence&gt;
39  * &lt;xs:element name="simpleType" type="xs:localSimpleType"
40  * minOccurs="0"/&gt;
41  * &lt;/xs:sequence&gt;
42  * &lt;xs:attribute name="itemType" type="xs:QName" use="optional"/&gt;
43  * &lt;/xs:extension&gt;
44  * &lt;/xs:complexContent&gt;
45  * &lt;/xs:complexType&gt;
46  * &lt;/xs:element&gt;
47  * </pre></p>
48  *
49  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
50  */

51 public class XsEListImpl extends XsTAnnotatedImpl implements XsEList {
52   private XsQName itemType;
53   private XsTLocalSimpleType simpleType;
54
55   protected XsEListImpl(XsObject pParent) {
56     super(pParent);
57   }
58
59   public void setItemType(XsQName pItemType) {
60     if (simpleType != null) {
61       throw new IllegalStateException JavaDoc("The 'itemType' attribute and the 'simpleType' child element are mutually exclusive.");
62     }
63     itemType = pItemType;
64   }
65
66   public void setItemType(String JavaDoc pItemType) throws SAXException {
67     setItemType(asXsQName(pItemType));
68   }
69
70   public XsQName getItemType() {
71     return itemType;
72   }
73
74   public XsTLocalSimpleType createSimpleType() {
75     if (itemType != null) {
76       throw new IllegalStateException JavaDoc("The 'itemType' attribute and the 'simpleType' child element are mutually exclusive.");
77     }
78     if (simpleType != null) {
79       throw new IllegalStateException JavaDoc("Multiple 'simpleType' child elements are forbidden.");
80     }
81     return simpleType = getObjectFactory().newXsTLocalSimpleType(this);
82   }
83
84   public XsTLocalSimpleType getSimpleType() {
85     return simpleType;
86   }
87
88   public void validate() throws SAXException {
89     super.validate();
90     if (itemType == null && simpleType == null) {
91       throw new LocSAXException("Either the 'itemType' attribute must be set or a 'simpleType' child element must be present.",
92                                  getLocator());
93     }
94   }
95 }
96
Popular Tags