KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > impl > XSUnionTypeImpl


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.impl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.ws.jaxme.xs.XSEnumeration;
23 import org.apache.ws.jaxme.xs.XSType;
24 import org.apache.ws.jaxme.xs.XSUnionType;
25 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
26 import org.apache.ws.jaxme.xs.xml.XsEUnion;
27 import org.apache.ws.jaxme.xs.xml.XsQName;
28 import org.apache.ws.jaxme.xs.xml.XsTLocalSimpleType;
29 import org.xml.sax.SAXException JavaDoc;
30
31 /**
32  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
33  */

34 public class XSUnionTypeImpl extends XSSimpleTypeImpl implements XSUnionType {
35   private static final String JavaDoc[][] ZERO_PATTERNS = new String JavaDoc[0][];
36   private static final XSEnumeration[] ZERO_ENUMERATIONS = new XSEnumeration[0];
37   private final List JavaDoc memberTypes = new ArrayList JavaDoc();
38
39   public XSUnionTypeImpl(XSType pOwner,
40                           XsEUnion pBaseUnion) throws SAXException {
41     XsQName[] names = pBaseUnion.getMemberTypes();
42     if (names != null) {
43       for (int i = 0; i < names.length; i++) {
44         XsQName name = names[i];
45         XSType type = pOwner.getXSSchema().getType(name);
46         if (type == null) {
47           throw new LocSAXException("Unknown member type: " + name, pBaseUnion.getLocator());
48         }
49         type.validate();
50         if (!type.isSimple()) {
51           throw new LocSAXException("The member type " + name + " is complex.",
52                                        pBaseUnion.getLocator());
53         }
54         memberTypes.add(type);
55       }
56     }
57     XsTLocalSimpleType[] simpleTypes = pBaseUnion.getSimpleTypes();
58     if (simpleTypes != null) {
59       for (int i = 0; i < simpleTypes.length; i++) {
60         XsTLocalSimpleType localSimpleType = simpleTypes[i];
61         XSType type = pOwner.getXSSchema().getXSObjectFactory().newXSType(pOwner, localSimpleType);
62         type.validate();
63         memberTypes.add(type);
64       }
65     }
66     if (memberTypes.size() == 0) {
67       throw new LocSAXException("Neither the 'memberTypes' attribute nor the 'simpleType' child elements did define a member type.",
68                                    pBaseUnion.getLocator());
69     }
70   }
71
72   public boolean isUnion() { return true; }
73   public boolean isRestriction() { return false; }
74   public XSType getRestrictedType() {
75     throw new IllegalStateException JavaDoc("This is a basic list type and not a restriction of another simple type.");
76   }
77   public XSUnionType getUnionType() { return this; }
78   public String JavaDoc[][] getPattern() { return ZERO_PATTERNS; }
79   public XSEnumeration[] getEnumerations() { return ZERO_ENUMERATIONS; }
80   public XSType[] getMemberTypes() {
81     return (XSType[]) memberTypes.toArray(new XSType[memberTypes.size()]);
82   }
83 }
84
Popular Tags