KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.deployment.wsdd;
56
57 import org.apache.commons.discovery.ResourceNameIterator;
58 import org.apache.commons.discovery.resource.ClassLoaders;
59 import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
60 import org.jboss.axis.EngineConfiguration;
61 import org.jboss.axis.Handler;
62 import org.jboss.axis.deployment.wsdd.providers.WSDDComProvider;
63 import org.jboss.axis.deployment.wsdd.providers.WSDDHandlerProvider;
64 import org.jboss.axis.deployment.wsdd.providers.WSDDJavaMsgProvider;
65 import org.jboss.axis.deployment.wsdd.providers.WSDDJavaRPCProvider;
66 import org.jboss.axis.utils.JavaUtils;
67 import org.jboss.axis.utils.Messages;
68 import org.jboss.logging.Logger;
69
70 import javax.xml.namespace.QName JavaDoc;
71 import java.util.Hashtable JavaDoc;
72
73
74 /**
75  * WSDD provider element
76  * <p/>
77  * Represents the liason to the application being exposed
78  * as a Web Service.
79  * <p/>
80  * Specific provider extension classes must be registered
81  * by namespace URI.
82  *
83  * @author James Snell
84  * @author Vishy Kasar
85  */

86 public abstract class WSDDProvider
87 {
88    private static Logger log = Logger.getLogger(WSDDProvider.class.getName());
89
90 // ** STATIC PROVIDER REGISTRY ** //
91
private static final String JavaDoc PLUGABLE_PROVIDER_FILENAME =
92            "org.jboss.axis.deployment.wsdd.Provider";
93
94    /**
95     * XXX
96     */

97    private static Hashtable JavaDoc providers = new Hashtable JavaDoc();
98
99    static
100    {
101       providers.put(WSDDConstants.QNAME_JAVARPC_PROVIDER, new WSDDJavaRPCProvider());
102       providers.put(WSDDConstants.QNAME_JAVAMSG_PROVIDER, new WSDDJavaMsgProvider());
103       providers.put(WSDDConstants.QNAME_HANDLER_PROVIDER, new WSDDHandlerProvider());
104       providers.put(WSDDConstants.QNAME_COM_PROVIDER, new WSDDComProvider());
105       try
106       {
107          loadPluggableProviders();
108       }
109       catch (Throwable JavaDoc t)
110       {
111          String JavaDoc msg = t + JavaUtils.LS + JavaUtils.stackToString(t);
112          log.info(Messages.getMessage("exception01", msg));
113       }
114    }
115
116    /**
117     * Look for file META-INF/services/org.jboss.axis.deployment.wsdd.Provider
118     * in all the JARS, get the classes listed in those files and add them to
119     * providers list if they are valid providers.
120     * <p/>
121     * Here is how the scheme would work.
122     * <p/>
123     * A company providing a new provider will jar up their provider related
124     * classes in a JAR file. The following file containing the name of the new
125     * provider class is also made part of this JAR file.
126     * <p/>
127     * META-INF/services/org.jboss.axis.deployment.wsdd.Provider
128     * <p/>
129     * By making this JAR part of the webapp, the new provider will be
130     * automatically discovered.
131     */

132    private static void loadPluggableProviders()
133    {
134       ClassLoader JavaDoc clzLoader = WSDDProvider.class.getClassLoader();
135       ClassLoaders loaders = new ClassLoaders();
136       loaders.put(clzLoader);
137       DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
138       ResourceNameIterator iter = dsn.findResourceNames(PLUGABLE_PROVIDER_FILENAME);
139       while (iter.hasNext())
140       {
141          String JavaDoc className = iter.nextResourceName();
142          try
143          {
144             Object JavaDoc o = Class.forName(className).newInstance();
145             if (o instanceof WSDDProvider)
146             {
147                WSDDProvider provider = (WSDDProvider)o;
148                String JavaDoc providerName = provider.getName();
149                QName JavaDoc q = new QName JavaDoc(WSDDConstants.URI_WSDD_JAVA, providerName);
150                providers.put(q, provider);
151             }
152          }
153          catch (Exception JavaDoc e)
154          {
155             String JavaDoc msg = e + JavaUtils.LS + JavaUtils.stackToString(e);
156             log.info(Messages.getMessage("exception01", msg));
157             continue;
158          }
159       }
160    }
161
162    /**
163     * @param uri XXX
164     * @param prov XXX
165     */

166    public static void registerProvider(QName JavaDoc uri, WSDDProvider prov)
167    {
168       providers.put(uri, prov);
169    }
170
171    /**
172     * @return XXX
173     */

174    public WSDDOperation[] getOperations()
175    {
176       return null;
177    }
178
179    /**
180     * @param name XXX
181     * @return XXX
182     */

183    public WSDDOperation getOperation(String JavaDoc name)
184    {
185       return null;
186    }
187
188    /**
189     * @param registry XXX
190     * @return XXX
191     * @throws Exception XXX
192     */

193    public static Handler getInstance(QName JavaDoc providerType,
194                                      WSDDService service,
195                                      EngineConfiguration registry)
196            throws Exception JavaDoc
197    {
198       if (providerType == null)
199          throw new WSDDException(Messages.getMessage("nullProvider00"));
200
201       WSDDProvider provider = (WSDDProvider)providers.get(providerType);
202       if (provider == null)
203       {
204          throw new WSDDException(Messages.getMessage("noMatchingProvider00",
205                  providerType.toString()));
206       }
207
208       return provider.newProviderInstance(service, registry);
209    }
210
211    /**
212     * @param registry XXX
213     * @return XXX
214     * @throws Exception XXX
215     */

216    public abstract Handler newProviderInstance(WSDDService service,
217                                                EngineConfiguration registry)
218            throws Exception JavaDoc;
219
220    public abstract String JavaDoc getName();
221 }
222
Popular Tags