KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > myeis > wsif > providers > j2c > myeis > WSIFProvider_MyEIS


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 com.myeis.wsif.providers.j2c.myeis;
59
60 import javax.resource.*;
61 import javax.resource.cci.*;
62 import javax.wsdl.*;
63 import javax.wsdl.Binding;
64 import javax.wsdl.extensions.*;
65
66 import java.util.Iterator JavaDoc;
67 import java.util.List JavaDoc;
68
69 import com.myeis.j2c.*;
70 import com.myeis.wsdl.extensions.j2c.myeis.*;
71 import org.apache.wsif.*;
72 import org.apache.wsif.base.*;
73 import org.apache.wsif.providers.jca.*;
74 import org.apache.wsif.providers.jca.WSIFUtils_JCA;
75 import org.apache.wsif.providers.*;
76
77 public class WSIFProvider_MyEIS implements org.apache.wsif.spi.WSIFProvider, org.apache.wsif.providers.jca.WSIFProviderJCAExtensions {
78
79     private final String JavaDoc[] namespaces = {MyEISBindingConstants.NS_URI};
80
81     /**
82      * WSIFDynamicProvider_MyEIS default constructor
83      */

84     public WSIFProvider_MyEIS() {
85         super();
86         WSIFServiceImpl.addExtensionRegistry(new MyEISExtensionRegistry());
87     }
88     
89     /**
90      * @see WSIFDynamicProvider#createDynamicWSIFPort(Definition, Service, Port, WSIFDynamicTypeMap)
91      */

92     public WSIFPort createDynamicWSIFPort(Definition definition, Service service, Port port, WSIFDynamicTypeMap typeMap) throws WSIFException {
93         
94         WSIFPort_JCA jcaPort = null;
95         Connection connection = null;
96         ConnectionFactory connectionFactory = null;
97
98         Binding binding = port.getBinding();
99         List JavaDoc eElements = binding.getExtensibilityElements();
100         Iterator JavaDoc iterator = eElements.iterator();
101         while (iterator.hasNext()) {
102             Object JavaDoc o = iterator.next();
103             if (o instanceof MyEISBinding) {
104                 /*
105                  * To create the connection factory, the default behaviour is to assume that the J2EE Connector is running
106                  * in a managed mode (i.e. deployed on an Application Server with a JNDI name). Hence the first attempt is done
107                  * by retrieving the connection factory using a JNDI lookup name.
108                  */

109                 String JavaDoc res_ref_name = WSIFUtils_JCA.getJNDILookupName(service, port);
110                 connectionFactory = WSIFUtils_JCA.lookupConnectionFactory(res_ref_name, "javax.resource.cci.ConnectionFactory");
111                 
112                 try {
113                     ExtensibilityElement portExtension = (ExtensibilityElement) port.getExtensibilityElements().get(0);
114
115                     if (portExtension == null) {
116                         return jcaPort;
117                     }
118                     MyEISAddress address = (MyEISAddress) portExtension;
119                     if (connectionFactory == null) {
120                         /*
121                          * The JNDI lookup must have failed, so we fall back to a non-managed mode. (i.e. we manually create
122                          * the managed connection factory and a connection.
123                          */

124                         MyEISManagedConnectionFactory managedConnectionFactory = new MyEISManagedConnectionFactory();
125                         managedConnectionFactory.setRepositoryLocation(address.getRepositoryLocation());
126                         connectionFactory = (ConnectionFactory) managedConnectionFactory.createConnectionFactory();
127                     }
128                     connection = connectionFactory.getConnection();
129                 }
130                 catch(Throwable JavaDoc exn){
131                     return jcaPort;
132                 }
133                 jcaPort = new WSIFPort_JCA(definition, service, port, connection, this, typeMap);
134                 return jcaPort;
135                 
136             }
137         }
138         return jcaPort;
139     }
140
141
142     public WSIFMessage createInputMessage(Definition definition, Binding binding, String JavaDoc operationName, String JavaDoc inputName, String JavaDoc outputName){return null;}
143     public WSIFMessage createOutputMessage(Definition definition, Binding binding, String JavaDoc operationName, String JavaDoc inputName, String JavaDoc outputName){return null;}
144     public WSIFMessage createFaultMessage(Definition definition, Binding binding, String JavaDoc operationName, String JavaDoc inputName, String JavaDoc outputName){return null;}
145
146     public String JavaDoc[] getBindingNamespaceURIs(){
147         return namespaces;
148     }
149
150     public String JavaDoc[] getAddressNamespaceURIs(){
151         return namespaces;
152     }
153     public void updateOutputMessage(WSIFMessage output, Binding aBinding, String JavaDoc aOperationName, String JavaDoc aInputName, String JavaDoc aOutputName, InteractionSpec aInteractionSpec) {
154         // Not supported in this sample
155
}
156     public void updateInteractionSpec(WSIFMessage input, Binding aBinding, String JavaDoc aOperationName, String JavaDoc aInputName, String JavaDoc aOutputName, InteractionSpec aInteractionSpec) {
157         // Not supported in this sample
158
}
159     
160     
161     /**
162      * @see org.apache.wsif.providers.jca.WSIFProviderJCAExtensions#createConnection(WSIFMessage, Definition, Service, Port, WSIFDynamicTypeMap, Binding, String, String, String)
163      */

164     public Connection createConnection(
165         WSIFMessage input,
166         Definition definition,
167         Service service,
168         Port port,
169         WSIFDynamicTypeMap typeMap,
170         Binding aBinding,
171         String JavaDoc aOperationName,
172         String JavaDoc aInputName,
173         String JavaDoc aOutputName)
174         throws WSIFException {
175         return null;
176     }
177
178     /**
179      * @see org.apache.wsif.providers.jca.WSIFProviderJCAExtensions#createOperation(Definition, Service, Port, String, String, String, WSIFDynamicTypeMap, WSIFPort_JCA, Connection)
180      */

181     public WSIFOperation createOperation(
182         Definition aDefinition,
183         Service aService,
184         Port aPort,
185         String JavaDoc aOperationName,
186         String JavaDoc aInputName,
187         String JavaDoc aOutputName,
188         WSIFDynamicTypeMap typeMap,
189         WSIFPort_JCA jcaPort,
190         Connection aConnection)
191         throws WSIFException {
192         WSIFOperation_JCA operation = null;
193
194         try {
195             BindingOperation bindingOperationModel = aPort.getBinding().getBindingOperation(aOperationName, aInputName, aOutputName);
196
197             ExtensibilityElement bindingOperationModelExtension = (ExtensibilityElement) bindingOperationModel.getExtensibilityElements().get(0);
198             if (bindingOperationModelExtension == null) {
199                 throw new WSIFException("missing bindingOperation extension");
200             }
201             if (!(bindingOperationModelExtension instanceof MyEISOperation)) {
202                 throw new WSIFException("invalid extensibility element");
203             }
204
205             MyEISOperation operationModelExtension = (MyEISOperation) bindingOperationModelExtension;
206
207             MyEISInteractionSpec interactionSpec = new MyEISInteractionSpec();
208             interactionSpec.setFunctionName(operationModelExtension.getFunctionName());
209
210             operation = new WSIFOperation_JCA(aDefinition, aService, aPort, aOperationName, aInputName, aOutputName, typeMap, jcaPort, this, aConnection, interactionSpec);
211         }
212         catch (Exception JavaDoc e) {
213             e.printStackTrace();
214         }
215
216         return operation;
217     }
218
219 }
Popular Tags