001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Xavier Delplanque
022: * --------------------------------------------------------------------------
023: * $Id: VcPortComponent.java 5045 2004-07-01 14:55:18Z sauthieg $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_ws.wsgen.generator.axis;
026:
027: import java.lang.reflect.Method;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Vector;
031:
032: import javax.wsdl.BindingFault;
033: import javax.wsdl.BindingOperation;
034: import javax.wsdl.Definition;
035: import javax.wsdl.Port;
036: import javax.wsdl.Service;
037: import javax.wsdl.extensions.ExtensibilityElement;
038: import javax.wsdl.extensions.soap.SOAPBinding;
039: import javax.wsdl.extensions.soap.SOAPBody;
040: import javax.wsdl.extensions.soap.SOAPFault;
041: import javax.wsdl.extensions.soap.SOAPOperation;
042: import javax.xml.namespace.QName;
043:
044: import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
045:
046: import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
047:
048: import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
049: import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
050:
051: /**
052: * Member of a VelocityContext. Contains information about a
053: * PortComponent(Desc/Ref).
054: * @author Xavier Delplanque
055: */
056: public class VcPortComponent {
057:
058: /** port component name */
059: private String name;
060:
061: /** the sib if the endpoint is an ejb */
062: private VcBean bean = null;
063:
064: /** a string containing sei method names separated by ',' */
065: private static final String SEP = ",";
066:
067: /** a list of method names */
068: private String methods = null;
069:
070: /** port component handlers */
071: private Vector handlers = new Vector();
072:
073: /** the JAXRPC class name if the sib is a servlet */
074: private String jaxRpcClassName;
075:
076: /** the wsdl file to display when ?wsdl is used */
077: private String wsdlFilename;
078:
079: /**
080: * Document style name
081: */
082: private static final String DOCUMENT_STYLE = "document";
083:
084: /**
085: * SOAP style
086: */
087: private String style = null;
088:
089: /**
090: * SOAP use
091: */
092: private String use = null;
093:
094: /**
095: * target Namespace
096: */
097: private String namespace = null;
098:
099: /**
100: * SOAP NS URI
101: */
102: public static final String NS_URI_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/";
103:
104: /**
105: * soap:binding
106: */
107: private static final QName SOAP_BINDING_QNAME = new QName(
108: NS_URI_SOAP, "binding");
109:
110: /**
111: * soap:operation
112: */
113: private static final QName SOAP_OPERATION_QNAME = new QName(
114: NS_URI_SOAP, "operation");
115:
116: /**
117: * soap:body
118: */
119: private static final QName SOAP_BODY_QNAME = new QName(NS_URI_SOAP,
120: "body");
121:
122: /**
123: * soap:fault
124: */
125: private static final QName SOAP_FAULT_QNAME = new QName(
126: NS_URI_SOAP, "fault");
127:
128: /**
129: * Construct a VcPortComponent from a PortComponentDesc. used for
130: * server-side configuration files generation. (server-config.wsdd)
131: * @param pcd PortComponentDesc to be used
132: * @param wsdl wsdl filename of the port
133: */
134: public VcPortComponent(PortComponentDesc pcd, String wsdl) {
135:
136: // set name
137: name = pcd.getServiceName();
138:
139: wsdlFilename = wsdl;
140:
141: // set bean or jaxRpcClassName
142: if (pcd.hasBeanImpl()) {
143: // set bean
144: SessionStatelessDesc ssb = ((SSBPortComponentDesc) pcd)
145: .getSessionStatelessDesc();
146: bean = new VcBean(ssb);
147: } else {
148: jaxRpcClassName = pcd.getSIBClassname();
149: }
150: // set methods
151: Method[] m = pcd.getServiceEndpointInterface().getMethods();
152: for (int i = 0; i < m.length; i++) {
153: if (methods != null) {
154: methods += SEP;
155: } else {
156: methods = "";
157: }
158: methods += m[i].getName();
159: }
160:
161: // set style/use/namespace
162: Definition def = pcd.getServiceDesc().getWSDL().getDefinition();
163: boolean portFound = false;
164: for (Iterator i = def.getServices().keySet().iterator(); i
165: .hasNext()
166: && !portFound;) {
167: Service s = def.getService((QName) i.next());
168: Port p = s.getPort(pcd.getQName().getLocalPart());
169: if (p != null) {
170: // we found the linked port
171: portFound = true;
172:
173: // search style attribute
174: style = getStyle(p);
175:
176: // search use attribute inside port
177: use = getUse(p);
178: }
179: }
180: namespace = def.getTargetNamespace();
181:
182: // set handlers
183: List hs = pcd.getHandlers();
184: for (Iterator itH = hs.iterator(); itH.hasNext();) {
185: HandlerDesc hd = (HandlerDesc) itH.next();
186: handlers.add(new VcHandler(hd));
187: }
188:
189: }
190:
191: /**
192: * @param p the wsdl port
193: * @return Returns the <code>use</code> to use with the port
194: */
195: private static String getUse(Port p) {
196: String use = null;
197:
198: // use is declared inside
199: // - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:input/soap:body@use
200: // - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:output/soap:body@use
201: // - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:fault/soap:fault@use
202: // take the first one.
203: List ops = p.getBinding().getBindingOperations();
204: for (Iterator j = ops.iterator(); j.hasNext() && (use == null);) {
205: BindingOperation bop = (BindingOperation) j.next();
206:
207: // search input
208: List inputExt = bop.getBindingInput()
209: .getExtensibilityElements();
210: for (Iterator k = inputExt.iterator(); k.hasNext()
211: && (use == null);) {
212: ExtensibilityElement ext = (ExtensibilityElement) k
213: .next();
214: if (ext.getElementType().equals(SOAP_BODY_QNAME)) {
215: SOAPBody sb = (SOAPBody) ext;
216: use = sb.getUse();
217: }
218: }
219:
220: // search output
221: List outputExt = bop.getBindingOutput()
222: .getExtensibilityElements();
223: for (Iterator k = outputExt.iterator(); k.hasNext()
224: && (use == null);) {
225: ExtensibilityElement ext = (ExtensibilityElement) k
226: .next();
227: if (ext.getElementType().equals(SOAP_BODY_QNAME)) {
228: SOAPBody sb = (SOAPBody) ext;
229: use = sb.getUse();
230: }
231: }
232:
233: // search faults
234: for (Iterator k = bop.getBindingFaults().keySet()
235: .iterator(); k.hasNext() && (use == null);) {
236: BindingFault bf = bop
237: .getBindingFault((String) k.next());
238:
239: // search soap:fault
240: List faultExt = bf.getExtensibilityElements();
241: for (Iterator i = faultExt.iterator(); i.hasNext()
242: && (use == null);) {
243: ExtensibilityElement ext = (ExtensibilityElement) i
244: .next();
245: if (ext.getElementType().equals(SOAP_FAULT_QNAME)) {
246: SOAPFault sf = (SOAPFault) ext;
247: use = sf.getUse();
248: }
249: }
250: }
251: }
252: // use cannot be null as it is required !
253:
254: return use;
255: }
256:
257: /**
258: * @param p the wsdl port
259: * @return Returns the <code>style</code> to use with the port
260: */
261: private static String getStyle(Port p) {
262: String style = null;
263:
264: // we need to explore soap:operation and get the first that set a style attribute
265: List bindingOps = p.getBinding().getBindingOperations();
266: for (Iterator i = bindingOps.iterator(); i.hasNext()
267: && (style == null);) {
268:
269: BindingOperation bop = (BindingOperation) i.next();
270: // browse soap:operation
271: List extElements = bop.getExtensibilityElements();
272: for (Iterator j = extElements.iterator(); j.hasNext();) {
273: ExtensibilityElement ext = (ExtensibilityElement) j
274: .next();
275: if (ext.getElementType().equals(SOAP_OPERATION_QNAME)) {
276:
277: // Got a soap:operation element
278: SOAPOperation sop = (SOAPOperation) ext;
279: style = sop.getStyle();
280: }
281: }
282: }
283:
284: // browse extensibility elements of port's binding
285: List soapElements = p.getBinding().getExtensibilityElements();
286: for (Iterator i = soapElements.iterator(); i.hasNext()
287: && (style == null);) {
288:
289: ExtensibilityElement ext = (ExtensibilityElement) i.next();
290: if (ext.getElementType().equals(SOAP_BINDING_QNAME)) {
291:
292: // Got a soap:binding element
293: SOAPBinding soapb = (SOAPBinding) ext;
294: style = soapb.getStyle();
295: }
296:
297: }
298:
299: if (style == null) {
300: style = DOCUMENT_STYLE;
301: }
302:
303: return style;
304: }
305:
306: /**
307: * Construct a VcPortComponent from a PortComponentRef. used for client-side
308: * configuration files generation. (client-config.wsdd)
309: * @param name Port Ref name
310: * @param hrs HandlerRef list
311: */
312: public VcPortComponent(String name, List hrs) {
313:
314: // set name
315: this .name = name;
316:
317: // set handlers
318: for (Iterator itH = hrs.iterator(); itH.hasNext();) {
319: HandlerDesc hr = (HandlerDesc) itH.next();
320: handlers.add(new VcHandler(hr));
321: }
322:
323: }
324:
325: /**
326: * @return Returns the PortComponent name
327: */
328: public String getName() {
329: return name;
330: }
331:
332: /**
333: * @return Returns the VcBean of this PortComponent
334: */
335: public VcBean getBean() {
336: return bean;
337: }
338:
339: /**
340: * @return Returns the WSDL filename
341: */
342: public String getWSDLFilename() {
343: return wsdlFilename;
344: }
345:
346: /**
347: * @return returns the exposed methods as a comma separated list
348: */
349: public String getMethods() {
350: return methods;
351: }
352:
353: /**
354: * @return Returns a list of Handler/HandlerRef
355: */
356: public Vector getHandlers() {
357: return handlers;
358: }
359:
360: /**
361: * @return Returns the JaxRpc implementation classname
362: */
363: public String getJaxRpcClassName() {
364: return jaxRpcClassName;
365: }
366:
367: /**
368: * @return Returns the style.
369: */
370: public String getStyle() {
371: return style;
372: }
373:
374: /**
375: * @return Returns the use.
376: */
377: public String getUse() {
378: return use;
379: }
380:
381: /**
382: * @return Returns the namespace.
383: */
384: public String getNamespace() {
385: return namespace;
386: }
387: }
|