KickJava   Java API By Example, From Geeks To Geeks.

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


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.xml.*;
20
21
22 /** <p>Base implementation of a complex type, to be shared
23  * by {@link org.apache.ws.jaxme.xs.xml.XsTLocalComplexType} and
24  * {@link org.apache.ws.jaxme.xs.xml.XsTComplexType}.
25  * Follows this specification:
26  * <pre>
27  * &lt;xs:complexType name="complexType" abstract="true"&gt;
28  * &lt;xs:complexContent&gt;
29  * &lt;xs:extension base="xs:annotated"&gt;
30  * &lt;xs:group ref="xs:complexTypeModel"/&gt;
31  * &lt;xs:attribute name="name" type="xs:NCName"&gt;
32  * &lt;xs:annotation&gt;
33  * &lt;xs:documentation&gt;
34  * Will be restricted to required or forbidden
35  * &lt;/xs:documentation&gt;
36  * &lt;/xs:annotation&gt;
37  * &lt;/xs:attribute&gt;
38  * &lt;xs:attribute name="mixed" type="xs:boolean" use="optional" default="false"&gt;
39  * &lt;xs:annotation&gt;
40  * &lt;xs:documentation&gt;
41  * Not allowed if simpleContent child is chosen.
42  * May be overriden by setting on complexContent child.
43  * &lt;/xs:documentation&gt;
44  * &lt;/xs:annotation&gt;
45  * &lt;/xs:attribute&gt;
46  * &lt;xs:attribute name="abstract" type="xs:boolean" use="optional" default="false"/&gt;
47  * &lt;xs:attribute name="final" type="xs:derivationSet"/&gt;
48  * &lt;xs:attribute name="block" type="xs:derivationSet"/&gt;
49  * &lt;/xs:extension&gt;
50  * &lt;/xs:complexContent&gt;
51  * &lt;/xs:complexType&gt;
52  *
53  * &lt;xs:group name="complexTypeModel"&gt;
54  * &lt;xs:choice&gt;
55  * &lt;xs:element ref="xs:simpleContent"/&gt;
56  * &lt;xs:element ref="xs:complexContent"/&gt;
57  * &lt;xs:sequence&gt;
58  * &lt;xs:annotation&gt;
59  * &lt;xs:documentation&gt;
60  * This branch is short for &amp;lt;complexContent&amp;gt;
61  * &amp;lt;restriction base="xs:anyType"&amp;gt;
62  * ...
63  * &amp;lt;/restriction&amp;gt;
64  * &amp;lt;/complexContent&amp;gt;
65  * &lt;/xs:documentation&gt;
66  * &lt;/xs:annotation&gt;
67  * &lt;xs:group ref="xs:typeDefParticle" minOccurs="0"/&gt;
68  * &lt;xs:group ref="xs:attrDecls"/&gt;
69  * &lt;/xs:sequence&gt;
70  * &lt;/xs:choice&gt;
71  * &lt;/xs:group&gt;
72  *
73  * &lt;xs:group name="typeDefParticle"&gt;
74  * &lt;xs:annotation&gt;
75  * &lt;xs:documentation&gt;
76  * 'complexType' uses this
77  * &lt;/xs:documentation&gt;
78  * &lt;/xs:annotation&gt;
79  * &lt;xs:choice&gt;
80  * &lt;xs:element name="group" type="xs:groupRef"/&gt;
81  * &lt;xs:element ref="xs:all"/&gt;
82  * &lt;xs:element ref="xs:choice"/&gt;
83  * &lt;xs:element ref="xs:sequence"/&gt;
84  * &lt;/xs:choice&gt;
85  * &lt;/xs:group&gt;
86  * </pre></p>
87  *
88  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
89  */

90 public class XsTComplexTypeImpl extends XsTAnnotatedImpl implements XsTComplexType {
91   private XsESimpleContent simpleContent;
92   private XsEComplexContent complexContent;
93   private final XsGTypeDefParticle particle;
94   private final XsGAttrDecls attrDecls;
95   private boolean isParticleInUse, isMixed, isAbstract;
96   private XsDerivationSet finalSet;
97   private XsNCName name;
98
99   protected XsTComplexTypeImpl(XsObject pParent) {
100     super(pParent);
101     particle = getObjectFactory().newXsGTypeDefParticle(this);
102     attrDecls = getObjectFactory().newXsGAttrDecls(this);
103   }
104
105   public XsDerivationSet getFinal() {
106     return finalSet;
107   }
108
109   public void setFinal(XsDerivationSet pFinal) {
110     finalSet = pFinal;
111   }
112
113   public XsESimpleContent createSimpleContent() {
114     if (simpleContent != null) {
115       throw new IllegalStateException JavaDoc("Multiple 'simpleContent' elements are forbidden.");
116     }
117     if (complexContent != null || isParticleInUse) {
118       throw new IllegalStateException JavaDoc("The child elements 'simpleContent', 'complexContent', 'group', 'all', 'sequence', or 'choice' are mutually exclusive.");
119     }
120     return simpleContent = getObjectFactory().newXsESimpleContent(this);
121   }
122
123   public XsESimpleContent getSimpleContent() {
124     return simpleContent;
125   }
126
127   public XsEComplexContent createComplexContent() {
128     if (complexContent != null) {
129       throw new IllegalStateException JavaDoc("Multiple 'complexContent' elements are forbidden.");
130     }
131     if (simpleContent != null || isParticleInUse) {
132       throw new IllegalStateException JavaDoc("The child elements 'simpleContent', 'complexContent', 'group', 'all', 'sequence', or 'choice' are mutually exclusive.");
133     }
134     return complexContent = getObjectFactory().newXsEComplexContent(this);
135   }
136
137   public XsEComplexContent getComplexContent() {
138     return complexContent;
139   }
140
141   public XsTGroupRef createGroup() {
142     if (simpleContent != null || complexContent != null || isParticleInUse) {
143       throw new IllegalStateException JavaDoc("The child elements 'simpleContent', 'complexContent', 'group', 'all', 'sequence', or 'choice' are mutually exclusive.");
144     }
145     isParticleInUse = true;
146     return particle.createGroup();
147   }
148
149   public XsTAll createAll() {
150     if (simpleContent != null || complexContent != null || isParticleInUse) {
151       throw new IllegalStateException JavaDoc("The child elements 'simpleContent', 'complexContent', 'group', 'all', 'sequence', or 'choice' are mutually exclusive.");
152     }
153     isParticleInUse = true;
154     return particle.createAll();
155   }
156
157   public XsEChoice createChoice() {
158     if (simpleContent != null || complexContent != null || isParticleInUse) {
159       throw new IllegalStateException JavaDoc("The child elements 'simpleContent', 'complexContent', 'group', 'all', 'sequence', or 'choice' are mutually exclusive.");
160     }
161     isParticleInUse = true;
162     return particle.createChoice();
163   }
164
165   public XsESequence createSequence() {
166     if (simpleContent != null || complexContent != null || isParticleInUse) {
167       throw new IllegalStateException JavaDoc("The child elements 'simpleContent', 'complexContent', 'group', 'all', 'sequence', or 'choice' are mutually exclusive.");
168     }
169     isParticleInUse = true;
170     return particle.createSequence();
171   }
172
173   public XsTTypeDefParticle getTypeDefParticle() {
174     return particle.getTypeDefParticle();
175   }
176
177   public XsTAttribute createAttribute() {
178     return attrDecls.createAttribute();
179   }
180
181   public XsTAttribute[] getAttributes() {
182     return attrDecls.getAttributes();
183   }
184
185   public XsTAttributeGroupRef createAttributeGroup() {
186     return attrDecls.createAttributeGroup();
187   }
188
189   public XsTAttributeGroupRef[] getAttributeGroups() {
190     return attrDecls.getAttributeGroups();
191   }
192
193   public XsTWildcard createAnyAttribute() {
194     return attrDecls.createAnyAttribute();
195   }
196
197   public XsTWildcard getAnyAttribute() {
198     return attrDecls.getAnyAttribute();
199   }
200
201   public Object JavaDoc[] getAllAttributes() {
202     return attrDecls.getAllAttributes();
203   }
204
205   public void setName(XsNCName pName) {
206     name = pName;
207   }
208
209   public XsNCName getName() {
210     return name;
211   }
212
213   public boolean isAbstract() {
214     return isAbstract;
215   }
216
217   public void setAbstract(boolean pAbstract) {
218     isAbstract = pAbstract;
219   }
220
221   public boolean isMixed() {
222     return isMixed;
223   }
224
225   public void setMixed(boolean pMixed) {
226     isMixed = pMixed;
227   }
228 }
229
Popular Tags