KickJava   Java API By Example, From Geeks To Geeks.

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


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 group <code>xs:complexTypeModel</code>,
25  * as specified by the following:
26  * <pre>
27  * &lt;xs:group name="complexTypeModel"&gt;
28  * &lt;xs:choice&gt;
29  * &lt;xs:element ref="xs:simpleContent"/&gt;
30  * &lt;xs:element ref="xs:complexContent"/&gt;
31  * &lt;xs:sequence&gt;
32  * &lt;xs:annotation&gt;
33  * &lt;xs:documentation&gt;
34  * This branch is short for &amp;lt;complexContent&amp;gt;
35  * &amp;lt;restriction base="xs:anyType"&amp;gt;
36  * ...
37  * &amp;lt;/restriction&amp;gt;
38  * &amp;lt;/complexContent&amp;gt;
39  * &lt;/xs:documentation&gt;
40  * &lt;/xs:annotation&gt;
41  * &lt;xs:group ref="xs:typeDefParticle" minOccurs="0"/&gt;
42  * &lt;xs:group ref="xs:attrDecls"/&gt;
43  * &lt;/xs:sequence&gt;
44  * &lt;/xs:choice&gt;
45  * &lt;/xs:group&gt;
46  * </pre></p>
47  *
48  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
49  */

50 public class XsGComplexTypeModelImpl implements XsGComplexTypeModel {
51   private final XsObject owner;
52   private XsESimpleContent simpleContent;
53   private XsEComplexContent complexContent;
54   private boolean otherContent;
55   private final XsGTypeDefParticle typeDefParticle;
56   private final XsGAttrDecls attrDecls;
57
58   protected XsGComplexTypeModelImpl(XsObject pOwner) {
59     owner = pOwner;
60     XsObjectFactory factory = owner.getObjectFactory();
61     typeDefParticle = factory.newXsGTypeDefParticle(owner);
62     attrDecls = factory.newXsGAttrDecls(owner);
63   }
64
65   public XsESimpleContent createSimpleContent() {
66     if (simpleContent != null) {
67       throw new IllegalStateException JavaDoc("Multiple 'simpleContent' child elements are forbidden.");
68     }
69     if (complexContent != null) {
70       throw new IllegalStateException JavaDoc("The 'simpleContent' and 'complexContent' child elements are mutually exclusive.");
71     }
72     if (otherContent) {
73       throw new IllegalStateException JavaDoc("The 'simpleContent' child element and the child elements 'all', 'choice', 'sequence', 'group', 'attribute', and 'attributeGroup' are mutually exclusive.");
74     }
75     return simpleContent = owner.getObjectFactory().newXsESimpleContent(owner);
76   }
77
78   public XsESimpleContent getSimpleContent() {
79     return simpleContent;
80   }
81
82   public XsEComplexContent createComplexContent() {
83     if (complexContent != null) {
84       throw new IllegalStateException JavaDoc("Multiple 'complexContent' child elements are forbidden.");
85     }
86     if (simpleContent != null) {
87       throw new IllegalStateException JavaDoc("The 'complexContent' and 'simpleContent' child elements are mutually exclusive.");
88     }
89     if (otherContent) {
90       throw new IllegalStateException JavaDoc("The 'complexContent' child element and the child elements 'all', 'choice', 'sequence', 'group', 'attribute', and 'attributeGroup' are mutually exclusive.");
91     }
92     return complexContent = owner.getObjectFactory().newXsEComplexContent(owner);
93   }
94
95   public XsEComplexContent getComplexContent() {
96     return complexContent;
97   }
98
99   protected void validateOtherContent() {
100     if (simpleContent != null) {
101       throw new IllegalStateException JavaDoc("The child elements 'all', 'choice', 'sequence', 'group', 'attribute', 'attributeGroup', and the child element 'simpleContent' are mutually exclusive.");
102     }
103     if (complexContent != null) {
104       throw new IllegalStateException JavaDoc("The child elements 'all', 'choice', 'sequence', 'group', 'attribute', 'attributeGroup', and the child element 'complexContent' are mutually exclusive.");
105     }
106   }
107
108   public XsTAttribute createAttribute() {
109     validateOtherContent();
110     return attrDecls.createAttribute();
111   }
112
113   public XsTAttribute[] getAttributes() {
114     return attrDecls.getAttributes();
115   }
116
117   public XsTAttributeGroupRef createAttributeGroup() {
118     validateOtherContent();
119     return attrDecls.createAttributeGroup();
120   }
121
122   public XsTAttributeGroupRef[] getAttributeGroups() {
123     return attrDecls.getAttributeGroups();
124   }
125
126   public XsTWildcard createAnyAttribute() {
127     validateOtherContent();
128     return attrDecls.createAnyAttribute();
129   }
130
131   public XsTWildcard getAnyAttribute() {
132     return attrDecls.getAnyAttribute();
133   }
134
135   public Object JavaDoc[] getAllAttributes() {
136     return attrDecls.getAllAttributes();
137   }
138
139   public void validate() throws SAXException {
140     if (!otherContent && (simpleContent == null && complexContent == null)) {
141       throw new LocSAXException("You must specify either of the 'simpleContent', 'complexContent', 'all', 'choice', 'sequence', or 'group' child elements.",
142                                  owner.getLocator());
143     }
144   }
145
146   public XsTGroupRef createGroup() {
147     return typeDefParticle.createGroup();
148   }
149
150   public XsTAll createAll() {
151     return typeDefParticle.createAll();
152   }
153
154   public XsESequence createSequence() {
155     return typeDefParticle.createSequence();
156   }
157
158   public XsEChoice createChoice() {
159     return typeDefParticle.createChoice();
160   }
161
162   public XsTTypeDefParticle getTypeDefParticle() {
163     return typeDefParticle.getTypeDefParticle();
164   }
165 }
166
Popular Tags