VcPortComponent.java

00001 
00027 package org.objectweb.jonas_ws.wsgen.generator.axis;
00028 
00029 import java.lang.reflect.Method;
00030 import java.util.Iterator;
00031 import java.util.List;
00032 import java.util.Vector;
00033 
00034 import javax.wsdl.BindingFault;
00035 import javax.wsdl.BindingOperation;
00036 import javax.wsdl.Definition;
00037 import javax.wsdl.Port;
00038 import javax.wsdl.Service;
00039 import javax.wsdl.extensions.ExtensibilityElement;
00040 import javax.wsdl.extensions.soap.SOAPBinding;
00041 import javax.wsdl.extensions.soap.SOAPBody;
00042 import javax.wsdl.extensions.soap.SOAPFault;
00043 import javax.wsdl.extensions.soap.SOAPOperation;
00044 import javax.xml.namespace.QName;
00045 
00046 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
00047 
00048 import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
00049 
00050 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
00051 import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
00052 
00058 public class VcPortComponent {
00059 
00061     private String name;
00062 
00064     private VcBean bean = null;
00065 
00067     private static final String SEP = ",";
00068 
00070     private String methods = null;
00071 
00073     private Vector handlers = new Vector();
00074 
00076     private String jaxRpcClassName;
00077 
00079     private String wsdlFilename;
00080 
00084     private static final String DOCUMENT_STYLE = "document";
00085 
00089     private String style = null;
00090 
00094     private String use = null;
00095 
00099     private String namespace = null;
00100 
00104     public static final String NS_URI_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/";
00105 
00109     private static final QName SOAP_BINDING_QNAME = new QName(NS_URI_SOAP, "binding");
00110 
00114     private static final QName SOAP_OPERATION_QNAME = new QName(NS_URI_SOAP, "operation");
00115 
00119     private static final QName SOAP_BODY_QNAME = new QName(NS_URI_SOAP, "body");
00120 
00124     private static final QName SOAP_FAULT_QNAME = new QName(NS_URI_SOAP, "fault");
00125 
00132     public VcPortComponent(PortComponentDesc pcd, String wsdl) {
00133 
00134         // set name
00135         name = pcd.getServiceName();
00136 
00137         wsdlFilename = wsdl;
00138 
00139         // set bean or jaxRpcClassName
00140         if (pcd.hasBeanImpl()) {
00141             // set bean
00142             SessionStatelessDesc ssb = ((SSBPortComponentDesc) pcd).getSessionStatelessDesc();
00143             bean = new VcBean(ssb);
00144         } else {
00145             jaxRpcClassName = pcd.getSIBClassname();
00146         }
00147         // set methods
00148         Method[] m = pcd.getServiceEndpointInterface().getMethods();
00149         for (int i = 0; i < m.length; i++) {
00150             if (methods != null) {
00151                 methods += SEP;
00152             } else {
00153                 methods = "";
00154             }
00155             methods += m[i].getName();
00156         }
00157 
00158         // set style/use/namespace
00159         Definition def = pcd.getServiceDesc().getWSDL().getDefinition();
00160         boolean portFound = false;
00161         for (Iterator i = def.getServices().keySet().iterator(); i.hasNext() && !portFound;) {
00162             Service s = def.getService((QName) i.next());
00163             Port p = s.getPort(pcd.getQName().getLocalPart());
00164             if (p != null) {
00165                 // we found the linked port
00166                 portFound = true;
00167 
00168                 // search style attribute
00169                 style = getStyle(p);
00170 
00171                 // search use attribute inside port
00172                 use = getUse(p);
00173             }
00174         }
00175         namespace = def.getTargetNamespace();
00176 
00177         // set handlers
00178         List hs = pcd.getHandlers();
00179         for (Iterator itH = hs.iterator(); itH.hasNext();) {
00180             HandlerDesc hd = (HandlerDesc) itH.next();
00181             handlers.add(new VcHandler(hd));
00182         }
00183 
00184     }
00185 
00190     private static String getUse(Port p) {
00191         String use = null;
00192 
00193         // use is declared inside
00194         // - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:input/soap:body@use
00195         // - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:output/soap:body@use
00196         // - wsdl:definition/wsdl:binding/wsdl:operation/wsdl:fault/soap:fault@use
00197         // take the first one.
00198         List ops = p.getBinding().getBindingOperations();
00199         for (Iterator j = ops.iterator(); j.hasNext() && (use == null);) {
00200             BindingOperation bop = (BindingOperation) j.next();
00201 
00202             // search input
00203             List inputExt = bop.getBindingInput().getExtensibilityElements();
00204             for (Iterator k = inputExt.iterator(); k.hasNext() && (use == null);) {
00205                 ExtensibilityElement ext = (ExtensibilityElement) k.next();
00206                 if (ext.getElementType().equals(SOAP_BODY_QNAME)) {
00207                     SOAPBody sb = (SOAPBody) ext;
00208                     use = sb.getUse();
00209                 }
00210             }
00211 
00212             // search output
00213             List outputExt = bop.getBindingOutput().getExtensibilityElements();
00214             for (Iterator k = outputExt.iterator(); k.hasNext() && (use == null);) {
00215                 ExtensibilityElement ext = (ExtensibilityElement) k.next();
00216                 if (ext.getElementType().equals(SOAP_BODY_QNAME)) {
00217                     SOAPBody sb = (SOAPBody) ext;
00218                     use = sb.getUse();
00219                 }
00220             }
00221 
00222             // search faults
00223             for (Iterator k = bop.getBindingFaults().keySet().iterator(); k.hasNext() && (use == null);) {
00224                 BindingFault bf = bop.getBindingFault((String) k.next());
00225 
00226                 // search soap:fault
00227                 List faultExt = bf.getExtensibilityElements();
00228                 for (Iterator i = faultExt.iterator(); i.hasNext() && (use == null);) {
00229                     ExtensibilityElement ext = (ExtensibilityElement) i.next();
00230                     if (ext.getElementType().equals(SOAP_FAULT_QNAME)) {
00231                         SOAPFault sf = (SOAPFault) ext;
00232                         use = sf.getUse();
00233                     }
00234                 }
00235             }
00236         }
00237         // use cannot be null as it is required !
00238 
00239         return use;
00240     }
00241 
00246     private static String getStyle(Port p) {
00247         String style = null;
00248 
00249         // we need to explore soap:operation and get the first that set a style attribute
00250         List bindingOps = p.getBinding().getBindingOperations();
00251         for (Iterator i = bindingOps.iterator(); i.hasNext() && (style == null);) {
00252 
00253             BindingOperation bop = (BindingOperation) i.next();
00254             // browse soap:operation
00255             List extElements = bop.getExtensibilityElements();
00256             for (Iterator j = extElements.iterator(); j.hasNext();) {
00257                 ExtensibilityElement ext = (ExtensibilityElement) j.next();
00258                 if (ext.getElementType().equals(SOAP_OPERATION_QNAME)) {
00259 
00260                     // Got a soap:operation element
00261                     SOAPOperation sop = (SOAPOperation) ext;
00262                     style = sop.getStyle();
00263                 }
00264             }
00265         }
00266 
00267         // browse extensibility elements of port's binding
00268         List soapElements = p.getBinding().getExtensibilityElements();
00269         for (Iterator i = soapElements.iterator(); i.hasNext() && (style == null);) {
00270 
00271             ExtensibilityElement ext = (ExtensibilityElement) i.next();
00272             if (ext.getElementType().equals(SOAP_BINDING_QNAME)) {
00273 
00274                 // Got a soap:binding element
00275                 SOAPBinding soapb = (SOAPBinding) ext;
00276                 style = soapb.getStyle();
00277             }
00278 
00279         }
00280 
00281         if (style == null) {
00282             style = DOCUMENT_STYLE;
00283         }
00284 
00285         return style;
00286     }
00287 
00294     public VcPortComponent(String name, List hrs) {
00295 
00296         // set name
00297         this.name = name;
00298 
00299         // set handlers
00300         for (Iterator itH = hrs.iterator(); itH.hasNext();) {
00301             HandlerDesc hr = (HandlerDesc) itH.next();
00302             handlers.add(new VcHandler(hr));
00303         }
00304 
00305     }
00306 
00310     public String getName() {
00311         return name;
00312     }
00313 
00317     public VcBean getBean() {
00318         return bean;
00319     }
00320 
00324     public String getWSDLFilename() {
00325         return wsdlFilename;
00326     }
00327 
00331     public String getMethods() {
00332         return methods;
00333     }
00334 
00338     public Vector getHandlers() {
00339         return handlers;
00340     }
00341 
00345     public String getJaxRpcClassName() {
00346         return jaxRpcClassName;
00347     }
00348 
00352     public String getStyle() {
00353         return style;
00354     }
00355 
00359     public String getUse() {
00360         return use;
00361     }
00362 
00366     public String getNamespace() {
00367         return namespace;
00368     }
00369 }

Generated on Tue Feb 15 15:06:01 2005 for JOnAS by  doxygen 1.3.9.1