KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > jca > toolplugin > Import


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.toolplugin;
58
59 import java.util.Arrays JavaDoc;
60 import java.util.Iterator JavaDoc;
61 import java.util.Map JavaDoc;
62
63 import javax.wsdl.Definition;
64 import javax.wsdl.Operation;
65 import javax.wsdl.PortType;
66 import javax.wsdl.Service;
67 import javax.xml.namespace.QName JavaDoc;
68
69 import org.apache.wsif.WSIFException;
70 import org.apache.wsif.WSIFMessage;
71 import org.apache.wsif.WSIFOperation;
72 import org.apache.wsif.WSIFPort;
73 import org.apache.wsif.WSIFService;
74 import org.apache.wsif.WSIFServiceFactory;
75
76 /**
77  * This class is a default implementation proxy for the Operations of the Import Service. Tooling environments can extend this class and customize
78  * its behaviour. It is provided as a default implementation of how to invoke the various operations that are defined in the Import Service archictecture.
79  *
80  * @author Hesham Fahmy <hfahmy@ca.ibm.com>
81  */

82 public abstract class Import {
83
84     private static final long serialVersionUID = 1L;
85     /*The WSDL Definition that is providing the implementation of the Import Service*/
86     private Definition serviceDefintion = null;
87     /*The WSDL Service that is providing the implementation of the Import Service*/
88     private Service importService = null;
89     /*The WSDL PortType that is providing the implementation of the Import Service*/
90     private PortType importPortType = null;
91
92
93     /*Constants that represent standard values of any Import Service implementation*/
94     public static final String JavaDoc IMPORT_SERVICE_BASE_NAMESPACE = "http://importservice.jca.providers.wsif.apache.org/";
95     public static final String JavaDoc IMPORT_SERVICE_BASE_PORTTYPE_NAME = "Import";
96     
97     public static final String JavaDoc GET_PORTTYPES_OPERATION = "getPortTypes";
98     public static final String JavaDoc GET_DEFINITION_OPERATION = "getDefinition";
99     public static final String JavaDoc GET_RAW_EIS_METADATA_OPERATION = "getRawEISMetaData";
100
101     public static final String JavaDoc PORT_TYPE_SELECTION_PART = "portTypeSelection";
102     public static final String JavaDoc RESULT_PART = "result";
103     public static final String JavaDoc QUERY_STRING_PART = "queryString";
104
105     /**
106      * Default Constructor for <code>Import</code>.
107      */

108     public Import() {
109         super();
110     }
111
112     /**
113      * Constructor for <code>Import</code>. This constructor allows a WSDL definition, that defines a concrete implementation of
114      * the Import Service (i.e. by a particular EIS), to be passed in. In addition to the WSDL Defintion, the constructor needs the name of
115      * the WSDL Service, contained in the Definition, that provides the implementation of the Import Service.
116      * @param <code>aServiceDefinition</code> The WSDL Definition
117      * @param <code>aServiceName</code> The name of the Service
118      * @throws <code>WSIFException</code>
119      */

120     public Import(Definition aServiceDefinition, String JavaDoc aServiceName) throws WSIFException {
121         super();
122         try {
123             serviceDefintion = aServiceDefinition;
124             importPortType = serviceDefintion.getPortType(new QName JavaDoc(IMPORT_SERVICE_BASE_NAMESPACE, IMPORT_SERVICE_BASE_PORTTYPE_NAME));
125             importService = serviceDefintion.getService(new QName JavaDoc(serviceDefintion.getTargetNamespace(), aServiceName));
126         } catch (Exception JavaDoc e) {
127             if (e instanceof WSIFException)
128                 throw (WSIFException) e;
129             else
130                 throw new WSIFException(e.getMessage(), e);
131         }
132     }
133
134
135     /**
136      * This is the proxy method to invoke the <code>getPortTypes</code> Operation of the Import Service.
137      * @param <code>queryString</code> - The query string to be used
138      * @return <code>PortTypeArray</code>
139      * @throws <code>WSIFException</code>
140      */

141     public PortTypeArray getPortTypes(String JavaDoc queryString) throws WSIFException {
142         try {
143             WSIFService portFactory = WSIFServiceFactory.newInstance().getService(serviceDefintion, importService, importPortType);
144
145             WSIFPort port = portFactory.getPort();
146
147             WSIFOperation operation = port.createOperation(GET_PORTTYPES_OPERATION);
148             WSIFMessage inputMessage = operation.createInputMessage();
149             WSIFMessage outputMessage = operation.createOutputMessage();
150             inputMessage.setObjectPart(QUERY_STRING_PART, queryString);
151
152             operation.executeRequestResponseOperation(inputMessage, outputMessage, null);
153
154             PortTypeArray portTypeArray = (PortTypeArray) outputMessage.getObjectPart(RESULT_PART);
155
156             port.close();
157             return portTypeArray;
158         } catch (Exception JavaDoc e) {
159             if (e instanceof WSIFException)
160                 throw (WSIFException) e;
161             else
162                 throw new WSIFException(e.getMessage(), e);
163         }
164     }
165
166     /**
167      * This is the proxy method to invoke the <code>getDefinition</code> Operation of the Import Service.
168      * @param <code>portTypeSelection<code> - the <code>PortTypeSelection</code> to be used.
169      * @return <code>ImportDefinition</code>
170      * @throws <code>WSIFException<code>
171      */

172     public ImportDefinition getDefinition(PortTypeSelection portTypeSelection) throws WSIFException {
173         try {
174             WSIFService portFactory = WSIFServiceFactory.newInstance().getService(serviceDefintion, importService, importPortType);
175             WSIFPort port = portFactory.getPort();
176
177             WSIFOperation operation = port.createOperation(GET_DEFINITION_OPERATION);
178             WSIFMessage inputMessage = operation.createInputMessage();
179             WSIFMessage outputMessage = operation.createOutputMessage();
180
181             inputMessage.setObjectPart(PORT_TYPE_SELECTION_PART, portTypeSelection);
182
183             operation.executeRequestResponseOperation(inputMessage, outputMessage, null);
184
185             ImportDefinition importDefinition = (ImportDefinition) outputMessage.getObjectPart(RESULT_PART);
186             port.close();
187
188             return importDefinition;
189         } catch (Exception JavaDoc e) {
190             if (e instanceof WSIFException)
191                 throw (WSIFException) e;
192             else
193                 throw new WSIFException(e.getMessage(), e);
194         }
195
196     }
197
198     /**
199      * This is the proxy method to invoke the <code>getRawEISMetaData</code> Operation of the Import Service
200      * @param <code>queryString</code> - The query string to be used
201      * @return <code>byte[]</code>
202      * @throws <code>WSIFException</code>
203      */

204     public byte[] getRawEISMetaData(String JavaDoc queryString) throws WSIFException {
205         try {
206             WSIFService portFactory = WSIFServiceFactory.newInstance().getService(serviceDefintion, importService, importPortType);
207
208             WSIFPort port = portFactory.getPort();
209
210             // getPortTypes
211
WSIFOperation operation = port.createOperation(GET_RAW_EIS_METADATA_OPERATION);
212             WSIFMessage inputMessage = operation.createInputMessage();
213             WSIFMessage outputMessage = operation.createOutputMessage();
214             inputMessage.setObjectPart(QUERY_STRING_PART, queryString);
215
216             operation.executeRequestResponseOperation(inputMessage, outputMessage, null);
217
218             byte[] byteArray = (byte[]) outputMessage.getObjectPart(RESULT_PART);
219
220             port.close();
221             return byteArray;
222         } catch (Exception JavaDoc e) {
223             if (e instanceof WSIFException)
224                 throw (WSIFException) e;
225             else
226                 throw new WSIFException(e.getMessage(), e);
227
228         }
229     }
230
231     /**
232      * Returns the WSDL PortType for the Import Service
233      * @return <code>PortType</code>
234      */

235     public PortType getImportPortType() {
236         return importPortType;
237     }
238
239     /**
240      * Returns the WSDL Service for the Import Service
241      * @return <code>Service</code>
242      */

243     public Service getImportService() {
244         return importService;
245     }
246
247     /**
248      * Returns the WSDL Definition for the Import Service
249      * @return <code>Definition</code>
250      */

251     public Definition getServiceDefintion() {
252         return serviceDefintion;
253     }
254
255     /**
256      * Sets the WSDL PortType for the Import Service
257      * @param <code>importPortType</code> The PortType to set
258      */

259     public void setImportPortType(PortType importPortType) {
260         this.importPortType = importPortType;
261     }
262
263     /**
264      * Sets the the WSDL Service for the Import Service
265      * @param <code>importService</code> The Service to set
266      */

267     public void setImportService(Service importService) {
268         this.importService = importService;
269     }
270
271     /**
272      * Sets the WSDL Definition for the Import Service
273      * @param <code>serviceDefintion</code> The Defintion to set
274      */

275     public void setServiceDefintion(Definition serviceDefintion) {
276         this.serviceDefintion = serviceDefintion;
277     }
278
279 }
Popular Tags