KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import org.apache.ws.jaxme.xs.xml.*;
23
24
25 /** <p>Interface of <code>xs:simpleRestrictionModel</code>, following
26  * this specification:
27  * <pre>
28  * &lt;xs:group name="simpleRestrictionModel"&gt;
29  * &lt;xs:sequence&gt;
30  * &lt;xs:element name="simpleType" type="xs:localSimpleType" minOccurs="0"/&gt;
31  * &lt;xs:group ref="xs:facets" minOccurs="0" maxOccurs="unbounded"/&gt;
32  * &lt;/xs:sequence&gt;
33  * &lt;/xs:group&gt;
34  *
35  * &lt;xs:group name="facets"&gt;
36  * &lt;xs:annotation&gt;
37  * &lt;xs:documentation&gt;
38  * We should use a substitution group for facets, but
39  * that's ruled out because it would allow users to
40  * add their own, which we're not ready for yet.
41  * &lt;/xs:documentation&gt;
42  * &lt;/xs:annotation&gt;
43  * &lt;xs:choice&gt;
44  * &lt;xs:element ref="xs:minExclusive"/&gt;
45  * &lt;xs:element ref="xs:minInclusive"/&gt;
46  * &lt;xs:element ref="xs:maxExclusive"/&gt;
47  * &lt;xs:element ref="xs:maxInclusive"/&gt;
48  * &lt;xs:element ref="xs:totalDigits"/&gt;
49  * &lt;xs:element ref="xs:fractionDigits"/&gt;
50  * &lt;xs:element ref="xs:length"/&gt;
51  * &lt;xs:element ref="xs:minLength"/&gt;
52  * &lt;xs:element ref="xs:maxLength"/&gt;
53  * &lt;xs:element ref="xs:enumeration"/&gt;
54  * &lt;xs:element ref="xs:whiteSpace"/&gt;
55  * &lt;xs:element ref="xs:pattern"/&gt;
56  * &lt;/xs:choice&gt;
57  * &lt;/xs:group&gt;
58  * </pre></p>
59  *
60  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
61  */

62 public class XsGSimpleRestrictionModelImpl implements XsGSimpleRestrictionModel {
63   private final XsObject owner;
64   private XsTLocalSimpleType simpleType;
65   private List JavaDoc facets;
66
67   protected XsGSimpleRestrictionModelImpl(XsObject pOwner) {
68     owner = pOwner;
69   }
70
71   public XsTLocalSimpleType createSimpleType() {
72     if (simpleType != null) {
73       throw new IllegalStateException JavaDoc("Multiple 'simpleType' childs are forbidden.");
74     }
75     if (facets != null && facets.size() > 0) {
76       throw new IllegalStateException JavaDoc("The 'simpleType' child element must precede the '" +
77                                        ((XsTFacetBase) facets.get(0)).getFacetName() + "' child element.");
78     }
79     return simpleType = owner.getObjectFactory().newXsTLocalSimpleType(owner);
80   }
81
82   public XsTLocalSimpleType getSimpleType() {
83     return simpleType;
84   }
85
86   protected XsTFacetBase getFacetByName(String JavaDoc pName) {
87     if (facets != null) {
88       for (int i = 0; i < facets.size(); i++) {
89         XsTFacetBase facet = (XsTFacetBase) facets.get(i);
90         if (pName.equals(facet.getFacetName())) {
91           return facet;
92         }
93       }
94     }
95     return null;
96   }
97
98   protected void addFacet(XsTFacetBase pFacet) {
99     if (facets == null) {
100       facets = new ArrayList JavaDoc();
101     }
102     facets.add(pFacet);
103   }
104
105   protected void addUniqueFacet(XsTFacetBase pFacet) {
106     if (getFacetByName(pFacet.getFacetName()) != null) {
107       throw new IllegalStateException JavaDoc("Multiple '" + pFacet.getFacetName() + "' childs are forbidden.");
108     }
109     addFacet(pFacet);
110   }
111
112   public XsEMinExclusive createMinExclusive() {
113     XsEMinExclusive minExclusive = owner.getObjectFactory().newXsEMinExclusive(owner);
114     addUniqueFacet(minExclusive);
115     return minExclusive;
116   }
117
118   public XsEMinExclusive getMinExclusive() {
119     return (XsEMinExclusive) getFacetByName("minExclusive");
120   }
121
122   public XsEMinInclusive createMinInclusive() {
123     XsEMinInclusive minInclusive = owner.getObjectFactory().newXsEMinInclusive(owner);
124     addUniqueFacet(minInclusive);
125     return minInclusive;
126   }
127
128   public XsEMinInclusive getMinInclusive() {
129     return (XsEMinInclusive) getFacetByName("minInclusive");
130   }
131
132   public XsEMaxExclusive createMaxExclusive() {
133     XsEMaxExclusive maxExclusive = owner.getObjectFactory().newXsEMaxExclusive(owner);
134     addUniqueFacet(maxExclusive);
135     return maxExclusive;
136   }
137
138   public XsEMaxExclusive getMaxExclusive() {
139     return (XsEMaxExclusive) getFacetByName("maxExclusive");
140   }
141
142   public XsEMaxInclusive createMaxInclusive() {
143     XsEMaxInclusive maxInclusive = owner.getObjectFactory().newXsEMaxInclusive(owner);
144     addUniqueFacet(maxInclusive);
145     return maxInclusive;
146   }
147
148   public XsEMaxInclusive getMaxInclusive() {
149     return (XsEMaxInclusive) getFacetByName("maxInclusive");
150   }
151
152   public XsETotalDigits createTotalDigits() {
153     XsETotalDigits totalDigits = owner.getObjectFactory().newXsETotalDigits(owner);
154     addUniqueFacet(totalDigits);
155     return totalDigits;
156   }
157
158   public XsETotalDigits getTotalDigits() {
159     return (XsETotalDigits) getFacetByName("totalDigits");
160   }
161
162   public XsEFractionDigits createFractionDigits() {
163     XsEFractionDigits fractionDigits = owner.getObjectFactory().newXsEFractionDigits(owner);
164     addUniqueFacet(fractionDigits);
165     return fractionDigits;
166   }
167
168   public XsEFractionDigits getFractionDigits() {
169     return (XsEFractionDigits) getFacetByName("fractionDigits");
170   }
171
172   public XsELength createLength() {
173     XsELength length = owner.getObjectFactory().newXsELength(owner);
174     addUniqueFacet(length);
175     return length;
176   }
177
178   public XsELength getLength() {
179     return (XsELength) getFacetByName("length");
180   }
181
182   public XsEMinLength createMinLength() {
183     XsEMinLength minLength = owner.getObjectFactory().newXsEMinLength(owner);
184     addUniqueFacet(minLength);
185     return minLength;
186   }
187
188   public XsEMinLength getMinLength() {
189     return (XsEMinLength) getFacetByName("minLength");
190   }
191
192   public XsEMaxLength createMaxLength() {
193     XsEMaxLength maxLength = owner.getObjectFactory().newXsEMaxLength(owner);
194     addUniqueFacet(maxLength);
195     return maxLength;
196   }
197
198   public XsEMaxLength getMaxLength() {
199     return (XsEMaxLength) getFacetByName("maxLength");
200   }
201
202   public XsEWhiteSpace createWhiteSpace() {
203     XsEWhiteSpace whiteSpace = owner.getObjectFactory().newXsEWhiteSpace(owner);
204     addUniqueFacet(whiteSpace);
205     return whiteSpace;
206   }
207
208   public XsEWhiteSpace getWhiteSpace() {
209     return (XsEWhiteSpace) getFacetByName("whiteSpace");
210   }
211
212   public XsEPattern createPattern() {
213     XsEPattern pattern = owner.getObjectFactory().newXsEPattern(owner);
214     addFacet(pattern);
215     return pattern;
216   }
217
218   public XsEPattern[] getPatterns() {
219     if (facets == null) {
220       return new XsEPattern[0];
221     }
222     List JavaDoc result = new ArrayList JavaDoc();
223     for (int i = 0; i < facets.size(); i++) {
224       XsTFacetBase facet = (XsTFacetBase) facets.get(i);
225       if ("pattern".equals(facet.getFacetName())) {
226         result.add(facet);
227       }
228     }
229     return (XsEPattern[]) result.toArray(new XsEPattern[result.size()]);
230   }
231
232   public XsEEnumeration createEnumeration() {
233     XsEEnumeration enumeration = owner.getObjectFactory().newXsEEnumeration(owner);
234     addFacet(enumeration);
235     return enumeration;
236   }
237
238   public XsEEnumeration[] getEnumerations() {
239     if (facets == null) {
240       return new XsEEnumeration[0];
241     }
242     List JavaDoc result = new ArrayList JavaDoc();
243     for (int i = 0; i < facets.size(); i++) {
244       XsTFacetBase facet = (XsTFacetBase) facets.get(i);
245       if ("enumeration".equals(facet.getFacetName())) {
246         result.add(facet);
247       }
248     }
249     return (XsEEnumeration[]) result.toArray(new XsEEnumeration[result.size()]);
250   }
251
252   public boolean hasFacets() {
253     return facets != null && facets.size() > 0;
254   }
255
256   public XsTFacetBase[] getFacets() {
257     if (facets == null) {
258       return new XsEEnumeration[0];
259     }
260     return (XsTFacetBase[]) facets.toArray(new XsTFacetBase[facets.size()]);
261   }
262 }
263
Popular Tags