KickJava   Java API By Example, From Geeks To Geeks.

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


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 the <code>xs:element</code> type,
25  * as specified by the following:
26  * <pre>
27  * &lt;xs:complexType name="element" abstract="true"&gt;
28  * &lt;xs:annotation&gt;
29  * &lt;xs:documentation&gt;
30  * The element element can be used either
31  * at the top level to define an element-type binding globally,
32  * or within a content model to either reference a globally-defined
33  * element or type or declare an element-type binding locally.
34  * The ref form is not allowed at the top level.
35  * &lt;/xs:documentation&gt;
36  * &lt;/xs:annotation&gt;
37  * &lt;xs:complexContent&gt;
38  * &lt;xs:extension base="xs:annotated"&gt;
39  * &lt;xs:sequence&gt;
40  * &lt;xs:choice minOccurs="0"&gt;
41  * &lt;xs:element name="simpleType" type="xs:localSimpleType"/&gt;
42  * &lt;xs:element name="complexType" type="xs:localComplexType"/&gt;
43  * &lt;/xs:choice&gt;
44  * &lt;xs:group ref="xs:identityConstraint" minOccurs="0" maxOccurs="unbounded"/&gt;
45  * &lt;/xs:sequence&gt;
46  * &lt;xs:attributeGroup ref="xs:defRef"/&gt;
47  * &lt;xs:attribute name="type" type="xs:QName"/&gt;
48  * &lt;xs:attribute name="substitutionGroup" type="xs:QName"/&gt;
49  * &lt;xs:attributeGroup ref="xs:occurs"/&gt;
50  * &lt;xs:attribute name="default" type="xs:string"/&gt;
51  * &lt;xs:attribute name="fixed" type="xs:string"/&gt;
52  * &lt;xs:attribute name="nillable" type="xs:boolean" use="optional" default="false"/&gt;
53  * &lt;xs:attribute name="abstract" type="xs:boolean" use="optional" default="false"/&gt;
54  * &lt;xs:attribute name="final" type="xs:derivationSet"/&gt;
55  * &lt;xs:attribute name="block" type="xs:blockSet"/&gt;
56  * &lt;xs:attribute name="form" type="xs:formChoice"/&gt;
57  * &lt;/xs:extension&gt;
58  * &lt;/xs:complexContent&gt;
59  * &lt;/xs:complexType&gt;
60  * </pre></p>
61  *
62  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
63  */

64 public abstract class XsTElementImpl extends XsTAnnotatedImpl implements XsTElement {
65   private XsTLocalSimpleType simpleType;
66   private XsTLocalComplexType complexType;
67   private XsQName type;
68   private XsQName substitutionGroup;
69   private String JavaDoc defaultValue;
70   private String JavaDoc fixedValue;
71   private boolean isNillable;
72   private boolean isAbstract;
73   private XsDerivationSet finalSet;
74   private XsBlockSet blockSet;
75   private XsFormChoice formChoice;
76   private final XsAGDefRef defRef;
77   private final XsAGOccurs occurs;
78   private XsGIdentityConstraint constraint;
79
80   protected XsTElementImpl(XsObject pParent) {
81     super(pParent);
82     defRef = getObjectFactory().newXsAGDefRef(this);
83     occurs = getObjectFactory().newXsAGOccurs(this);
84     constraint = getObjectFactory().newXsGIdentityConstraint(this);
85   }
86
87   public XsTLocalSimpleType createSimpleType() throws SAXException {
88     if (simpleType != null) {
89       throw new LocSAXException("Multiple 'simpleType' childs are forbidden.", getLocator());
90     }
91     if (complexType != null) {
92       throw new LocSAXException("The 'simpleType' and 'complexType' childs are mutually exclusive.", getLocator());
93     }
94     if (type != null) {
95       throw new LocSAXException("The 'simpleType' child and the 'type' attribute are mutually exclusive.", getLocator());
96     }
97     return simpleType = getObjectFactory().newXsTLocalSimpleType(this);
98   }
99
100   public XsTLocalSimpleType getSimpleType() {
101     return simpleType;
102   }
103
104   public XsTLocalComplexType createComplexType() throws SAXException {
105     if (complexType != null) {
106       throw new LocSAXException("Multiple 'complexType' childs are forbidden.", getLocator());
107     }
108     if (simpleType != null) {
109       throw new LocSAXException("The 'simpleType' and 'complexType' childs are mutually exclusive.", getLocator());
110     }
111     if (type != null) {
112       throw new LocSAXException("The 'complexType' child and the 'type' attribute are mutually exclusive.", getLocator());
113     }
114     return complexType = getObjectFactory().newXsTLocalComplexType(this);
115   }
116
117   public XsTLocalComplexType getComplexType() {
118     return complexType;
119   }
120
121   public void setType(XsQName pType) throws SAXException {
122     if (simpleType != null) {
123       throw new LocSAXException("The 'simpleType' child element and the 'type' attribute are mutually exclusive.", getLocator());
124     }
125     if (complexType != null) {
126       throw new LocSAXException("The 'complexType' child element and the 'type' attribute are mutually exclusive.", getLocator());
127     }
128     type = pType;
129   }
130
131   public void setType(String JavaDoc pType) throws SAXException {
132     setType(asXsQName(pType));
133   }
134
135   public XsQName getType() {
136     return type;
137   }
138
139   public void setSubstitutionGroup(XsQName pSubstitutionGroup) throws SAXException {
140     substitutionGroup = pSubstitutionGroup;
141   }
142
143   public void setSubstitutionGroup(String JavaDoc pSubstitutionGroup) throws SAXException {
144     setSubstitutionGroup(asXsQName(pSubstitutionGroup));
145   }
146
147   public XsQName getSubstitutionGroup() {
148     return substitutionGroup;
149   }
150
151   public void setDefault(String JavaDoc pDefault) {
152     defaultValue = pDefault;
153   }
154
155   public String JavaDoc getDefault() {
156     return defaultValue;
157   }
158
159   public void setFixed(String JavaDoc pFixed) {
160     fixedValue = pFixed;
161   }
162
163   public String JavaDoc getFixed() {
164     return fixedValue;
165   }
166
167   public void setNillable(boolean pNillable) {
168     isNillable = pNillable;
169   }
170
171   public boolean getNillable() {
172     return isNillable;
173   }
174
175   public void setAbstract(boolean pAbstract) {
176     isAbstract = pAbstract;
177   }
178
179   public boolean getAbstract() {
180     return isAbstract;
181   }
182
183   public void setFinal(XsDerivationSet pFinal) {
184     finalSet = pFinal;
185   }
186
187   public XsDerivationSet getFinal() {
188     return finalSet;
189   }
190
191   public void setBlock(XsBlockSet pBlock) {
192     blockSet = pBlock;
193   }
194
195   public XsBlockSet getBlock() {
196     return blockSet;
197   }
198
199   public void setForm(XsFormChoice pForm) {
200     formChoice = pForm;
201   }
202
203   public XsFormChoice getForm() {
204     return formChoice;
205   }
206
207   public void validate() throws SAXException {
208     super.validate();
209     if (type == null && simpleType == null && complexType == null && getRef() == null) {
210       setType(org.apache.ws.jaxme.xs.types.XSAnyType.getInstance().getName());
211     }
212     defRef.validate();
213     occurs.validate();
214   }
215
216   public void setName(XsNCName pName) {
217     defRef.setName(pName);
218   }
219
220   public XsNCName getName() {
221     return defRef.getName();
222   }
223
224   public void setRef(XsQName pRef) {
225     defRef.setRef(pRef);
226   }
227
228   public void setRef(String JavaDoc pRef) throws SAXException {
229     setRef(asXsQName(pRef));
230   }
231
232   public XsQName getRef() {
233     return defRef.getRef();
234   }
235
236   public void setMaxOccurs(String JavaDoc pMaxOccurs) {
237     occurs.setMaxOccurs(pMaxOccurs);
238   }
239
240   public int getMaxOccurs() {
241     return occurs.getMaxOccurs();
242   }
243
244   public void setMinOccurs(int pMinOccurs) {
245     occurs.setMinOccurs(pMinOccurs);
246   }
247
248   public int getMinOccurs() {
249     return occurs.getMinOccurs();
250   }
251
252   public XsEUnique createUnique() {
253     return constraint.createUnique();
254   }
255
256   public XsEKey createKey() {
257     return constraint.createKey();
258   }
259
260   public XsEKeyref createKeyref() {
261     return constraint.createKeyref();
262   }
263
264   public XsTIdentityConstraint[] getIdentityConstraints() {
265     return constraint.getIdentityConstraints();
266   }
267 }
268
Popular Tags