001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.wsif.providers.soap.apacheaxis;
059:
060: import java.security.AccessController;
061: import java.security.PrivilegedAction;
062: import java.util.ArrayList;
063: import java.util.Iterator;
064: import java.util.List;
065:
066: import javax.wsdl.Binding;
067: import javax.wsdl.Definition;
068: import javax.wsdl.Port;
069: import javax.wsdl.Service;
070: import javax.wsdl.extensions.soap.SOAPBinding;
071:
072: import org.apache.wsif.WSIFException;
073: import org.apache.wsif.WSIFPort;
074: import org.apache.wsif.base.WSIFServiceImpl;
075: import org.apache.wsif.logging.Trc;
076: import org.apache.wsif.providers.WSIFDynamicTypeMap;
077: import org.apache.wsif.spi.WSIFProvider;
078:
079: /**
080: * @author Owen Burroughs <owenb@apache.org>
081: * @author Ant Elder <antelder@apache.org>
082: * @author Jeremy Hughes <hughesj@apache.org>
083: * @author Mark Whitlock <whitlock@apache.org>
084: */
085: public class WSIFDynamicProvider_ApacheAxis implements WSIFProvider {
086:
087: private static final boolean axisAvailable = isAXISAvailable();
088: private static final boolean jmsAvailable = isJMSAvailable();
089: private static final String[] bindings = setUpBindingNamespaceURIs();
090: private static final String[] addresses = setUpAddressNamespaceURIs();
091:
092: /**
093: * Construct a new AXIS provider
094: */
095: public WSIFDynamicProvider_ApacheAxis() {
096: Trc.entry(this );
097: if (axisAvailable && jmsAvailable) {
098: WSIFServiceImpl
099: .addExtensionRegistry(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(Definition definition,
109: Service service, Port port,
110: WSIFDynamicTypeMap wsifdynamictypemap) throws WSIFException {
111: Trc.entry(this , definition, service, port, wsifdynamictypemap);
112:
113: Binding binding = port.getBinding();
114: List list = binding.getExtensibilityElements();
115:
116: WSIFPort wp = null;
117: for (Iterator i = list.iterator(); (i.hasNext() && wp == null);) {
118: Object o = i.next();
119: if (o instanceof SOAPBinding) {
120: wp = new WSIFPort_ApacheAxis(definition, port,
121: (SOAPBinding) o, wsifdynamictypemap);
122: }
123: }
124:
125: Trc.exit(wp);
126: return wp;
127: }
128:
129: /**
130: * Returns the WSDL namespace URIs of any bindings this provider supports.
131: * @return an array of all binding namespaces supported by this provider
132: */
133: public String[] getBindingNamespaceURIs() {
134: Trc.entry(this );
135: Trc.exit(bindings);
136: return bindings;
137: }
138:
139: /**
140: * Returns the WSDL namespace URIs of any port addresses this provider supports.
141: * @return an array of all address namespaces supported by this provider
142: */
143: public String[] getAddressNamespaceURIs() {
144: Trc.entry(this );
145: Trc.exit(addresses);
146: return addresses;
147: }
148:
149: /**
150: * Sets up the binding namespace URIs this provider supports.
151: */
152: private static String[] setUpBindingNamespaceURIs() {
153: String[] bindings;
154: if (axisAvailable) {
155: bindings = new String[] { WSIFAXISConstants.SOAP_BINDING_NAMESPACE };
156: } else {
157: bindings = new String[0];
158: }
159: Trc.event("available binding namespace URIs: ", bindings);
160: return bindings;
161: }
162:
163: /**
164: * Sets up the address namespace URIs this provider supports.
165: */
166: private static String[] setUpAddressNamespaceURIs() {
167: ArrayList l = new ArrayList();
168: if (isAXISAvailable()) {
169: l.add(WSIFAXISConstants.SOAP_BINDING_NAMESPACE);
170: }
171: if (jmsAvailable) {
172: l.add(WSIFAXISConstants.JMS_TRANSPORT_URI);
173: }
174: String[] addresses = new String[l.size()];
175: for (int i = 0; i < l.size(); i++) {
176: addresses[i] = (String) l.get(i);
177: }
178: Trc.event("available address namespace URIs: ", addresses);
179: return addresses;
180: }
181:
182: /**
183: * Checks if the axis.jar is available in the Java CLASSPATH
184: */
185: private static boolean isAXISAvailable() {
186: return isClassAvailable(WSIFAXISConstants.CLASS_IN_AXIS_JAR);
187: }
188:
189: /**
190: * Checks if the JMS API jar is available in the Java CLASSPATH
191: */
192: private static boolean isJMSAvailable() {
193: return isClassAvailable(WSIFAXISConstants.CLASS_IN_JMS_JAR);
194: }
195:
196: /**
197: * Checks if a class is available in the Java CLASSPATH
198: */
199: private static boolean isClassAvailable(final String className) {
200: Class c = (Class) AccessController
201: .doPrivileged(new PrivilegedAction() {
202: public Object run() {
203: try {
204: return Class.forName(className, true,
205: Thread.currentThread()
206: .getContextClassLoader());
207: } catch (Throwable ignored) {
208: Trc.ignoredException(ignored);
209: }
210: return null;
211: }
212: });
213: return c != null;
214: }
215:
216: }
|