KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > jca > WSIFPort_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
58
59 package org.apache.wsif.providers.jca;
60
61 import org.apache.wsif.logging.*;
62 import org.apache.wsif.providers.*;
63 import org.apache.wsif.*;
64 import org.apache.wsif.base.*;
65 import org.apache.wsif.util.*;
66
67 import javax.resource.*;
68 import javax.resource.cci.*;
69 import javax.wsdl.extensions.*;
70 import javax.wsdl.*;
71
72 import java.net.URL JavaDoc;
73 import java.util.*;
74
75 /**
76  * The WSIFPort_JCA class is a connector architecture specific implementation of WSIFPort.
77  * This port has a handle to resource adapter connection, and is used to create WSIFOperation.
78  *
79  * @author Michael Beisiegel
80  * @author Piotr Przybylski <piotrp@ca.ibm.com>
81  */

82 public class WSIFPort_JCA extends WSIFDefaultPort {
83
84     private static final long serialVersionUID = 1L;
85     private Connection fieldConnection;
86     private Port fieldPort;
87     private Definition fieldDefinition;
88     private Service fieldService;
89     private WSIFProviderJCAExtensions fieldFactory;
90     private final static String JavaDoc crlf = System.getProperty("line.separator");
91     protected Map operationInstances = new HashMap();
92     private org.apache.wsif.providers.WSIFDynamicTypeMap fieldTypeMap;
93     
94     
95     /**
96      * Constructor for WSIFPort_JCA.
97      * @param aDefinition
98      * @param aService
99      * @param aPort
100      * @param aConnection
101      * @param aFactory
102      * @param typeMap
103      */

104     public WSIFPort_JCA(Definition aDefinition, Service aService, Port aPort, Connection aConnection, WSIFProviderJCAExtensions aFactory, org.apache.wsif.providers.WSIFDynamicTypeMap typeMap) {
105
106         super();
107         this.fieldDefinition = aDefinition;
108         this.fieldService = aService;
109         this.fieldPort = aPort;
110         this.fieldConnection = aConnection;
111         this.fieldFactory = aFactory;
112         this.fieldTypeMap = typeMap;
113     }
114
115     private void addOperation(String JavaDoc name, String JavaDoc inputName, String JavaDoc outputName, WSIFOperation value) {
116         operationInstances.put(getKey(name, inputName, outputName), value);
117     }
118
119     /**
120      * This method creates WSIFOperation_JCA using the configured, Resource Adapter specific
121      * factory (i.e. the implementor of <code>WSIFProviderJCAExtensions</code>).
122      * @see org.apache.wsif.WSIFPort#createOperation(String, String, String)
123      */

124     public WSIFOperation createOperation(String JavaDoc aOperationName, String JavaDoc aInputName, String JavaDoc aOutputName) throws WSIFException {
125         
126         Trc.entry(this);
127         WSIFOperation wsifOperation = getOperation(aOperationName, aInputName, aOutputName);
128         if (wsifOperation == null) {
129             wsifOperation = fieldFactory.createOperation(fieldDefinition, fieldService, fieldPort, aOperationName,
130                                                          aInputName, aOutputName, fieldTypeMap, this, fieldConnection);
131             addOperation(aOperationName, aInputName, aOutputName, wsifOperation);
132         }
133         Trc.exit(wsifOperation);
134         return wsifOperation;
135     }
136
137     /**
138      * Creates a WSIFOperation_JCA using the configured, Resource Adapter specific
139      * factory (i.e. the implementor of <code>WSIFProviderJCAExtensions</code>).
140      * @see org.apache.wsif.WSIFPort#createOperation(String)
141      */

142     public WSIFOperation createOperation(String JavaDoc aOperationName) throws WSIFException {
143
144         Trc.entry(this, aOperationName);
145
146         WSIFOperation wsifOperation = getOperation(aOperationName, null, null);
147         if (wsifOperation == null) {
148             wsifOperation = fieldFactory.createOperation(fieldDefinition, fieldService, fieldPort, aOperationName,
149                                                          null, null, fieldTypeMap, this, fieldConnection);
150
151             addOperation(aOperationName, null, null, wsifOperation);
152         }
153         Trc.exit(wsifOperation);
154         return wsifOperation;
155     }
156
157     /**
158      * Closes the javax.resource.cci.Connection associated with this port.
159      *
160      * @see org.apache.wsif.WSIFPort#close()
161      */

162     public void close() {
163         try {
164             if(this.fieldConnection != null)
165                 this.fieldConnection.close();
166         }
167         catch (ResourceException exn) {
168         }
169     }
170
171     private WSIFOperation_JCA getOperation(String JavaDoc name, String JavaDoc inputName, String JavaDoc outputName) {
172
173         return (WSIFOperation_JCA) operationInstances.get(getKey(name, inputName, outputName));
174
175     }
176
177     public String JavaDoc toString() {
178
179         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
180         buffer.append(crlf + "[WSIFPort_JCA" + crlf);
181         try {
182             if (fieldConnection != null)
183                 buffer.append("\tConnection: " + fieldConnection.toString() + crlf);
184             else
185                 buffer.append("\tConnection: null" + crlf);
186
187             if (fieldPort != null)
188                 buffer.append("\tPort: " + fieldPort.toString() + crlf);
189             else
190                 buffer.append("\tPort: null" + crlf);
191
192             if (fieldDefinition != null)
193                 buffer.append("\tDefinition: " + fieldDefinition.toString() + crlf);
194             else
195                 buffer.append("\tDefinition null" + crlf);
196
197             if (fieldService != null)
198                 buffer.append("\tService: " + fieldService.toString() + crlf);
199             else
200                 buffer.append("\tService: null" + crlf);
201
202             if (fieldFactory != null)
203                 buffer.append("\tFactory: " + fieldFactory.toString() + crlf);
204             else
205                 buffer.append("\tFactory: null" + crlf);
206             buffer.append("]" + crlf);
207         }
208         catch (Throwable JavaDoc exn) {
209         }
210         return buffer.toString();
211     }
212     /**
213      * Sets the javax.resource.cci.Connection associated with this port.
214      * @param connection The connection to set
215      */

216     void setConnection(Connection connection) {
217         fieldConnection = connection;
218     }
219
220 }
Popular Tags