1 17 package org.apache.ws.jaxme.generator.sg.impl; 18 19 import java.util.ArrayList ; 20 import java.util.Arrays ; 21 import java.util.List ; 22 23 import org.apache.ws.jaxme.generator.Generator; 24 import org.apache.ws.jaxme.generator.sg.SGFactory; 25 import org.apache.ws.jaxme.generator.sg.SGFactoryChain; 26 import org.apache.ws.jaxme.xs.jaxb.JAXBGlobalBindings; 27 import org.apache.ws.jaxme.xs.jaxb.impl.JAXBAppinfoImpl; 28 import org.apache.ws.jaxme.xs.jaxb.impl.JAXBGlobalBindingsImpl; 29 import org.apache.ws.jaxme.xs.jaxb.impl.JAXBXsObjectFactoryImpl; 30 import org.apache.ws.jaxme.xs.parser.XsObjectCreator; 31 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException; 32 import org.apache.ws.jaxme.xs.xml.XsEAppinfo; 33 import org.apache.ws.jaxme.xs.xml.XsObject; 34 import org.apache.ws.jaxme.xs.xml.XsObjectFactory; 35 import org.apache.ws.jaxme.xs.xml.XsQName; 36 import org.xml.sax.Locator ; 37 import org.xml.sax.SAXException ; 38 39 40 43 public class JaxMeSchemaReader extends JAXBSchemaReader { 44 public static final String JAXME_SCHEMA_URI = "http://ws.apache.org/jaxme/namespaces/jaxme2"; 45 public static final String XJC_SCHEMA_URI = "http://java.sun.com/xml/ns/jaxb/xjc"; 46 private XjcSerializable xjcSerializable; 47 private List xsObjectCreators = new ArrayList (); 48 49 public JaxMeSchemaReader() { 50 setSupportingExtensions(true); 51 } 52 53 protected void reset() { 54 super.reset(); 55 xjcSerializable = null; 56 } 57 58 private XsObjectCreator[] append(XsObjectCreator[] pBase) { 59 XsObjectCreator[] baseResult = pBase; 60 List myXsObjectCreators = getXsObjectCreators(); 61 List result; 62 if (baseResult == null || baseResult.length == 0) { 63 result = myXsObjectCreators; 64 } else { 65 result = new ArrayList (baseResult.length + myXsObjectCreators.size()); 66 result.addAll(Arrays.asList(baseResult)); 67 result.addAll(myXsObjectCreators); 68 } 69 return (XsObjectCreator[]) myXsObjectCreators.toArray(new XsObjectCreator[myXsObjectCreators.size()]); 70 } 71 72 public class JaxMeAppinfoImpl extends JAXBAppinfoImpl { 73 JaxMeAppinfoImpl(XsObject pParent) { 74 super(pParent); 75 } 76 77 protected XsObjectCreator[] getXsObjectCreators() { 78 return append(super.getXsObjectCreators()); 79 } 80 } 81 82 public class JaxMeGlobalBindingsImpl extends JAXBGlobalBindingsImpl { 83 protected JaxMeGlobalBindingsImpl(XsObject pParent) { 84 super(pParent); 85 } 86 87 protected XsObjectCreator[] getXsObjectCreators() { 88 return append(super.getXsObjectCreators()); 89 } 90 91 92 protected XsObject getBeanByParent(XsObject pParent, Locator pLocator, XsQName pQName) 93 throws SAXException { 94 if (XJC_SCHEMA_URI.equals(pQName.getNamespaceURI())) { 95 if ("serializable".equals(pQName.getLocalName())) { 96 if (getXjcSerializable() != null) { 97 throw new LocSAXException("The element xjc:serializable was already specified.", pLocator); 98 } 99 XjcSerializable s = new XjcSerializable(pParent); 100 setXjcSerializable(s); 101 return s; 102 } 103 } 104 return super.getBeanByParent(pParent, pLocator, pQName); 105 } 106 } 107 108 public class JaxMeXsObjectFactory extends JAXBXsObjectFactoryImpl { 109 public XsEAppinfo newXsEAppinfo(XsObject pParent) { 110 return new JaxMeAppinfoImpl(pParent); 111 } 112 public JAXBGlobalBindings newJAXBGlobalBindings(XsObject pParent) { 113 return new JaxMeGlobalBindingsImpl(pParent); 114 } 115 } 116 117 protected List getXsObjectCreators() { 118 return xsObjectCreators; 119 } 120 121 public void addXsObjectCreator(XsObjectCreator pCreator) { 122 if (pCreator == null) { 123 throw new NullPointerException ("The object creator must not be null."); 124 } 125 xsObjectCreators.add(pCreator); 126 } 127 128 public SGFactoryChain newSGFactoryChain(Generator pGenerator) { 129 SGFactoryChain result = super.newSGFactoryChain(pGenerator); 130 result = new SGFactoryChainImpl(result){ 131 public XsObjectFactory newXsObjectFactory(SGFactory pFactory) { 132 return new JaxMeXsObjectFactory(); 133 } 134 }; 135 136 return result; 137 } 138 139 public XjcSerializable getXjcSerializable() { 140 return xjcSerializable; 141 } 142 143 public void setXjcSerializable(XjcSerializable pXjcSerializable) { 144 xjcSerializable = pXjcSerializable; 145 } 146 } 147 | Popular Tags |