KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > wsgen > generator > axis > VcPortComponent


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Xavier Delplanque
22  * --------------------------------------------------------------------------
23  * $Id: VcPortComponent.java,v 1.6 2004/07/01 14:55:17 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_ws.wsgen.generator.axis;
28
29 import java.lang.reflect.Method JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 import javax.wsdl.BindingFault;
35 import javax.wsdl.BindingOperation;
36 import javax.wsdl.Definition;
37 import javax.wsdl.Port;
38 import javax.wsdl.Service;
39 import javax.wsdl.extensions.ExtensibilityElement;
40 import javax.wsdl.extensions.soap.SOAPBinding;
41 import javax.wsdl.extensions.soap.SOAPBody;
42 import javax.wsdl.extensions.soap.SOAPFault;
43 import javax.wsdl.extensions.soap.SOAPOperation;
44 import javax.xml.namespace.QName JavaDoc;
45
46 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
47
48 import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
49
50 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
51 import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
52
53 /**
54  * Member of a VelocityContext. Contains information about a
55  * PortComponent(Desc/Ref).
56  * @author Xavier Delplanque
57  */

58 public class VcPortComponent {
59
60     /** port component name */
61     private String JavaDoc name;
62
63     /** the sib if the endpoint is an ejb */
64     private VcBean bean = null;
65
66     /** a string containing sei method names separated by ',' */
67     private static final String JavaDoc SEP = ",";
68
69     /** a list of method names */
70     private String JavaDoc methods = null;
71
72     /** port component handlers */
73     private Vector JavaDoc handlers = new Vector JavaDoc();
74
75     /** the JAXRPC class name if the sib is a servlet */
76     private String JavaDoc jaxRpcClassName;
77
78     /** the wsdl file to display when ?wsdl is used */
79     private String JavaDoc wsdlFilename;
80
81     /**
82      * Document style name
83      */

84     private static final String JavaDoc DOCUMENT_STYLE = "document";
85
86     /**
87      * SOAP style
88      */

89     private String JavaDoc style = null;
90
91     /**
92      * SOAP use
93      */

94     private String JavaDoc use = null;
95
96     /**
97      * target Namespace
98      */

99     private String JavaDoc namespace = null;
100
101     /**
102      * SOAP NS URI
103      */

104     public static final String JavaDoc NS_URI_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/";
105
106     /**
107      * soap:binding
108      */

109     private static final QName JavaDoc SOAP_BINDING_QNAME = new QName JavaDoc(NS_URI_SOAP, "binding");
110
111     /**
112      * soap:operation
113      */

114     private static final QName JavaDoc SOAP_OPERATION_QNAME = new QName JavaDoc(NS_URI_SOAP, "operation");
115
116     /**
117      * soap:body
118      */

119     private static final QName JavaDoc SOAP_BODY_QNAME = new QName JavaDoc(NS_URI_SOAP, "body");
120
121     /**
122      * soap:fault
123      */

124     private static final QName JavaDoc SOAP_FAULT_QNAME = new QName JavaDoc(NS_URI_SOAP, "fault");
125
126     /**
127      * Construct a VcPortComponent from a PortComponentDesc. used for
128      * server-side configuration files generation. (server-config.wsdd)
129      * @param pcd PortComponentDesc to be used
130      * @param wsdl wsdl filename of the port
131      */

132     public VcPortComponent(PortComponentDesc pcd, String JavaDoc wsdl) {
133
134         // set name
135
name = pcd.getServiceName();
136
137         wsdlFilename = wsdl;
138
139         // set bean or jaxRpcClassName
140
if (pcd.hasBeanImpl()) {
141             // set bean
142
SessionStatelessDesc ssb = ((SSBPortComponentDesc) pcd).getSessionStatelessDesc();
143             bean = new VcBean(ssb);
144         } else {
145             jaxRpcClassName = pcd.getSIBClassname();
146         }
147         // set methods
148
Method JavaDoc[] m = pcd.getServiceEndpointInterface().getMethods();
149         for (int i = 0; i < m.length; i++) {
150             if (methods != null) {
151                 methods += SEP;
152             } else {
153                 methods = "";
154             }
155             methods += m[i].getName();
156         }
157
158         // set style/use/namespace
159
Definition def = pcd.getServiceDesc().getWSDL().getDefinition();
160         boolean portFound = false;
161         for (Iterator JavaDoc i = def.getServices().keySet().iterator(); i.hasNext() && !portFound;) {
162             Service s = def.getService((QName JavaDoc) i.next());
163             Port p = s.getPort(pcd.getQName().getLocalPart());
164             if (p != null) {
165                 // we found the linked port
166
portFound = true;
167
168                 // search style attribute
169
style = getStyle(p);
170
171                 // search use attribute inside port
172
use = getUse(p);
173             }
174         }
175         namespace = def.getTargetNamespace();
176
177         // set handlers
178
List JavaDoc hs = pcd.getHandlers();
179         for (Iterator JavaDoc itH = hs.iterator(); itH.hasNext();) {
180             HandlerDesc hd = (HandlerDesc) itH.next();
181             handlers.add(new VcHandler(hd));
182         }
183
184     }
185
186     /**
187      * @param p the wsdl port
188      * @return Returns the <code>use</code> to use with the port
189      */

190     private static String JavaDoc getUse(Port p) {
191         String JavaDoc use = null;
192
193         // use is declared inside
194
// - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:input/soap:body@use
195
// - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:output/soap:body@use
196
// - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:fault/soap:fault@use
197
// take the first one.
198
List JavaDoc ops = p.getBinding().getBindingOperations();
199         for (Iterator JavaDoc j = ops.iterator(); j.hasNext() && (use == null);) {
200             BindingOperation bop = (BindingOperation) j.next();
201
202             // search input
203
List JavaDoc inputExt = bop.getBindingInput().getExtensibilityElements();
204             for (Iterator JavaDoc k = inputExt.iterator(); k.hasNext() && (use == null);) {
205                 ExtensibilityElement ext = (ExtensibilityElement) k.next();
206                 if (ext.getElementType().equals(SOAP_BODY_QNAME)) {
207                     SOAPBody sb = (SOAPBody) ext;
208                     use = sb.getUse();
209                 }
210             }
211
212             // search output
213
List JavaDoc outputExt = bop.getBindingOutput().getExtensibilityElements();
214             for (Iterator JavaDoc k = outputExt.iterator(); k.hasNext() && (use == null);) {
215                 ExtensibilityElement ext = (ExtensibilityElement) k.next();
216                 if (ext.getElementType().equals(SOAP_BODY_QNAME)) {
217                     SOAPBody sb = (SOAPBody) ext;
218                     use = sb.getUse();
219                 }
220             }
221
222             // search faults
223
for (Iterator JavaDoc k = bop.getBindingFaults().keySet().iterator(); k.hasNext() && (use == null);) {
224                 BindingFault bf = bop.getBindingFault((String JavaDoc) k.next());
225
226                 // search soap:fault
227
List JavaDoc faultExt = bf.getExtensibilityElements();
228                 for (Iterator JavaDoc i = faultExt.iterator(); i.hasNext() && (use == null);) {
229                     ExtensibilityElement ext = (ExtensibilityElement) i.next();
230                     if (ext.getElementType().equals(SOAP_FAULT_QNAME)) {
231                         SOAPFault sf = (SOAPFault) ext;
232                         use = sf.getUse();
233                     }
234                 }
235             }
236         }
237         // use cannot be null as it is required !
238

239         return use;
240     }
241
242     /**
243      * @param p the wsdl port
244      * @return Returns the <code>style</code> to use with the port
245      */

246     private static String JavaDoc getStyle(Port p) {
247         String JavaDoc style = null;
248
249         // we need to explore soap:operation and get the first that set a style attribute
250
List JavaDoc bindingOps = p.getBinding().getBindingOperations();
251         for (Iterator JavaDoc i = bindingOps.iterator(); i.hasNext() && (style == null);) {
252
253             BindingOperation bop = (BindingOperation) i.next();
254             // browse soap:operation
255
List JavaDoc extElements = bop.getExtensibilityElements();
256             for (Iterator JavaDoc j = extElements.iterator(); j.hasNext();) {
257                 ExtensibilityElement ext = (ExtensibilityElement) j.next();
258                 if (ext.getElementType().equals(SOAP_OPERATION_QNAME)) {
259
260                     // Got a soap:operation element
261
SOAPOperation sop = (SOAPOperation) ext;
262                     style = sop.getStyle();
263                 }
264             }
265         }
266
267         // browse extensibility elements of port's binding
268
List JavaDoc soapElements = p.getBinding().getExtensibilityElements();
269         for (Iterator JavaDoc i = soapElements.iterator(); i.hasNext() && (style == null);) {
270
271             ExtensibilityElement ext = (ExtensibilityElement) i.next();
272             if (ext.getElementType().equals(SOAP_BINDING_QNAME)) {
273
274                 // Got a soap:binding element
275
SOAPBinding soapb = (SOAPBinding) ext;
276                 style = soapb.getStyle();
277             }
278
279         }
280
281         if (style == null) {
282             style = DOCUMENT_STYLE;
283         }
284
285         return style;
286     }
287
288     /**
289      * Construct a VcPortComponent from a PortComponentRef. used for client-side
290      * configuration files generation. (client-config.wsdd)
291      * @param name Port Ref name
292      * @param hrs HandlerRef list
293      */

294     public VcPortComponent(String JavaDoc name, List JavaDoc hrs) {
295
296         // set name
297
this.name = name;
298
299         // set handlers
300
for (Iterator JavaDoc itH = hrs.iterator(); itH.hasNext();) {
301             HandlerDesc hr = (HandlerDesc) itH.next();
302             handlers.add(new VcHandler(hr));
303         }
304
305     }
306
307     /**
308      * @return Returns the PortComponent name
309      */

310     public String JavaDoc getName() {
311         return name;
312     }
313
314     /**
315      * @return Returns the VcBean of this PortComponent
316      */

317     public VcBean getBean() {
318         return bean;
319     }
320
321     /**
322      * @return Returns the WSDL filename
323      */

324     public String JavaDoc getWSDLFilename() {
325         return wsdlFilename;
326     }
327
328     /**
329      * @return returns the exposed methods as a comma separated list
330      */

331     public String JavaDoc getMethods() {
332         return methods;
333     }
334
335     /**
336      * @return Returns a list of Handler/HandlerRef
337      */

338     public Vector JavaDoc getHandlers() {
339         return handlers;
340     }
341
342     /**
343      * @return Returns the JaxRpc implementation classname
344      */

345     public String JavaDoc getJaxRpcClassName() {
346         return jaxRpcClassName;
347     }
348
349     /**
350      * @return Returns the style.
351      */

352     public String JavaDoc getStyle() {
353         return style;
354     }
355
356     /**
357      * @return Returns the use.
358      */

359     public String JavaDoc getUse() {
360         return use;
361     }
362
363     /**
364      * @return Returns the namespace.
365      */

366     public String JavaDoc getNamespace() {
367         return namespace;
368     }
369 }
Popular Tags