1 17 package org.apache.ws.jaxme.xs.xml.impl; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import javax.xml.XMLConstants ; 23 24 import org.apache.ws.jaxme.xs.parser.XSContext; 25 import org.apache.ws.jaxme.xs.xml.*; 26 import org.xml.sax.SAXException ; 27 import org.xml.sax.helpers.NamespaceSupport ; 28 29 30 113 public class XsESchemaImpl extends XsTOpenAttrsImpl implements XsESchema { 114 private final XSContext context; 115 private XsAnyURI targetNamespace; 116 private String targetNamespacePrefix; 117 private XsToken version; 118 private XsDerivationSet finalDefault = new XsDerivationSet(""); 119 private XsBlockSet blockDefault = new XsBlockSet("#all"); 120 private XsFormChoice attributeFormDefault = XsFormChoice.UNQUALIFIED; 121 private XsFormChoice elementFormDefault = XsFormChoice.UNQUALIFIED; 122 private XsID id; 123 private XmlLang language; 124 private List childs = new ArrayList (); 125 boolean schemaTopSeen = false; 126 127 protected XsESchemaImpl(XSContext pContext) { 128 super(null); 129 context = pContext; 130 } 131 132 public XSContext getContext() { return context; } 133 134 public XsEInclude createInclude() { 135 if (schemaTopSeen) { 136 throw new IllegalStateException ("xs:include is not allowed after xs:simpleType, xs:complexType, xs:group, xs:attributeGroup, xs:element. xs:attribute, or xs:notation have been seen."); 137 } 138 XsEInclude xsInclude = getObjectFactory().newXsEInclude(this); 139 childs.add(xsInclude); 140 return xsInclude; 141 } 142 143 public XsEImport createImport() { 144 if (schemaTopSeen) { 145 throw new IllegalStateException ("xs:include is not allowed after xs:simpleType, xs:complexType, xs:group, xs:attributeGroup, xs:element. xs:attribute, or xs:notation have been seen."); 146 } 147 XsEImport xsImport = getObjectFactory().newXsEImport(this); 148 childs.add(xsImport); 149 return xsImport; 150 } 151 152 public XsERedefine createRedefine() { 153 if (schemaTopSeen) { 154 throw new IllegalStateException ("xs:include is not allowed after xs:simpleType, xs:complexType, xs:group, xs:attributeGroup, xs:element. xs:attribute, or xs:notation have been seen."); 155 } 156 XsERedefine xsRedefine = getObjectFactory().newXsERedefine(this); 157 childs.add(xsRedefine); 158 return xsRedefine; 159 } 160 161 public XsEAnnotation createAnnotation() { 162 XsEAnnotation xsAnnotation = getObjectFactory().newXsEAnnotation(this); 163 childs.add(xsAnnotation); 164 return xsAnnotation; 165 } 166 167 public XsETopLevelSimpleType createSimpleType() { 168 schemaTopSeen = true; 169 XsETopLevelSimpleType xsSimpleType = getObjectFactory().newXsETopLevelSimpleType(this); 170 childs.add(xsSimpleType); 171 return xsSimpleType; 172 } 173 174 public XsTComplexType createComplexType() { 175 schemaTopSeen = true; 176 XsTComplexType xsComplexType = getObjectFactory().newXsTComplexType(this); 177 childs.add(xsComplexType); 178 return xsComplexType; 179 } 180 181 public XsTNamedGroup createGroup() { 182 schemaTopSeen = true; 183 XsTNamedGroup xsGroup = getObjectFactory().newXsTNamedGroup(this); 184 childs.add(xsGroup); 185 return xsGroup; 186 } 187 188 public XsTAttributeGroup createAttributeGroup() { 189 schemaTopSeen = true; 190 XsTAttributeGroup xsAttributeGroup = getObjectFactory().newXsTAttributeGroup(this); 191 childs.add(xsAttributeGroup); 192 return xsAttributeGroup; 193 } 194 195 public XsTTopLevelElement createElement() { 196 schemaTopSeen = true; 197 XsTTopLevelElement xsElement = getObjectFactory().newXsTTopLevelElement(this); 198 childs.add(xsElement); 199 return xsElement; 200 } 201 202 public XsTAttribute createAttribute() { 203 schemaTopSeen = true; 204 XsTAttribute xsAttribute = getObjectFactory().newXsTAttribute(this); 205 childs.add(xsAttribute); 206 return xsAttribute; 207 } 208 209 public XsENotation createNotation() { 210 schemaTopSeen = true; 211 XsENotation xsNotation = getObjectFactory().newXsENotation(this); 212 childs.add(xsNotation); 213 return xsNotation; 214 } 215 216 public XsFormChoice getAttributeFormDefault() { return attributeFormDefault; } 217 public void setAttributeFormDefault(XsFormChoice pChoice) { attributeFormDefault = pChoice; } 218 public XsBlockSet getBlockDefault() { return blockDefault; } 219 public void setBlockDefault(XsBlockSet pSet) { blockDefault = pSet; } 220 public XsFormChoice getElementFormDefault() { return elementFormDefault; } 221 public void setElementFormDefault(XsFormChoice pChoice) { elementFormDefault = pChoice; } 222 public XsDerivationSet getFinalDefault() { return finalDefault; } 223 public void setFinalDefault(XsDerivationSet pSet) { finalDefault = pSet; } 224 public XsID getId() { return id; } 225 public void setId(XsID pId) { id = pId; } 226 public XsAnyURI getTargetNamespace() { return targetNamespace; } 227 public String getTargetNamespacePrefix() { return targetNamespacePrefix; } 228 public void setTargetNamespace(XsAnyURI pAnyURI) { 229 targetNamespace = pAnyURI; 230 if (targetNamespace == null) { 231 targetNamespacePrefix = null; 232 } else { 233 NamespaceSupport nss = getNamespaceSupport(); 234 targetNamespacePrefix = nss.getPrefix(targetNamespace.toString()); 235 } 236 } 237 public XsToken getVersion() { return version; } 238 public void setVersion(XsToken pToken) { version = pToken; } 239 public XmlLang getLang() { return language; } 240 public void setLang(XmlLang pLanguage) { language = pLanguage; } 241 242 public boolean setAttribute(String pQName, String pNamespaceURI, 243 String pLocalName, String pValue) throws SAXException { 244 if (XMLConstants.XML_NS_URI.equals(pNamespaceURI) && "lang".equals(pLocalName)) { 245 setLang(new XmlLang(pValue)); 246 return true; 247 } 248 return super.setAttribute(pQName, pNamespaceURI, pLocalName, pValue); 249 } 250 251 public Object [] getChilds() { 252 return childs.toArray(); 253 } 254 255 260 public XsQName newXsQName(String pLocalName, String pPrefix) { 261 return new XsQName(getTargetNamespace(), pLocalName, pPrefix){ 262 public String getNamespaceURI() { 263 XsAnyURI uri = getTargetNamespace(); 264 if (uri != null) { 265 return uri.toString(); 266 } else { 267 return ""; 268 } 269 } 270 public String toString() { 271 XsAnyURI uri = getTargetNamespace(); 272 if (uri == null) { 273 return super.toString(); 274 } else { 275 return "{" + uri + "}" + getLocalName() + " (<= " + super.toString() + ")"; 276 } 277 } 278 }; 279 } 280 } 281 | Popular Tags |