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.jca;
059:
060: import org.apache.wsif.logging.*;
061: import org.apache.wsif.providers.*;
062: import org.apache.wsif.*;
063: import org.apache.wsif.base.*;
064: import org.apache.wsif.util.*;
065:
066: import javax.resource.*;
067: import javax.resource.cci.*;
068: import javax.wsdl.extensions.*;
069: import javax.wsdl.*;
070:
071: import java.net.URL;
072: import java.util.*;
073:
074: /**
075: * The WSIFPort_JCA class is a connector architecture specific implementation of WSIFPort.
076: * This port has a handle to resource adapter connection, and is used to create WSIFOperation.
077: *
078: * @author Michael Beisiegel
079: * @author Piotr Przybylski <piotrp@ca.ibm.com>
080: */
081: public class WSIFPort_JCA extends WSIFDefaultPort {
082:
083: private static final long serialVersionUID = 1L;
084: private Connection fieldConnection;
085: private Port fieldPort;
086: private Definition fieldDefinition;
087: private Service fieldService;
088: private WSIFProviderJCAExtensions fieldFactory;
089: private final static String crlf = System
090: .getProperty("line.separator");
091: protected Map operationInstances = new HashMap();
092: private org.apache.wsif.providers.WSIFDynamicTypeMap fieldTypeMap;
093:
094: /**
095: * Constructor for WSIFPort_JCA.
096: * @param aDefinition
097: * @param aService
098: * @param aPort
099: * @param aConnection
100: * @param aFactory
101: * @param typeMap
102: */
103: public WSIFPort_JCA(Definition aDefinition, Service aService,
104: Port aPort, Connection aConnection,
105: WSIFProviderJCAExtensions aFactory,
106: org.apache.wsif.providers.WSIFDynamicTypeMap typeMap) {
107:
108: super ();
109: this .fieldDefinition = aDefinition;
110: this .fieldService = aService;
111: this .fieldPort = aPort;
112: this .fieldConnection = aConnection;
113: this .fieldFactory = aFactory;
114: this .fieldTypeMap = typeMap;
115: }
116:
117: private void addOperation(String name, String inputName,
118: String outputName, WSIFOperation value) {
119: operationInstances.put(getKey(name, inputName, outputName),
120: value);
121: }
122:
123: /**
124: * This method creates WSIFOperation_JCA using the configured, Resource Adapter specific
125: * factory (i.e. the implementor of <code>WSIFProviderJCAExtensions</code>).
126: * @see org.apache.wsif.WSIFPort#createOperation(String, String, String)
127: */
128: public WSIFOperation createOperation(String aOperationName,
129: String aInputName, String aOutputName) throws WSIFException {
130:
131: Trc.entry(this );
132: WSIFOperation wsifOperation = getOperation(aOperationName,
133: aInputName, aOutputName);
134: if (wsifOperation == null) {
135: wsifOperation = fieldFactory.createOperation(
136: fieldDefinition, fieldService, fieldPort,
137: aOperationName, aInputName, aOutputName,
138: fieldTypeMap, this , fieldConnection);
139: addOperation(aOperationName, aInputName, aOutputName,
140: wsifOperation);
141: }
142: Trc.exit(wsifOperation);
143: return wsifOperation;
144: }
145:
146: /**
147: * Creates a WSIFOperation_JCA using the configured, Resource Adapter specific
148: * factory (i.e. the implementor of <code>WSIFProviderJCAExtensions</code>).
149: * @see org.apache.wsif.WSIFPort#createOperation(String)
150: */
151: public WSIFOperation createOperation(String aOperationName)
152: throws WSIFException {
153:
154: Trc.entry(this , aOperationName);
155:
156: WSIFOperation wsifOperation = getOperation(aOperationName,
157: null, null);
158: if (wsifOperation == null) {
159: wsifOperation = fieldFactory.createOperation(
160: fieldDefinition, fieldService, fieldPort,
161: aOperationName, null, null, fieldTypeMap, this ,
162: fieldConnection);
163:
164: addOperation(aOperationName, null, null, wsifOperation);
165: }
166: Trc.exit(wsifOperation);
167: return wsifOperation;
168: }
169:
170: /**
171: * Closes the javax.resource.cci.Connection associated with this port.
172: *
173: * @see org.apache.wsif.WSIFPort#close()
174: */
175: public void close() {
176: try {
177: if (this .fieldConnection != null)
178: this .fieldConnection.close();
179: } catch (ResourceException exn) {
180: }
181: }
182:
183: private WSIFOperation_JCA getOperation(String name,
184: String inputName, String outputName) {
185:
186: return (WSIFOperation_JCA) operationInstances.get(getKey(name,
187: inputName, outputName));
188:
189: }
190:
191: public String toString() {
192:
193: StringBuffer buffer = new StringBuffer();
194: buffer.append(crlf + "[WSIFPort_JCA" + crlf);
195: try {
196: if (fieldConnection != null)
197: buffer.append("\tConnection: "
198: + fieldConnection.toString() + crlf);
199: else
200: buffer.append("\tConnection: null" + crlf);
201:
202: if (fieldPort != null)
203: buffer.append("\tPort: " + fieldPort.toString()
204: + crlf);
205: else
206: buffer.append("\tPort: null" + crlf);
207:
208: if (fieldDefinition != null)
209: buffer.append("\tDefinition: "
210: + fieldDefinition.toString() + crlf);
211: else
212: buffer.append("\tDefinition null" + crlf);
213:
214: if (fieldService != null)
215: buffer.append("\tService: "
216: + fieldService.toString() + crlf);
217: else
218: buffer.append("\tService: null" + crlf);
219:
220: if (fieldFactory != null)
221: buffer.append("\tFactory: "
222: + fieldFactory.toString() + crlf);
223: else
224: buffer.append("\tFactory: null" + crlf);
225: buffer.append("]" + crlf);
226: } catch (Throwable exn) {
227: }
228: return buffer.toString();
229: }
230:
231: /**
232: * Sets the javax.resource.cci.Connection associated with this port.
233: * @param connection The connection to set
234: */
235: void setConnection(Connection connection) {
236: fieldConnection = connection;
237: }
238:
239: }
|