KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > jca > WSIFOperation_JCA


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 package org.apache.wsif.providers.jca;
58
59 import javax.resource.*;
60 import org.apache.wsif.logging.*;
61 import org.apache.wsif.providers.*;
62 import org.apache.wsif.*;
63 import org.apache.wsif.base.*;
64 import org.apache.wsif.util.*;
65 import javax.resource.*;
66 import javax.resource.cci.*;
67 import javax.wsdl.extensions.*;
68 import javax.wsdl.*;
69 import java.net.URL JavaDoc;
70 import java.util.*;
71 import javax.resource.cci.*;
72 import java.io.Serializable JavaDoc;
73 import java.util.*;
74
75 /**
76  * The WSIFOperation_JCA class is an implementation of the WSIFOperation interface,
77  * which is used to execute interactions with the EIS.
78  *
79  * @author Michael Beisiegel
80  * @author Piotr Przybylski <piotrp@ca.ibm.com>
81  * @author John Green
82  */

83 public class WSIFOperation_JCA implements WSIFOperation {
84
85     private static final long serialVersionUID = 1L;
86     protected Connection fieldConnection;
87     protected InteractionSpec fieldInteractionSpec;
88     protected Definition fieldDefinition;
89     protected Binding fieldBinding;
90     protected String JavaDoc fieldOperationName;
91     protected String JavaDoc fieldInputName;
92     protected String JavaDoc fieldOutputName;
93     protected Operation fieldOperation;
94     protected WSIFProviderJCAExtensions fieldFactory = null;
95     private final static String JavaDoc crlf = System.getProperty("line.separator");
96     private org.apache.wsif.providers.WSIFDynamicTypeMap fieldTypeMap;
97     private Port fieldPort;
98     private Service fieldService;
99     private WSIFPort_JCA fieldJcaPort;
100     
101     /**
102      * The WSIFOperation_JCA constructor.
103      * @param aDefinition
104      * @param aBinding
105      * @param aOperationName
106      * @param aInputName
107      * @param aOutputName
108      * @param aConnection
109      * @param aInteractionSpec
110      * @param aFactory
111      * @param typeMap
112      * @param aPort
113      * @param aService
114      * @param jcaPort
115      */

116     public WSIFOperation_JCA(
117         Definition aDefinition,
118         Service aService,
119         Port aPort,
120         String JavaDoc aOperationName,
121         String JavaDoc aInputName,
122         String JavaDoc aOutputName,
123         org.apache.wsif.providers.WSIFDynamicTypeMap typeMap,
124         WSIFPort_JCA jcaPort,
125         WSIFProviderJCAExtensions aFactory,
126         Connection aConnection,
127         InteractionSpec aInteractionSpec) {
128
129         super();
130         this.fieldDefinition = aDefinition;
131         this.fieldInteractionSpec = aInteractionSpec;
132         this.fieldConnection = aConnection;
133         this.fieldFactory = aFactory;
134         this.fieldBinding = aPort.getBinding();
135         this.fieldOperationName = aOperationName;
136         this.fieldInputName = aInputName;
137         this.fieldOutputName = aOutputName;
138         this.fieldTypeMap = typeMap;
139         this.fieldPort = aPort;
140         this.fieldService = aService;
141         this.fieldJcaPort = jcaPort;
142     }
143
144     /**
145      * Invokes the request/response operation. This method
146      * <ul>
147      * <li>Updates the InteractionSpec using data from the input message.
148      * <li>If a Connection is not currently available creates one, where a
149      * ConnectionSpec can be created using data from the input message and then
150      * used when creating the Connection.
151      * <li>Uses the Connection to create a javax.resource.cci.Interaction.
152      * <li>Invokes the Interaction execute method.
153      * <li>Closes the interaction.
154      * <li>Updates the output message with InteractionSpec properties.
155      * </ul>
156      */

157     public boolean executeRequestResponseOperation(WSIFMessage input, WSIFMessage output, WSIFMessage fault) throws WSIFException {
158
159         Trc.entry(this, input, output, fault);
160         if (!input.getParts().hasNext())
161             input = null;
162         try {
163             fieldFactory.updateInteractionSpec(input, fieldBinding, fieldOperationName, fieldInputName, fieldOutputName, fieldInteractionSpec);
164             if (this.fieldConnection == null){
165                 this.fieldConnection = this.fieldFactory.createConnection(input, this.fieldDefinition, this.fieldService, this.fieldPort, this.fieldTypeMap, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
166                 fieldJcaPort.setConnection(fieldConnection);
167             }
168             Interaction interaction = this.fieldConnection.createInteraction();
169             interaction.execute(this.fieldInteractionSpec, (javax.resource.cci.Record JavaDoc) input, (javax.resource.cci.Record JavaDoc) output);
170             interaction.close();
171             if (output instanceof WSIFMessage_JCA) {
172                 ((WSIFMessage_JCA) output).setInteractionSpec(this.fieldInteractionSpec);
173             }
174             fieldFactory.updateOutputMessage(output, fieldBinding, fieldOperationName, fieldInputName, fieldOutputName, fieldInteractionSpec);
175         }
176         catch (ResourceException exn1) {
177             WSIFException newExn = new WSIFException(WSIFResource_JCA.get("WSIF1000E"));
178             newExn.setTargetException(exn1);
179             Trc.exception(exn1);
180             throw newExn;
181         }
182         catch (Throwable JavaDoc exn3) {
183             WSIFException newExn = new WSIFException(WSIFResource_JCA.get("WSIF1008E", exn3.getLocalizedMessage()));
184             newExn.setTargetException(exn3);
185             Trc.exception(newExn);
186             throw newExn;
187         }
188         Trc.exit();
189         return true;
190     }
191
192     /**
193      * Invokes input only operation. This method
194      * <ul>
195      * <li>Updates the InteractionSpec using data from the input message.
196      * <li>If a Connection is not currently available creates one, where a
197      * ConnectionSpec can be created using data from the input message and then
198      * used when creating the Connection.
199      * <li>Uses the Connection to create a javax.resource.cci.Interaction.
200      * <li>Invokes the Interaction execute method.
201      * <li>Closes the interaction.
202      * </ul>
203      */

204     public void executeInputOnlyOperation(WSIFMessage input) throws WSIFException {
205
206         Trc.entry(this, input);
207         if (!input.getParts().hasNext())
208             input = null;
209         try {
210             fieldFactory.updateInteractionSpec(input, fieldBinding, fieldOperationName, fieldInputName, fieldOutputName, fieldInteractionSpec);
211             if (fieldConnection == null){
212                 fieldConnection = this.fieldFactory.createConnection(input, this.fieldDefinition, this.fieldService, this.fieldPort, this.fieldTypeMap, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
213                 fieldJcaPort.setConnection(fieldConnection);
214             }
215             Interaction interaction = fieldConnection.createInteraction();
216             interaction.execute(fieldInteractionSpec, (javax.resource.cci.Record JavaDoc) input);
217             interaction.close();
218         }
219         catch (ResourceException exn1) {
220             WSIFException newExn = new WSIFException(WSIFResource_JCA.get("WSIF1000E"));
221             Trc.exception(exn1);
222             newExn.setTargetException(exn1);
223             throw newExn;
224         }
225         catch (Throwable JavaDoc exn3) {
226             WSIFException newExn = new WSIFException(WSIFResource_JCA.get("WSIF1008E", exn3.getLocalizedMessage()));
227             newExn.setTargetException(exn3);
228             Trc.exception(newExn);
229             throw newExn;
230         }
231         Trc.exit();
232     }
233
234     /**
235      * This method creates the fault message. It first attempts to use Resource Adapter specific class
236      * to create the message. If this fails (i.e. the Resource Adapter does not require specialized messages),
237      * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
238      */

239     
240     public WSIFMessage createFaultMessage() {
241
242         Trc.entry(this);
243         WSIFMessage message = this.fieldFactory.createFaultMessage(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
244         if (message != null)
245             return message;
246         return new WSIFMessage_JCAStreamable(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName, WSIFMessage_JCA.FAULT_MESSAGE);
247     }
248
249     /**
250      * This method creates the fault message with specific name. It first attempts to use Resource Adapter specific class
251      * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
252      * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
253      */

254     public WSIFMessage createFaultMessage(String JavaDoc name) {
255
256         Trc.entry(this, name);
257
258         WSIFMessage message = this.fieldFactory.createFaultMessage(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
259         if (message != null) {
260             message.setName(name);
261             return message;
262         }
263         message = new WSIFMessage_JCAStreamable(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName, WSIFMessage_JCA.FAULT_MESSAGE);
264         message.setName(name);
265         return message;
266     }
267
268     /**
269      * This method creates the input message. It first attempts to use Resource Adapter specific class
270      * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
271      * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
272      */

273     public WSIFMessage createInputMessage() {
274
275         Trc.entry(this);
276         WSIFMessage message = this.fieldFactory.createInputMessage(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
277         if (message != null)
278             return message;
279         return new WSIFMessage_JCAStreamable(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName, WSIFMessage_JCA.INPUT_MESSAGE);
280     }
281
282     /**
283      * This method creates the input message with specific name. It first attempts to use Resource Adapter specific class
284      * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
285      * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
286      */

287     public WSIFMessage createInputMessage(String JavaDoc name) {
288
289         Trc.entry(this, name);
290         WSIFMessage message = this.fieldFactory.createInputMessage(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
291         if (message != null) {
292             message.setName(name);
293             return message;
294         }
295         message = new WSIFMessage_JCAStreamable(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName, WSIFMessage_JCA.INPUT_MESSAGE);
296         message.setName(name);
297         return message;
298     }
299
300     /**
301      * This method creates the output message. It first attempts to use Resource Adapter specific class
302      * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
303      * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
304      */

305     public WSIFMessage createOutputMessage() {
306
307         Trc.entry(this);
308         WSIFMessage message = this.fieldFactory.createOutputMessage(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
309         if (message != null)
310             return message;
311         return new WSIFMessage_JCAStreamable(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName, WSIFMessage_JCA.OUTPUT_MESSAGE);
312     }
313
314     /**
315      * This method creates the output message with specific name. It first attempts to use Resource Adapter specific class
316      * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
317      * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
318      */

319     public WSIFMessage createOutputMessage(String JavaDoc name) {
320
321         Trc.entry(this, name);
322         WSIFMessage message = this.fieldFactory.createOutputMessage(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName);
323         if (message != null) {
324             message.setName(name);
325             return message;
326         }
327         message = new WSIFMessage_JCAStreamable(this.fieldDefinition, this.fieldBinding, this.fieldOperationName, this.fieldInputName, this.fieldOutputName, WSIFMessage_JCA.OUTPUT_MESSAGE);
328         message.setName(name);
329         return message;
330     }
331
332     /**
333      * Returns the interactionSpec.
334      * @return Returns a InteractionSpec
335      */

336     public InteractionSpec getInteractionSpec() {
337         return fieldInteractionSpec;
338     }
339
340     /**
341      * Sets the interactionSpec.
342      * @param interactionSpec The interactionSpec to set
343      */

344     public void setInteractionSpec(InteractionSpec interactionSpec) {
345         fieldInteractionSpec = interactionSpec;
346     }
347
348     public String JavaDoc toString() {
349
350         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
351         buffer.append(crlf + "[JCAOperation" + crlf);
352         try {
353             if (fieldConnection != null)
354                 buffer.append("\tConnection: " + fieldConnection.toString() + crlf);
355             else
356                 buffer.append("\tConnection: null" + crlf);
357
358             if (fieldInteractionSpec != null)
359                 buffer.append("\tInteractionSpec: " + fieldInteractionSpec.toString() + crlf);
360             else
361                 buffer.append("\tInteractionSpec: null" + crlf);
362
363             if (fieldBinding != null)
364                 buffer.append("\tBinding: " + fieldBinding.toString() + crlf);
365             else
366                 buffer.append("\tBinding: null" + crlf);
367
368             if (fieldOperation != null)
369                 buffer.append("\tOperation: " + fieldOperation.toString() + crlf);
370             else
371                 buffer.append("\tOperation: null" + crlf);
372
373             if (fieldFactory != null)
374                 buffer.append("\tFactory: " + fieldFactory.toString() + crlf);
375             else
376                 buffer.append("\tFactory: null" + crlf);
377
378             if (fieldOperationName != null)
379                 buffer.append("\tOperationName: " + fieldOperationName + crlf);
380             else
381                 buffer.append("\tOperationName: null" + crlf);
382
383             if (fieldInputName != null)
384                 buffer.append("\tInputName: " + fieldInputName + crlf);
385             else
386                 buffer.append("\tInputName: null" + crlf);
387
388             if (fieldOutputName != null)
389                 buffer.append("\tOutputName: " + fieldOutputName + crlf);
390             else
391                 buffer.append("\tOutputName: null" + crlf);
392
393             buffer.append("]" + crlf);
394         }
395         catch (Throwable JavaDoc exn) {
396         }
397         return buffer.toString();
398     }
399
400     /**
401      * Method not supported.
402      */

403     public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage input, WSIFResponseHandler handler) throws WSIFException {
404         return null;
405     }
406
407     /**
408      * Method not supported.
409      */

410     public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage input) throws WSIFException {
411         return null;
412     }
413
414     /**
415      * Method not supported.
416      */

417     public void fireAsyncResponse(Object JavaDoc response) throws WSIFException {
418         
419     }
420     /**
421      * Method not supported.
422      */

423     public boolean processAsyncResponse(Object JavaDoc response, WSIFMessage output, WSIFMessage fault) throws WSIFException {
424         return false;
425     }
426
427     /**
428      * Method not supported.
429      */

430     public void setContext(WSIFMessage context) {
431
432     }
433
434     /**
435      * Method not supported.
436      */

437     public WSIFMessage getContext() {
438
439         return null;
440     }
441
442 }
Popular Tags