KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > soap > apachesoap > WSIFDynamicProvider_ApacheSOAP


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 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 "WSIF" 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 and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.providers.soap.apachesoap;
59
60 import java.security.AccessController JavaDoc;
61 import java.security.PrivilegedAction JavaDoc;
62 import java.util.Iterator JavaDoc;
63 import java.util.List JavaDoc;
64 import java.util.Vector JavaDoc;
65
66 import javax.wsdl.Binding;
67 import javax.wsdl.Definition;
68 import javax.wsdl.Port;
69 import javax.wsdl.Service;
70 import javax.wsdl.extensions.soap.SOAPBinding;
71
72 import org.apache.wsif.WSIFException;
73 import org.apache.wsif.WSIFPort;
74 import org.apache.wsif.base.WSIFServiceImpl;
75 import org.apache.wsif.logging.Trc;
76 import org.apache.wsif.providers.WSIFDynamicTypeMap;
77 import org.apache.wsif.spi.WSIFProvider;
78
79 /**
80  * ApacheSOAP specific provider of dynamic WSDL invocations.
81  *
82  * @author Aleksander Slominski
83  * @author Owen Burroughs <owenb@apache.org>
84  * @author Ant Elder <antelder@apache.org>
85  * @author Jeremy Hughes <hughesj@apache.org>
86  * @author Mark Whitlock <whitlock@apache.org>
87
88  */

89 public class WSIFDynamicProvider_ApacheSOAP implements WSIFProvider {
90     protected String JavaDoc partSerializerName = null;
91
92     private static final String JavaDoc soap = "http://schemas.xmlsoap.org/wsdl/soap/";
93     private static final String JavaDoc jms = "http://schemas.xmlsoap.org/wsdl/jms/";
94     private static String JavaDoc[] bindings = new String JavaDoc[0];
95     private static String JavaDoc[] addresses = new String JavaDoc[0];
96     private static boolean setUpBindings = false;
97     private static boolean setUpAddresses = false;
98
99     public WSIFDynamicProvider_ApacheSOAP() {
100         Trc.entry(this);
101         if (!setUpBindings) {
102             setUpBindingNamespaceURIs();
103         }
104         if (!setUpAddresses) {
105             setUpAddressNamespaceURIs();
106         }
107         WSIFServiceImpl.addExtensionRegistry(
108             new org.apache.wsif.wsdl.extensions.jms.JMSExtensionRegistry());
109         Trc.exit();
110     }
111
112     /**
113      * Check if WSDL port has SOAP binding and if successful try
114      * to create ApacheSOAP port instance.
115      */

116     public WSIFPort createDynamicWSIFPort(
117         Definition def,
118         Service service,
119         Port port,
120         WSIFDynamicTypeMap typeMap)
121         throws WSIFException {
122         Trc.entry(this, def, service, port, typeMap);
123
124         // check that Port binding has SOAP binding extensibility element
125
Binding binding = port.getBinding();
126         List JavaDoc exs = binding.getExtensibilityElements();
127         for (Iterator JavaDoc i = exs.iterator(); i.hasNext();) {
128             Object JavaDoc o = i.next();
129             if (o instanceof SOAPBinding) {
130                 // if so try to create ApacheSOAP dynamic port instance
131
WSIFPort wp =
132                     new WSIFPort_ApacheSOAP(
133                         def,
134                         service,
135                         port,
136                         typeMap,
137                         partSerializerName);
138                 Trc.exit(wp);
139                 return wp;
140             }
141         }
142
143         // otherwise return null (so other providers can be checked)
144
Trc.exit(null);
145         return null;
146     }
147
148     /**
149      * Gets the partSerializerName.
150      * @return Returns a String
151      */

152     public String JavaDoc getPartSerializerName() {
153         Trc.entry(this);
154         Trc.exit(partSerializerName);
155         return partSerializerName;
156     }
157
158     /**
159      * Sets the partSerializerName.
160      * @param partSerializerName The partSerializerName to set
161      */

162     public void setPartSerializerName(String JavaDoc partSerializerName) {
163         Trc.entry(this, partSerializerName);
164         this.partSerializerName = partSerializerName;
165         Trc.exit();
166     }
167
168     /**
169      * Returns the WSDL namespace URIs of any bindings this provider supports.
170      * @return an array of all binding namespaces supported by this provider
171      */

172     public String JavaDoc[] getBindingNamespaceURIs() {
173         Trc.entry(this);
174         Trc.exit(bindings);
175         return bindings;
176     }
177
178     /**
179      * Returns the WSDL namespace URIs of any port addresses this provider supports.
180      * @return an array of all address namespaces supported by this provider
181      */

182     public String JavaDoc[] getAddressNamespaceURIs() {
183         Trc.entry(this);
184         Trc.exit(addresses);
185         return addresses;
186     }
187
188     private void setUpBindingNamespaceURIs() {
189         // check if the soap classes are available, if not then we cannot
190
// support soap bindings!
191
Class JavaDoc cls =
192             (Class JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
193             public Object JavaDoc run() {
194                 try {
195                     return Class.forName(
196                         "org.apache.soap.Constants",
197                         true,
198                         Thread.currentThread().getContextClassLoader());
199                 } catch (Throwable JavaDoc ignored) {
200                     Trc.ignoredException(ignored);
201                 }
202                 return null;
203             }
204         });
205         if (cls != null) {
206             bindings = new String JavaDoc[] { soap };
207         }
208         setUpBindings = true;
209     }
210
211     private void setUpAddressNamespaceURIs() {
212         Vector JavaDoc v = new Vector JavaDoc();
213         // check if the jms classes are available, if not then we cannot
214
// support jms addresses!
215
Class JavaDoc cls =
216             (Class JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
217             public Object JavaDoc run() {
218                 try {
219                     return Class.forName(
220                         "javax.jms.Queue",
221                         true,
222                         Thread.currentThread().getContextClassLoader());
223                 } catch (Throwable JavaDoc ignored) {
224                     Trc.ignoredException(ignored);
225                 }
226                 return null;
227             }
228         });
229         if (cls != null) {
230             v.add(jms);
231         }
232                         
233         // check if the soap classes are available, if not then we cannot
234
// support soap addresses!
235
Class JavaDoc cls2 =
236             (Class JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
237             public Object JavaDoc run() {
238                 try {
239                     return Class.forName(
240                         "org.apache.soap.Constants",
241                         true,
242                         Thread.currentThread().getContextClassLoader());
243                 } catch (Throwable JavaDoc ignored) {
244                     Trc.ignoredException(ignored);
245                 }
246                 return null;
247             }
248         });
249         if (cls2 != null) {
250             v.add(soap);
251         }
252         addresses = null;
253         addresses = new String JavaDoc[v.size()];
254         for (int i = 0; i < v.size(); i++) {
255             addresses[i] = (String JavaDoc) v.elementAt(i);
256         }
257         setUpAddresses = true;
258     }
259 }
Popular Tags