KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > jms > WSIFPort_Jms


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 org.apache.wsif.providers.jms;
59
60 import java.io.Serializable JavaDoc;
61 import java.util.HashMap JavaDoc;
62 import java.util.Iterator JavaDoc;
63 import java.util.Map JavaDoc;
64
65 import javax.wsdl.BindingOperation;
66 import javax.wsdl.Definition;
67 import javax.wsdl.Port;
68 import javax.wsdl.extensions.ExtensibilityElement;
69
70 import org.apache.wsif.WSIFException;
71 import org.apache.wsif.WSIFOperation;
72 import org.apache.wsif.base.WSIFDefaultPort;
73 import org.apache.wsif.format.WSIFFormatter;
74 import org.apache.wsif.logging.Trc;
75 import org.apache.wsif.providers.WSIFDynamicTypeMap;
76 import org.apache.wsif.util.WSIFProperties;
77 import org.apache.wsif.util.WSIFUtils;
78 import org.apache.wsif.util.jms.WSIFJMSDestination;
79 import org.apache.wsif.util.jms.WSIFJMSFinder;
80 import org.apache.wsif.wsdl.extensions.jms.JMSAddress;
81
82 /**
83  * Jms WSIF port
84  *
85  * @author <a HREF="mailto:ake@de.ibm.com">Hermann Akermann</a>
86  * @author <a HREF="mailto:antelder@apache.org">Ant Elder</a>
87  * @author <a HREF="mailto:seto@ca.ibm.com">Norman Seto</a>
88  */

89 public class WSIFPort_Jms extends WSIFDefaultPort implements Serializable JavaDoc {
90
91     private static final long serialVersionUID = 1L;
92
93     private Definition fieldDefinition = null;
94     private Port fieldPortModel = null;
95     private JMSAddress fieldObjectReference = null; // 'physical connection'
96

97     protected Map JavaDoc operationInstances = new HashMap JavaDoc();
98     transient private WSIFJMSDestination jmsDest;
99
100     /**
101      * ctor
102      */

103     public WSIFPort_Jms(
104         Definition def,
105         Port port,
106         WSIFDynamicTypeMap typeMap) throws WSIFException {
107         Trc.entry(this, def, port, typeMap);
108
109         fieldDefinition = def;
110         fieldPortModel = port;
111
112         if (Trc.ON)
113             Trc.exit(deep());
114     }
115
116     /**
117      * @see WSIFPort#createOperation(String)
118      */

119     public WSIFOperation createOperation(String JavaDoc operationName)
120         throws WSIFException {
121         Trc.entry(this, operationName);
122         WSIFOperation wo = createOperation(operationName, null, null);
123         Trc.exit(wo);
124         return wo;
125     }
126
127     /**
128      * @see WSIFPort#createOperation(String, String, String)
129      */

130     public WSIFOperation createOperation(
131         String JavaDoc operationName,
132         String JavaDoc inputName,
133         String JavaDoc outputName)
134         throws WSIFException {
135         Trc.entry(this, operationName, inputName, outputName);
136
137         WSIFOperation_Jms op =
138             getDynamicWSIFOperation(operationName, inputName, outputName);
139         if (op == null) {
140             throw new WSIFException(
141                 "Could not create operation: "
142                     + operationName
143                     + ":"
144                     + inputName
145                     + ":"
146                     + outputName);
147         }
148         WSIFOperation wo = op.copy();
149         Trc.exit(wo);
150         return wo;
151     }
152
153     /**
154      * get/set WSIF operation
155      */

156     public WSIFOperation_Jms getDynamicWSIFOperation(
157         String JavaDoc name,
158         String JavaDoc inputName,
159         String JavaDoc outputName)
160         throws WSIFException {
161         Trc.entry(this, name, inputName, outputName);
162
163         WSIFOperation_Jms tempOp =
164             (WSIFOperation_Jms) operationInstances.get(getKey(name, inputName, outputName));
165
166         WSIFOperation_Jms operation = null;
167         if (tempOp != null) {
168             operation = tempOp.copy();
169         }
170         
171         if (operation == null) {
172             BindingOperation bindingOperationModel =
173                WSIFUtils.getBindingOperation(
174                   fieldPortModel.getBinding(), name, inputName, outputName );
175
176             if (bindingOperationModel != null) {
177                 operation =
178                     new WSIFOperation_Jms(
179                         fieldPortModel,
180                         bindingOperationModel,
181                         this);
182                 setDynamicWSIFOperation(name, inputName, outputName, operation);
183             }
184         }
185
186         Trc.exit(operation);
187         return operation;
188     }
189
190     // WSIF: keep list of operations available in this port
191
public void setDynamicWSIFOperation(
192         String JavaDoc name,
193         String JavaDoc inputName,
194         String JavaDoc outputName,
195         WSIFOperation_Jms value) {
196         Trc.entry(this, name, inputName, outputName);
197
198         operationInstances.put(getKey(name, inputName, outputName), value);
199         Trc.exit();
200     }
201
202     /**
203      * Tests if this port supports asynchronous/synchronous
204      * calls to operations.
205      *
206      */

207     public boolean supportsSync() {
208         Trc.entry(this);
209         Trc.exit(true);
210         return true;
211     }
212
213     public boolean supportsAsync() {
214         Trc.entry(this);
215         Trc.exit(true);
216         return true;
217     }
218
219     /**
220      * accessor/mutators
221      */

222     public Definition getDefinition() {
223         Trc.entry(this);
224         Trc.exit(fieldDefinition);
225         return fieldDefinition;
226     }
227
228     public void setDefinition(Definition value) {
229         Trc.entry(this, value);
230         fieldDefinition = value;
231         Trc.exit();
232     }
233
234     public Port getPortModel() {
235         Trc.entry(this);
236         Trc.exit(fieldPortModel);
237         return fieldPortModel;
238     }
239
240     public void setPortModel(Port value) {
241         Trc.entry(this, value);
242         fieldPortModel = value;
243         Trc.exit();
244     }
245
246     public JMSAddress getObjectReference() throws WSIFException {
247         Trc.entry(this);
248         if (fieldObjectReference == null) {
249
250             try {
251                 ExtensibilityElement portExtension =
252                     (ExtensibilityElement) fieldPortModel.getExtensibilityElements().get(0);
253
254                 if (portExtension == null) {
255                     throw new WSIFException("Jms missing port extension");
256                 }
257
258                 fieldObjectReference = (JMSAddress) portExtension;
259
260             } catch (Exception JavaDoc ex) {
261                 Trc.exception(ex);
262                 throw new WSIFException(
263                     "Could not create object of class '???todo??? " + "'",
264                     ex);
265             }
266         }
267         Trc.exit(fieldObjectReference);
268         return fieldObjectReference;
269     }
270
271     public void setObjectReference(JMSAddress newObjectReference) {
272         Trc.entry(this, newObjectReference);
273         fieldObjectReference = newObjectReference;
274         Trc.exit();
275     }
276
277     public WSIFFormatter getFormatter() {
278         Trc.entry(this);
279         WSIFFormatter wf = new JMSFormatter(fieldDefinition, fieldPortModel);
280         Trc.exit(wf);
281         return wf;
282     }
283
284     /**
285      * Returns the jmsDestination for this WSIFPort.
286      * @return WSIFJMSDestination
287      */

288     public WSIFJMSDestination getJmsDestination() throws WSIFException {
289         if (jmsDest==null) {
290            jmsDest =
291               new WSIFJMSDestination(
292                  WSIFJMSFinder.newFinder(
293                     getObjectReference(),
294                     fieldPortModel.getName()),
295               getObjectReference().getJmsProvDestName(),
296               WSIFProperties.getSyncTimeout());
297         }
298         return jmsDest;
299     }
300
301     /**
302      * Closes the port. All methods are invalid after calling this method.
303      */

304     public void close() throws WSIFException {
305         Trc.entry(this);
306         if (jmsDest != null) {
307             jmsDest.close();
308         }
309         Trc.exit();
310     }
311
312     /**
313      * helper
314      */

315     public String JavaDoc deep() {
316         String JavaDoc buff = "";
317         try {
318             buff = new String JavaDoc(super.toString() + ":\n");
319
320             buff += "definition:" + Trc.brief(fieldDefinition);
321             buff += " portModel:" + Trc.brief(fieldPortModel);
322             buff += " objectReference:" + fieldObjectReference;
323
324             buff += " operationInstances: ";
325             if (operationInstances == null)
326                 buff += "null";
327             else {
328                 buff += "size:" + operationInstances.size();
329                 Iterator JavaDoc it = operationInstances.keySet().iterator();
330                 int i = 0;
331                 while (it.hasNext()) {
332                     String JavaDoc key = (String JavaDoc) it.next();
333                     WSIFOperation_Jms woj = (WSIFOperation_Jms) operationInstances.get(key);
334                     buff += "\noperationInstances[" + i + "]:" + key + " " + woj + " ";
335                     i++;
336                 }
337             }
338         } catch (Exception JavaDoc e) {
339             Trc.exceptionInTrace(e);
340         }
341         return buff;
342     }
343
344 }
Popular Tags