KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > generator > sg > impl > JaxMeSchemaReader


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.generator.sg.impl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Arrays JavaDoc;
21 import java.util.List JavaDoc;
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 JavaDoc;
37 import org.xml.sax.SAXException JavaDoc;
38
39
40 /**
41  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
42  */

43 public class JaxMeSchemaReader extends JAXBSchemaReader {
44     public static final String JavaDoc JAXME_SCHEMA_URI = "http://ws.apache.org/jaxme/namespaces/jaxme2";
45     public static final String JavaDoc XJC_SCHEMA_URI = "http://java.sun.com/xml/ns/jaxb/xjc";
46     private XjcSerializable xjcSerializable;
47     private List JavaDoc xsObjectCreators = new ArrayList JavaDoc();
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 JavaDoc myXsObjectCreators = getXsObjectCreators();
61         List JavaDoc result;
62         if (baseResult == null || baseResult.length == 0) {
63             result = myXsObjectCreators;
64         } else {
65             result = new ArrayList JavaDoc(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 JavaDoc 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 JavaDoc getXsObjectCreators() {
118         return xsObjectCreators;
119     }
120
121     public void addXsObjectCreator(XsObjectCreator pCreator) {
122         if (pCreator == null) {
123             throw new NullPointerException JavaDoc("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