KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > soap > apacheaxis > WSIFDynamicProvider_ApacheAxis


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.apacheaxis;
59
60 import java.security.AccessController JavaDoc;
61 import java.security.PrivilegedAction JavaDoc;
62 import java.util.ArrayList JavaDoc;
63 import java.util.Iterator JavaDoc;
64 import java.util.List 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  * @author Owen Burroughs <owenb@apache.org>
81  * @author Ant Elder <antelder@apache.org>
82  * @author Jeremy Hughes <hughesj@apache.org>
83  * @author Mark Whitlock <whitlock@apache.org>
84  */

85 public class WSIFDynamicProvider_ApacheAxis implements WSIFProvider {
86
87     private static final boolean axisAvailable = isAXISAvailable();
88     private static final boolean jmsAvailable = isJMSAvailable();
89     private static final String JavaDoc[] bindings = setUpBindingNamespaceURIs();
90     private static final String JavaDoc[] addresses = setUpAddressNamespaceURIs();
91
92     /**
93      * Construct a new AXIS provider
94      */

95     public WSIFDynamicProvider_ApacheAxis() {
96         Trc.entry(this);
97         if (axisAvailable && jmsAvailable) {
98             WSIFServiceImpl.addExtensionRegistry(
99                 new org.apache.wsif.wsdl.extensions.jms.JMSExtensionRegistry());
100         }
101         Trc.exit();
102     }
103
104     /**
105      * Create a new AXIS WSIFPort
106      * @see WSIFProvider.createDynamicWSIFPort
107      */

108     public WSIFPort createDynamicWSIFPort(
109         Definition definition,
110         Service service,
111         Port port,
112         WSIFDynamicTypeMap wsifdynamictypemap)
113         throws WSIFException {
114         Trc.entry(this, definition, service, port, wsifdynamictypemap);
115
116         Binding binding = port.getBinding();
117         List JavaDoc list = binding.getExtensibilityElements();
118
119         WSIFPort wp = null;
120         for (Iterator JavaDoc i = list.iterator();(i.hasNext() && wp == null);) {
121             Object JavaDoc o = i.next();
122             if (o instanceof SOAPBinding) {
123                 wp = new WSIFPort_ApacheAxis(
124                         definition,
125                         port,
126                         (SOAPBinding) o,
127                         wsifdynamictypemap);
128             }
129         }
130
131         Trc.exit(wp);
132         return wp;
133     }
134
135     /**
136      * Returns the WSDL namespace URIs of any bindings this provider supports.
137      * @return an array of all binding namespaces supported by this provider
138      */

139     public String JavaDoc[] getBindingNamespaceURIs() {
140         Trc.entry(this);
141         Trc.exit(bindings);
142         return bindings;
143     }
144
145     /**
146      * Returns the WSDL namespace URIs of any port addresses this provider supports.
147      * @return an array of all address namespaces supported by this provider
148      */

149     public String JavaDoc[] getAddressNamespaceURIs() {
150         Trc.entry(this);
151         Trc.exit(addresses);
152         return addresses;
153     }
154
155     /**
156      * Sets up the binding namespace URIs this provider supports.
157      */

158     private static String JavaDoc[] setUpBindingNamespaceURIs() {
159         String JavaDoc[] bindings;
160         if (axisAvailable) {
161             bindings =
162                 new String JavaDoc[] { WSIFAXISConstants.SOAP_BINDING_NAMESPACE };
163         } else {
164             bindings = new String JavaDoc[0];
165         }
166         Trc.event("available binding namespace URIs: ", bindings);
167         return bindings;
168     }
169
170     /**
171      * Sets up the address namespace URIs this provider supports.
172      */

173     private static String JavaDoc[] setUpAddressNamespaceURIs() {
174         ArrayList JavaDoc l = new ArrayList JavaDoc();
175         if (isAXISAvailable()) {
176             l.add(WSIFAXISConstants.SOAP_BINDING_NAMESPACE);
177         }
178         if (jmsAvailable) {
179             l.add(WSIFAXISConstants.JMS_TRANSPORT_URI);
180         }
181         String JavaDoc[] addresses = new String JavaDoc[l.size()];
182         for (int i = 0; i < l.size(); i++) {
183             addresses[i] = (String JavaDoc) l.get(i);
184         }
185         Trc.event("available address namespace URIs: ", addresses);
186         return addresses;
187     }
188
189     /**
190      * Checks if the axis.jar is available in the Java CLASSPATH
191      */

192     private static boolean isAXISAvailable() {
193         return isClassAvailable(WSIFAXISConstants.CLASS_IN_AXIS_JAR);
194     }
195
196     /**
197      * Checks if the JMS API jar is available in the Java CLASSPATH
198      */

199     private static boolean isJMSAvailable() {
200         return isClassAvailable(WSIFAXISConstants.CLASS_IN_JMS_JAR);
201     }
202
203     /**
204      * Checks if a class is available in the Java CLASSPATH
205      */

206     private static boolean isClassAvailable(final String JavaDoc className) {
207         Class JavaDoc c =
208             (Class JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
209             public Object JavaDoc run() {
210                 try {
211                     return Class.forName(
212                         className,
213                         true,
214                         Thread.currentThread().getContextClassLoader());
215                 } catch (Throwable JavaDoc ignored) {
216                     Trc.ignoredException(ignored);
217                 }
218                 return null;
219             }
220         });
221         return c != null;
222     }
223
224 }
Popular Tags