KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > deployment > wsdd > WSDDProvider


1 /*
2  * Copyright 2001-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 package org.apache.axis.deployment.wsdd;
17
18 import org.apache.axis.EngineConfiguration;
19 import org.apache.axis.Handler;
20 import org.apache.axis.components.logger.LogFactory;
21 import org.apache.axis.deployment.wsdd.providers.WSDDBsfProvider;
22 import org.apache.axis.deployment.wsdd.providers.WSDDComProvider;
23 import org.apache.axis.deployment.wsdd.providers.WSDDHandlerProvider;
24 import org.apache.axis.deployment.wsdd.providers.WSDDJavaCORBAProvider;
25 import org.apache.axis.deployment.wsdd.providers.WSDDJavaEJBProvider;
26 import org.apache.axis.deployment.wsdd.providers.WSDDJavaMsgProvider;
27 import org.apache.axis.deployment.wsdd.providers.WSDDJavaRMIProvider;
28 import org.apache.axis.deployment.wsdd.providers.WSDDJavaRPCProvider;
29 import org.apache.axis.utils.JavaUtils;
30 import org.apache.axis.utils.Messages;
31 import org.apache.commons.discovery.ResourceNameIterator;
32 import org.apache.commons.discovery.resource.ClassLoaders;
33 import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
34 import org.apache.commons.logging.Log;
35
36 import javax.xml.namespace.QName JavaDoc;
37 import java.util.Hashtable JavaDoc;
38
39
40 /**
41  * WSDD provider element
42  *
43  * Represents the liason to the application being exposed
44  * as a Web Service.
45  *
46  * Specific provider extension classes must be registered
47  * by namespace URI.
48  *
49  * @author James Snell
50  * @author Vishy Kasar
51  */

52 public abstract class WSDDProvider
53 {
54     protected static Log log =
55         LogFactory.getLog(WSDDProvider.class.getName());
56
57 // ** STATIC PROVIDER REGISTRY ** //
58
private static final String JavaDoc PLUGABLE_PROVIDER_FILENAME =
59        "org.apache.axis.deployment.wsdd.Provider";
60
61     /** XXX */
62     private static Hashtable JavaDoc providers = new Hashtable JavaDoc();
63
64     static {
65         providers.put(WSDDConstants.QNAME_JAVARPC_PROVIDER, new WSDDJavaRPCProvider());
66         providers.put(WSDDConstants.QNAME_JAVAMSG_PROVIDER, new WSDDJavaMsgProvider());
67         providers.put(WSDDConstants.QNAME_HANDLER_PROVIDER, new WSDDHandlerProvider());
68         providers.put(WSDDConstants.QNAME_EJB_PROVIDER, new WSDDJavaEJBProvider());
69         providers.put(WSDDConstants.QNAME_COM_PROVIDER, new WSDDComProvider());
70         providers.put(WSDDConstants.QNAME_BSF_PROVIDER, new WSDDBsfProvider());
71         providers.put(WSDDConstants.QNAME_CORBA_PROVIDER, new WSDDJavaCORBAProvider());
72         providers.put(WSDDConstants.QNAME_RMI_PROVIDER, new WSDDJavaRMIProvider());
73         try {
74             loadPluggableProviders();
75         } catch (Throwable JavaDoc t){
76             String JavaDoc msg=t + JavaUtils.LS + JavaUtils.stackToString(t);
77             log.info(Messages.getMessage("exception01",msg));
78         }
79     }
80
81     /**
82        Look for file META-INF/services/org.apache.axis.deployment.wsdd.Provider
83        in all the JARS, get the classes listed in those files and add them to
84        providers list if they are valid providers.
85
86        Here is how the scheme would work.
87
88        A company providing a new provider will jar up their provider related
89        classes in a JAR file. The following file containing the name of the new
90        provider class is also made part of this JAR file.
91
92        META-INF/services/org.apache.axis.deployment.wsdd.Provider
93
94        By making this JAR part of the webapp, the new provider will be
95        automatically discovered.
96     */

97     private static void loadPluggableProviders() {
98         ClassLoader JavaDoc clzLoader = WSDDProvider.class.getClassLoader();
99         ClassLoaders loaders = new ClassLoaders();
100         loaders.put(clzLoader);
101         DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
102         ResourceNameIterator iter = dsn.findResourceNames(PLUGABLE_PROVIDER_FILENAME);
103         while (iter.hasNext()) {
104             String JavaDoc className = iter.nextResourceName();
105             try {
106                 Object JavaDoc o = Class.forName(className).newInstance();
107                 if (o instanceof WSDDProvider) {
108                     WSDDProvider provider = (WSDDProvider) o;
109                     String JavaDoc providerName = provider.getName();
110                     QName JavaDoc q = new QName JavaDoc(WSDDConstants.URI_WSDD_JAVA, providerName);
111                     providers.put(q, provider);
112                 }
113             } catch (Exception JavaDoc e) {
114                 String JavaDoc msg=e + JavaUtils.LS + JavaUtils.stackToString(e);
115                 log.info(Messages.getMessage("exception01",msg));
116                 continue;
117             }
118         }
119     }
120
121     /**
122      *
123      * @param uri XXX
124      * @param prov XXX
125      */

126     public static void registerProvider(QName JavaDoc uri, WSDDProvider prov)
127     {
128         providers.put(uri, prov);
129     }
130
131     /**
132      *
133      * @return XXX
134      */

135     public WSDDOperation[] getOperations()
136     {
137         return null;
138     }
139
140     /**
141      *
142      * @param name XXX
143      * @return XXX
144      */

145     public WSDDOperation getOperation(String JavaDoc name)
146     {
147         return null;
148     }
149
150     /**
151      *
152      * @param registry XXX
153      * @return XXX
154      * @throws Exception XXX
155      */

156     public static Handler getInstance(QName JavaDoc providerType,
157                                WSDDService service,
158                                EngineConfiguration registry)
159         throws Exception JavaDoc
160     {
161         if (providerType == null)
162             throw new WSDDException(Messages.getMessage("nullProvider00"));
163         
164         WSDDProvider provider = (WSDDProvider)providers.get(providerType);
165         if (provider == null) {
166             throw new WSDDException(Messages.getMessage("noMatchingProvider00",
167                                     providerType.toString()));
168         }
169         
170         return provider.newProviderInstance(service, registry);
171     }
172
173     /**
174      *
175      * @param registry XXX
176      * @return XXX
177      * @throws Exception XXX
178      */

179     public abstract Handler newProviderInstance(WSDDService service,
180                                                 EngineConfiguration registry)
181         throws Exception JavaDoc;
182
183     public abstract String JavaDoc getName();
184 }
185
Popular Tags