1 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 ; 22 23 24 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 ("Multiple 'simpleContent' child elements are forbidden."); 68 } 69 if (complexContent != null) { 70 throw new IllegalStateException ("The 'simpleContent' and 'complexContent' child elements are mutually exclusive."); 71 } 72 if (otherContent) { 73 throw new IllegalStateException ("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 ("Multiple 'complexContent' child elements are forbidden."); 85 } 86 if (simpleContent != null) { 87 throw new IllegalStateException ("The 'complexContent' and 'simpleContent' child elements are mutually exclusive."); 88 } 89 if (otherContent) { 90 throw new IllegalStateException ("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 ("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 ("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 [] 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 |