KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.ws.jaxme.generator.sg.SchemaSG;
20 import org.apache.ws.jaxme.js.JavaQName;
21 import org.apache.ws.jaxme.js.JavaQNameImpl;
22 import org.apache.ws.jaxme.xs.XSObject;
23 import org.apache.ws.jaxme.xs.XSType;
24 import org.apache.ws.jaxme.xs.jaxb.JAXBClass;
25 import org.apache.ws.jaxme.xs.jaxb.JAXBClassOwner;
26 import org.apache.ws.jaxme.xs.jaxb.JAXBSchemaBindings;
27 import org.apache.ws.jaxme.xs.xml.XsQName;
28 import org.xml.sax.Locator JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30
31 /**
32  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
33  */

34 public class GlobalContext extends AbstractContext {
35     /** <p>Creates a new, global class context.</p>
36      */

37     public GlobalContext(XsQName pQName, XSObject pJAXBClassOwner,
38                          String JavaDoc pPrefix, String JavaDoc pSuffix, SchemaSG pSchemaSG)
39             throws SAXException JavaDoc {
40         Locator JavaDoc locator;
41         if (pJAXBClassOwner instanceof XSType) {
42             XSType type = (XSType) pJAXBClassOwner;
43             if (type.isBuiltin()) {
44                 locator = null;
45             } else {
46                 locator = type.getLocator();
47             }
48         } else {
49             locator = pJAXBClassOwner.getLocator();
50         }
51
52         if (pQName == null) {
53             throw new NullPointerException JavaDoc("The XsQName argument must not be null.");
54         }
55         setName(pQName);
56         if (pJAXBClassOwner == null) {
57             throw new NullPointerException JavaDoc("The XSObject argument must not be null.");
58         }
59         
60         JAXBClassOwner jaxbClassOwner = null;
61         JAXBSchemaBindings schemaBindings = null;
62         
63         if (pJAXBClassOwner instanceof JAXBClassOwner) {
64             jaxbClassOwner = (JAXBClassOwner) pJAXBClassOwner;
65             schemaBindings = jaxbClassOwner.getJAXBSchemaBindings();
66         }
67         
68         String JavaDoc packageName = getPackageName(pSchemaSG, schemaBindings, locator, pQName);
69         String JavaDoc className = null, implementationName = null;
70         JAXBClass jaxbClass = (jaxbClassOwner == null) ? null : jaxbClassOwner.getJAXBClass();
71         if (jaxbClass != null) {
72             className = jaxbClass.getName();
73             implementationName = jaxbClass.getImplClass();
74         }
75         
76         if (className == null) {
77             String JavaDoc prefix = null, suffix = null;
78             className = getClassNameFromLocalName(locator, pQName.getLocalName(), pSchemaSG);
79             if (prefix == null) { prefix = pPrefix; }
80             if (prefix != null) className = prefix + className;
81             if (suffix == null) { suffix = pSuffix; }
82             if (suffix != null) className += suffix;
83         }
84         if (className.equals("EmailDetailsType")) {
85             throw new IllegalStateException JavaDoc();
86         }
87         
88         JavaQName xmlInterfaceName = JavaQNameImpl.getInstance(packageName, className);
89         setXMLInterfaceName(xmlInterfaceName);
90         
91         if (implementationName == null) {
92             setXMLImplementationName(JavaQNameImpl.getInstance(xmlInterfaceName.getPackageName() + ".impl",
93                     xmlInterfaceName.getClassName() + "Impl"));
94         } else {
95             setXMLImplementationName(JavaQNameImpl.getInstance(implementationName, true));
96         }
97         setXMLHandlerName(JavaQNameImpl.getInstance(xmlInterfaceName.getPackageName() + ".impl",
98                 xmlInterfaceName.getClassName() + "Handler"));
99         setXMLSerializerName(JavaQNameImpl.getInstance(xmlInterfaceName.getPackageName() + ".impl",
100                 xmlInterfaceName.getClassName() + "Driver"));
101         setXMLValidatorName(JavaQNameImpl.getInstance(xmlInterfaceName.getPackageName() + ".impl",
102                 xmlInterfaceName.getClassName() + "Validator"));
103         setPMName(JavaQNameImpl.getInstance(xmlInterfaceName.getPackageName() + ".impl",
104                 xmlInterfaceName.getClassName() + "PM"));
105     }
106     
107     public boolean isGlobal() { return true; }
108 }
109
Popular Tags