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 com.myeis.wsif.providers.j2c.myeis;
059:
060: import javax.resource.*;
061: import javax.resource.cci.*;
062: import javax.wsdl.*;
063: import javax.wsdl.Binding;
064: import javax.wsdl.extensions.*;
065:
066: import java.util.Iterator;
067: import java.util.List;
068:
069: import com.myeis.j2c.*;
070: import com.myeis.wsdl.extensions.j2c.myeis.*;
071: import org.apache.wsif.*;
072: import org.apache.wsif.base.*;
073: import org.apache.wsif.providers.jca.*;
074: import org.apache.wsif.providers.jca.WSIFUtils_JCA;
075: import org.apache.wsif.providers.*;
076:
077: public class WSIFProvider_MyEIS implements
078: org.apache.wsif.spi.WSIFProvider,
079: org.apache.wsif.providers.jca.WSIFProviderJCAExtensions {
080:
081: private final String[] namespaces = { MyEISBindingConstants.NS_URI };
082:
083: /**
084: * WSIFDynamicProvider_MyEIS default constructor
085: */
086: public WSIFProvider_MyEIS() {
087: super ();
088: WSIFServiceImpl
089: .addExtensionRegistry(new MyEISExtensionRegistry());
090: }
091:
092: /**
093: * @see WSIFDynamicProvider#createDynamicWSIFPort(Definition, Service, Port, WSIFDynamicTypeMap)
094: */
095: public WSIFPort createDynamicWSIFPort(Definition definition,
096: Service service, Port port, WSIFDynamicTypeMap typeMap)
097: throws WSIFException {
098:
099: WSIFPort_JCA jcaPort = null;
100: Connection connection = null;
101: ConnectionFactory connectionFactory = null;
102:
103: Binding binding = port.getBinding();
104: List eElements = binding.getExtensibilityElements();
105: Iterator iterator = eElements.iterator();
106: while (iterator.hasNext()) {
107: Object o = iterator.next();
108: if (o instanceof MyEISBinding) {
109: /*
110: * To create the connection factory, the default behaviour is to assume that the J2EE Connector is running
111: * in a managed mode (i.e. deployed on an Application Server with a JNDI name). Hence the first attempt is done
112: * by retrieving the connection factory using a JNDI lookup name.
113: */
114: String res_ref_name = WSIFUtils_JCA.getJNDILookupName(
115: service, port);
116: connectionFactory = WSIFUtils_JCA
117: .lookupConnectionFactory(res_ref_name,
118: "javax.resource.cci.ConnectionFactory");
119:
120: try {
121: ExtensibilityElement portExtension = (ExtensibilityElement) port
122: .getExtensibilityElements().get(0);
123:
124: if (portExtension == null) {
125: return jcaPort;
126: }
127: MyEISAddress address = (MyEISAddress) portExtension;
128: if (connectionFactory == null) {
129: /*
130: * The JNDI lookup must have failed, so we fall back to a non-managed mode. (i.e. we manually create
131: * the managed connection factory and a connection.
132: */
133: MyEISManagedConnectionFactory managedConnectionFactory = new MyEISManagedConnectionFactory();
134: managedConnectionFactory
135: .setRepositoryLocation(address
136: .getRepositoryLocation());
137: connectionFactory = (ConnectionFactory) managedConnectionFactory
138: .createConnectionFactory();
139: }
140: connection = connectionFactory.getConnection();
141: } catch (Throwable exn) {
142: return jcaPort;
143: }
144: jcaPort = new WSIFPort_JCA(definition, service, port,
145: connection, this , typeMap);
146: return jcaPort;
147:
148: }
149: }
150: return jcaPort;
151: }
152:
153: public WSIFMessage createInputMessage(Definition definition,
154: Binding binding, String operationName, String inputName,
155: String outputName) {
156: return null;
157: }
158:
159: public WSIFMessage createOutputMessage(Definition definition,
160: Binding binding, String operationName, String inputName,
161: String outputName) {
162: return null;
163: }
164:
165: public WSIFMessage createFaultMessage(Definition definition,
166: Binding binding, String operationName, String inputName,
167: String outputName) {
168: return null;
169: }
170:
171: public String[] getBindingNamespaceURIs() {
172: return namespaces;
173: }
174:
175: public String[] getAddressNamespaceURIs() {
176: return namespaces;
177: }
178:
179: public void updateOutputMessage(WSIFMessage output,
180: Binding aBinding, String aOperationName, String aInputName,
181: String aOutputName, InteractionSpec aInteractionSpec) {
182: // Not supported in this sample
183: }
184:
185: public void updateInteractionSpec(WSIFMessage input,
186: Binding aBinding, String aOperationName, String aInputName,
187: String aOutputName, InteractionSpec aInteractionSpec) {
188: // Not supported in this sample
189: }
190:
191: /**
192: * @see org.apache.wsif.providers.jca.WSIFProviderJCAExtensions#createConnection(WSIFMessage, Definition, Service, Port, WSIFDynamicTypeMap, Binding, String, String, String)
193: */
194: public Connection createConnection(WSIFMessage input,
195: Definition definition, Service service, Port port,
196: WSIFDynamicTypeMap typeMap, Binding aBinding,
197: String aOperationName, String aInputName, String aOutputName)
198: throws WSIFException {
199: return null;
200: }
201:
202: /**
203: * @see org.apache.wsif.providers.jca.WSIFProviderJCAExtensions#createOperation(Definition, Service, Port, String, String, String, WSIFDynamicTypeMap, WSIFPort_JCA, Connection)
204: */
205: public WSIFOperation createOperation(Definition aDefinition,
206: Service aService, Port aPort, String aOperationName,
207: String aInputName, String aOutputName,
208: WSIFDynamicTypeMap typeMap, WSIFPort_JCA jcaPort,
209: Connection aConnection) throws WSIFException {
210: WSIFOperation_JCA operation = null;
211:
212: try {
213: BindingOperation bindingOperationModel = aPort.getBinding()
214: .getBindingOperation(aOperationName, aInputName,
215: aOutputName);
216:
217: ExtensibilityElement bindingOperationModelExtension = (ExtensibilityElement) bindingOperationModel
218: .getExtensibilityElements().get(0);
219: if (bindingOperationModelExtension == null) {
220: throw new WSIFException(
221: "missing bindingOperation extension");
222: }
223: if (!(bindingOperationModelExtension instanceof MyEISOperation)) {
224: throw new WSIFException("invalid extensibility element");
225: }
226:
227: MyEISOperation operationModelExtension = (MyEISOperation) bindingOperationModelExtension;
228:
229: MyEISInteractionSpec interactionSpec = new MyEISInteractionSpec();
230: interactionSpec.setFunctionName(operationModelExtension
231: .getFunctionName());
232:
233: operation = new WSIFOperation_JCA(aDefinition, aService,
234: aPort, aOperationName, aInputName, aOutputName,
235: typeMap, jcaPort, this , aConnection,
236: interactionSpec);
237: } catch (Exception e) {
238: e.printStackTrace();
239: }
240:
241: return operation;
242: }
243:
244: }
|