KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > configuration > SimpleProvider


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
56 package org.jboss.axis.configuration;
57
58 import org.jboss.axis.AxisEngine;
59 import org.jboss.axis.ConfigurationException;
60 import org.jboss.axis.EngineConfiguration;
61 import org.jboss.axis.Handler;
62 import org.jboss.axis.encoding.TypeMapping;
63 import org.jboss.axis.encoding.TypeMappingRegistry;
64 import org.jboss.axis.encoding.TypeMappingRegistryImpl;
65 import org.jboss.axis.handlers.soap.SOAPService;
66
67 import javax.xml.namespace.QName JavaDoc;
68 import java.util.ArrayList JavaDoc;
69 import java.util.HashMap JavaDoc;
70 import java.util.Hashtable JavaDoc;
71 import java.util.Iterator JavaDoc;
72
73 /**
74  * A SimpleProvider is an EngineConfiguration which contains a simple
75  * HashMap-based registry of Handlers, Transports, and Services. This is
76  * for when you want to programatically deploy components which you create.
77  * <p/>
78  * SimpleProvider may also optionally contain a reference to a "default"
79  * EngineConfiguration, which will be scanned for components not found in
80  * the internal registry. This is handy when you want to start with a base
81  * configuration (like the default WSDD) and then quickly add stuff without
82  * changing the WSDD document.
83  *
84  * @author Glen Daniels (gdaniels@macromedia.com)
85  */

86 public class SimpleProvider implements EngineConfiguration
87 {
88    /**
89     * Handler registry
90     */

91    HashMap JavaDoc handlers = new HashMap JavaDoc();
92    /**
93     * Transport registry
94     */

95    HashMap JavaDoc transports = new HashMap JavaDoc();
96    /**
97     * Service registry
98     */

99    HashMap JavaDoc services = new HashMap JavaDoc();
100
101    /**
102     * Global configuration stuff
103     */

104    Hashtable JavaDoc globalOptions = null;
105    Handler globalRequest = null;
106    Handler globalResponse = null;
107
108    /**
109     * Our TypeMappingRegistry
110     */

111    TypeMappingRegistry tmr = null;
112
113    /**
114     * An optional "default" EngineConfiguration
115     */

116    EngineConfiguration defaultConfiguration = null;
117    private AxisEngine engine;
118
119    /**
120     * Default constructor.
121     */

122    public SimpleProvider()
123    {
124    }
125
126    /**
127     * Constructor which takes an EngineConfiguration which will be used
128     * as the default.
129     */

130    public SimpleProvider(EngineConfiguration defaultConfiguration)
131    {
132       this.defaultConfiguration = defaultConfiguration;
133    }
134
135    /**
136     * Configure an AxisEngine. Right now just calls the default
137     * configuration if there is one, since we don't do anything special.
138     */

139    public void configureEngine(AxisEngine engine) throws ConfigurationException
140    {
141       this.engine = engine;
142
143       if (defaultConfiguration != null)
144          defaultConfiguration.configureEngine(engine);
145
146       for (Iterator JavaDoc i = services.values().iterator(); i.hasNext();)
147       {
148          ((SOAPService)i.next()).setEngine(engine);
149       }
150    }
151
152    /**
153     * We don't write ourselves out, so this is a noop.
154     */

155    public void writeEngineConfig(AxisEngine engine) throws ConfigurationException
156    {
157    }
158
159    /**
160     * Returns the global configuration options.
161     */

162    public Hashtable JavaDoc getGlobalOptions() throws ConfigurationException
163    {
164       if (globalOptions != null)
165          return globalOptions;
166
167       if (defaultConfiguration != null)
168          return defaultConfiguration.getGlobalOptions();
169
170       return null;
171    }
172
173    /**
174     * Returns a global response handler.
175     */

176    public Handler getGlobalResponse() throws ConfigurationException
177    {
178       if (globalResponse != null)
179          return globalResponse;
180
181       if (defaultConfiguration != null)
182          return defaultConfiguration.getGlobalResponse();
183
184       return null;
185    }
186
187    /**
188     * Returns a global request handler.
189     */

190    public Handler getGlobalRequest() throws ConfigurationException
191    {
192       if (globalRequest != null)
193          return globalRequest;
194
195       if (defaultConfiguration != null)
196          return defaultConfiguration.getGlobalRequest();
197
198       return null;
199    }
200
201    /**
202     * Get our TypeMappingRegistry. Returns our specific one if we have
203     * one, otherwise the one from our defaultConfiguration. If we don't
204     * have one and also don't have a defaultConfiguration, we create one.
205     */

206    public TypeMappingRegistry getTypeMappingRegistry() throws ConfigurationException
207    {
208       if (tmr != null)
209          return tmr;
210
211       if (defaultConfiguration != null)
212          return defaultConfiguration.getTypeMappingRegistry();
213
214       // No default config, but we need a TypeMappingRegistry...
215
// (perhaps the TMRs could just be chained?)
216
tmr = new TypeMappingRegistryImpl();
217       return tmr;
218    }
219
220    public TypeMapping getTypeMapping(String JavaDoc encodingStyle) throws ConfigurationException
221    {
222       return (TypeMapping)getTypeMappingRegistry().getTypeMapping(encodingStyle);
223    }
224
225    public Handler getTransport(QName JavaDoc qname) throws ConfigurationException
226    {
227       Handler transport = (Handler)transports.get(qname);
228       if ((defaultConfiguration != null) && (transport == null))
229          transport = defaultConfiguration.getTransport(qname);
230       return transport;
231    }
232
233    public SOAPService getService(QName JavaDoc qname) throws ConfigurationException
234    {
235       SOAPService service = (SOAPService)services.get(qname);
236       if ((defaultConfiguration != null) && (service == null))
237          service = defaultConfiguration.getService(qname);
238       return service;
239    }
240
241    /**
242     * Get a service which has been mapped to a particular namespace
243     *
244     * @param namespace a namespace URI
245     * @return an instance of the appropriate Service, or null
246     */

247    public SOAPService getServiceByNamespaceURI(String JavaDoc namespace)
248            throws ConfigurationException
249    {
250       SOAPService service = (SOAPService)services.get(new QName JavaDoc("", namespace));
251       if ((service == null) && (defaultConfiguration != null))
252          service = defaultConfiguration.getServiceByNamespaceURI(namespace);
253       return service;
254    }
255
256    public Handler getHandler(QName JavaDoc qname) throws ConfigurationException
257    {
258       Handler handler = (Handler)handlers.get(qname);
259       if ((defaultConfiguration != null) && (handler == null))
260          handler = defaultConfiguration.getHandler(qname);
261       return handler;
262    }
263
264    public void deployService(QName JavaDoc qname, SOAPService service)
265    {
266       services.put(qname, service);
267       if (engine != null)
268          service.setEngine(engine);
269    }
270
271    public void deployService(String JavaDoc name, SOAPService service)
272    {
273       deployService(new QName JavaDoc(null, name), service);
274    }
275
276    public void deployTransport(QName JavaDoc qname, Handler transport)
277    {
278       transports.put(qname, transport);
279    }
280
281    public void deployTransport(String JavaDoc name, Handler transport)
282    {
283       deployTransport(new QName JavaDoc(null, name), transport);
284    }
285
286    /**
287     * Get an enumeration of the services deployed to this engine
288     */

289    public Iterator JavaDoc getDeployedServices() throws ConfigurationException
290    {
291       ArrayList JavaDoc serviceDescs = new ArrayList JavaDoc();
292       Iterator JavaDoc i = services.values().iterator();
293       while (i.hasNext())
294       {
295          SOAPService service = (SOAPService)i.next();
296          serviceDescs.add(service.getServiceDescription());
297       }
298       return serviceDescs.iterator();
299    }
300 }
301
Popular Tags