1 17 package org.apache.ws.jaxme.xs.jaxb.impl; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.StringTokenizer ; 22 23 import org.apache.ws.jaxme.xs.jaxb.*; 24 import org.apache.ws.jaxme.xs.jaxb.JAXBSchemaBindings; 25 import org.apache.ws.jaxme.xs.jaxb.JAXBXsObjectFactory; 26 import org.apache.ws.jaxme.xs.parser.XSContext; 27 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException; 28 import org.apache.ws.jaxme.xs.xml.XsEAnnotation; 29 import org.apache.ws.jaxme.xs.xml.XsEAppinfo; 30 import org.apache.ws.jaxme.xs.xml.impl.XsESchemaImpl; 31 import org.xml.sax.SAXException ; 32 33 34 37 public class JAXBXsSchemaImpl extends XsESchemaImpl implements JAXBXsSchema { 38 private JAXBSchemaBindings schemaBindings; 39 private String jaxbVersion; 40 private String [] jaxbExtensionBindingPrefixes; 41 42 public void setJaxbVersion(String pVersion) { 43 jaxbVersion = pVersion; 44 } 45 46 public void setJaxbExtensionBindingPrefixes(String pExtensionBindingPrefixes) { 47 List result = new ArrayList (); 48 for (StringTokenizer st = new StringTokenizer (pExtensionBindingPrefixes); st.hasMoreTokens(); ) { 49 result.add(st.nextToken()); 50 } 51 jaxbExtensionBindingPrefixes = (String []) result.toArray(new String [result.size()]); 52 } 53 54 public String [] getJaxbExtensionBindingPrefixes() { 55 return jaxbExtensionBindingPrefixes == null ? new String [0] : jaxbExtensionBindingPrefixes; 56 } 57 58 public String getJaxbVersion() { 59 return jaxbVersion; 60 } 61 62 64 public JAXBXsSchemaImpl(XSContext pContext) { 65 super(pContext); 66 } 67 68 public void validate() throws SAXException { 69 if (isValidated()) { 70 return; 71 } 72 super.validate(); 73 Object [] childs = getChilds(); 74 for (int i = 0; i < childs.length; i++) { 75 if (!(childs[i] instanceof XsEAnnotation)) { 76 continue; 77 } 78 XsEAnnotation annotation = (XsEAnnotation) childs[i]; 79 XsEAppinfo[] appinfos = annotation.getAppinfos(); 80 for (int j = 0; j < appinfos.length; j++) { 81 Object [] appinfoChilds = appinfos[j].getChilds(); 82 for (int k = 0; k < appinfoChilds.length; k++) { 83 if (!(appinfoChilds[k] instanceof JAXBSchemaBindings)) { 84 continue; 85 } 86 if (schemaBindings == null) { 87 schemaBindings = (JAXBSchemaBindings) appinfoChilds[k]; 88 } else { 89 throw new LocSAXException("A schema must have at most a single instance of 'schemaBindings'", 90 appinfos[j].getLocator()); 91 } 92 } 93 } 94 } 95 96 if (schemaBindings == null) { 97 schemaBindings = ((JAXBXsObjectFactory) getObjectFactory()).newJAXBSchemaBindings(this); 98 } 99 } 100 101 public JAXBSchemaBindings getJAXBSchemaBindings() { 102 return schemaBindings; 103 } 104 105 public boolean setAttribute(String pQName, String pNamespaceURI, String pLocalName, 106 String pValue) throws SAXException { 107 if (JAXBParser.JAXB_SCHEMA_URI.equals(pNamespaceURI)) { 108 if ("version".equals(pLocalName)) { 109 setJaxbVersion(pValue); 110 return true; 111 } else if ("extensionBindingPrefixes".equals(pLocalName)) { 112 setJaxbExtensionBindingPrefixes(pValue); 113 return true; 114 } else { 115 throw new LocSAXException("Invalid attribute: " + pQName, getLocator()); 116 } 117 } else { 118 return super.setAttribute(pQName, pNamespaceURI, pLocalName, pValue); 119 } 120 } 121 } 122 | Popular Tags |