KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > base > WSIFDefaultPort


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.base;
59
60 import java.util.ArrayList JavaDoc;
61 import java.util.Iterator JavaDoc;
62 import java.util.List JavaDoc;
63
64 import org.apache.wsif.WSIFException;
65 import org.apache.wsif.WSIFConstants;
66 import org.apache.wsif.WSIFMessage;
67 import org.apache.wsif.WSIFPort;
68 import org.apache.wsif.logging.Trc;
69
70 /**
71  * A DefaultWSIFPort is a default implementation of WSIFPort
72  * all methods are implemented except execute*.
73  *
74  * @author Paul Fremantle
75  * @author Alekander Slominski
76  * @author Matthew J. Duftler
77  * @author Sanjiva Weerawarana
78  * @author Nirmal Mukhi
79  */

80 public abstract class WSIFDefaultPort implements WSIFPort {
81     private static final long serialVersionUID = 1L;
82     
83     private WSIFMessage context;
84
85     public void close() throws WSIFException {
86         Trc.entry(this);
87         Trc.exit();
88     }
89
90     public void finalize() throws Throwable JavaDoc {
91         Trc.entry(this);
92         try {
93             close();
94         } catch (WSIFException ex) {
95             Trc.ignoredException( ex );
96         }
97         super.finalize();
98         Trc.exit();
99     }
100   
101     /**
102      * Utility method to return key suitable for hash table.
103      */

104     protected String JavaDoc getKey(String JavaDoc name, String JavaDoc inputName, String JavaDoc outputName) {
105         Trc.entry(this, name, inputName, outputName);
106         String JavaDoc s =
107             name
108                 + (inputName != null ? ":" + inputName : "")
109                 + (outputName != null ? ":" + outputName : "");
110         Trc.exit(s);
111         return s;
112     }
113
114     /**
115      * Utility method to retrieve extensibility element from list
116      * checks also that it is exactly one extensibility element.
117      */

118     protected Object JavaDoc getExtElem(Object JavaDoc ctx, Class JavaDoc extType, List JavaDoc extElems)
119         throws WSIFException {
120         Trc.entry(this, ctx, extType, extElems);
121
122         Object JavaDoc found = null;
123         if (extElems != null) {
124             for (Iterator JavaDoc i = extElems.iterator(); i.hasNext();) {
125                 // if so return new
126
Object JavaDoc o = i.next();
127                 if (extType.isAssignableFrom(o.getClass())) {
128                     if (found != null) {
129                         throw new WSIFException(
130                             "duplicated extensibility element "
131                                 + extType.getClass().getName()
132                                 + " in "
133                                 + ctx);
134                     }
135                     found = o;
136                 }
137             }
138         }
139         Trc.exit(found);
140         return found;
141     }
142
143     /**
144      * Utility method to retrieve multiple extensibility elements from a list.
145      */

146     protected List JavaDoc getExtElems(Object JavaDoc ctx, Class JavaDoc extType, List JavaDoc extElems)
147         throws WSIFException {
148         Trc.entry(this, ctx, extType, extElems);
149         List JavaDoc found = new ArrayList JavaDoc();
150         if (extElems != null)
151             for (Iterator JavaDoc i = extElems.iterator(); i.hasNext();) {
152                 Object JavaDoc o = i.next();
153                 if (extType.isAssignableFrom(o.getClass()))
154                     found.add(o);
155             }
156         if (found.size() == 0)
157             return null;
158         Trc.exit(found);
159         return found;
160     }
161
162     /**
163      * Tests if this port supports synchronous calls to operations.
164      *
165      * @return true by default WSIFPorts do support synchronous calls
166      */

167     public boolean supportsSync() {
168         Trc.entry(this);
169         Trc.exit(true);
170         return true;
171     }
172
173     /**
174      * Tests if this port supports asynchronous calls to operations.
175      *
176      * @return false by default ports do not support asynchronous calls
177      */

178     public boolean supportsAsync() {
179         Trc.entry(this);
180         Trc.exit(false);
181         return false;
182     }
183
184     /**
185      * Gets the context information for this WSIFPort.
186      * @return context
187      */

188     public WSIFMessage getContext() throws WSIFException {
189         Trc.entry(this);
190         WSIFMessage contextCopy;
191         if (this.context == null) {
192             // really this should call getContext on the WSIFService but
193
// theres no reference to that so WSIFService must call setContext
194
// on any WSIFPorts it creates.
195
contextCopy = new WSIFDefaultMessage();
196         } else {
197             try {
198                 contextCopy = (WSIFMessage) this.context.clone();
199             } catch (CloneNotSupportedException JavaDoc e) {
200                 throw new WSIFException(
201                     "CloneNotSupportedException cloning context", e);
202             }
203         }
204         Trc.exit(contextCopy);
205         return contextCopy;
206     }
207
208     /**
209      * Sets the context information for this WSIFPort.
210      * @param WSIFMessage the new context information
211      */

212     public void setContext(WSIFMessage context) {
213         Trc.entry(this, context);
214         if (context == null) {
215             throw new IllegalArgumentException JavaDoc("context must not be null");
216         }
217         this.context = context;
218         Trc.exit(null);
219     }
220
221 }
Popular Tags