1 17 package org.apache.ws.jaxme.xs.impl; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 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 ; 30 31 34 public class XSUnionTypeImpl extends XSSimpleTypeImpl implements XSUnionType { 35 private static final String [][] ZERO_PATTERNS = new String [0][]; 36 private static final XSEnumeration[] ZERO_ENUMERATIONS = new XSEnumeration[0]; 37 private final List memberTypes = new ArrayList (); 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 ("This is a basic list type and not a restriction of another simple type."); 76 } 77 public XSUnionType getUnionType() { return this; } 78 public String [][] 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 |