You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by sa...@apache.org on 2009/09/02 17:26:00 UTC

svn commit: r810563 - /webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java

Author: sagara
Date: Wed Sep  2 15:25:59 2009
New Revision: 810563

URL: http://svn.apache.org/viewvc?rev=810563&view=rev
Log:
add some missing features. 

Modified:
    webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java

Modified: webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java?rev=810563&r1=810562&r2=810563&view=diff
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java (original)
+++ webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java Wed Sep  2 15:25:59 2009
@@ -12,7 +12,9 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
 import org.apache.woden.WSDLException;
 import org.apache.woden.XMLElement;
 import org.apache.woden.internal.util.om.OMUtils;
@@ -35,6 +37,7 @@
 import org.apache.woden.wsdl20.xml.ImportElement;
 import org.apache.woden.wsdl20.xml.IncludeElement;
 import org.apache.woden.wsdl20.xml.InterfaceElement;
+import org.apache.woden.wsdl20.xml.InterfaceFaultElement;
 import org.apache.woden.wsdl20.xml.InterfaceFaultReferenceElement;
 import org.apache.woden.wsdl20.xml.InterfaceMessageReferenceElement;
 import org.apache.woden.wsdl20.xml.InterfaceOperationElement;
@@ -45,9 +48,15 @@
 
 
 /**
- * @author Sagara Gunathunga (sagara.gunathunga@gmail.com)
+ * This is a concrete class derived from BaseWSDLWriter
+ * class and implements method to serialize each WSDL2.0
+ * element based on OM and also WriteWSDL() methods of
+ * the  WSDLWriter interface .
+ *
  *
+ * @author Sagara Gunathunga (sagara.gunathunga@gmail.com)
  */
+
 public class OMWSDLWriter extends BaseWSDLWriter{
 
     public OMWSDLWriter(WSDLContext wsdlContext)
@@ -175,8 +184,6 @@
                         namespaces[i].getNamespaceURI().toString(), pw);
             }
         }
-
-
     }
 
 
@@ -191,8 +198,8 @@
                                 DescriptionElement des,
                                 PrintWriter pw)
                                 throws WSDLException
-    {   
-        
+    { 
+              
         if (imports != null){
             String tagName =
                 OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
@@ -293,18 +300,25 @@
                                 name.getLocalPart(),
                                 pw);
                     }
-
+                    
                     QName[] extendedInterfaces = intrface.getExtendedInterfaceNames();
-                    for(int i=0;i<extendedInterfaces.length;i++){
+                    String attrExtendedInterfaces="";
+                    for(int i=0;i<extendedInterfaces.length;i++){                    	
                         if(extendedInterfaces[i]!=null){
-
-                            OMUtils.printQualifiedAttribute(
-                                    Constants.ATTR_EXTENDS,
-                                    extendedInterfaces[i],
-                                    des, pw);
+                        	attrExtendedInterfaces=attrExtendedInterfaces + OMUtils.
+                        					getQualifiedValue(extendedInterfaces[i].getNamespaceURI(), 
+                        							extendedInterfaces[i].getLocalPart(), des);
+                        	if(i!=extendedInterfaces.length-1){
+                        		attrExtendedInterfaces=attrExtendedInterfaces+ " ";
+                        		
+                        	}
+                           
                         }
                     }
-
+                    if(extendedInterfaces.length>0){
+                    	OMUtils.printAttribute(Constants.ATTR_EXTENDS,attrExtendedInterfaces,pw);                    	
+                    }                    
+           
                     URI[] styleDefaults = intrface.getStyleDefault();
                     for(int i=0;i<styleDefaults.length;i++){
 
@@ -318,12 +332,11 @@
                                     pw);
                         }
                     }
-
-
                     printExtensibilityAttributes(intrface.getExtensionAttributes(), intrface, pw);
                     pw.println('>');
                     printDocumentation(intrface.getDocumentationElements(), des, pw);
                     printOperations(intrface.getInterfaceOperationElements(), des, pw);
+                    printFaults(intrface.getInterfaceFaultElements(), des, pw);    
                     printExtensibilityElements(intrface.getClass(), intrface.getExtensionElements(), des, pw);
                     pw.println("  </" + tagName + '>');
                 }
@@ -345,7 +358,7 @@
                                    throws WSDLException
      {
         if (operations != null){
-
+        	
             String tagName =
                 OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
                           Constants.ELEM_OPERATION,
@@ -381,7 +394,7 @@
                                     pw);
                         }
                     }
-
+                    
                     printExtensibilityAttributes(operation.getExtensionAttributes(), operation, pw);
                     pw.println('>');
                     printDocumentation(operation.getDocumentationElements(), des, pw);
@@ -412,7 +425,52 @@
             PrintWriter pw)
               throws WSDLException
      {
-        //TODO     
+       for(int ind=0;ind<msgrefs.length;ind++){
+             InterfaceMessageReferenceElement msgRef=msgrefs[ind];
+             if(msgRef!=null){
+                 String tagName =null;
+                 Direction msgDirection=msgRef.getDirection();
+                 if(msgDirection==Direction.IN){
+                     tagName=OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                              Constants.ELEM_INPUT,
+                              msgRef);
+                 }else if(msgDirection==Direction.OUT){
+                     tagName=OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                              Constants.ELEM_OUTPUT,
+                              msgRef);            }
+
+             pw.print("      <" + tagName);
+
+             String msglable=msgRef.getMessageLabel().toString();
+             OMUtils.printAttribute(Constants.ATTR_MESSAGE_LABEL, msglable, pw);
+
+             QNameTokenUnion qtu = msgRef.getElement();
+             if(qtu != null) {
+                 if(qtu.isQName()) {
+                     QName element=qtu.getQName();
+                     URI ns=msgRef.getNamespaceURI(element.getPrefix());
+                     String attrName;
+                     if(ns!=null){
+                         attrName=
+                             OMUtils.getQualifiedValue(msgRef.getNamespaceURI(element.getPrefix()).toString(),
+                                     element.getLocalPart(), msgRef);
+                     }else{
+                         attrName=element.getLocalPart();
+                     }
+                     OMUtils.printAttribute(Constants.ATTR_ELEMENT, attrName, pw);
+                 } else {
+                     //qtu is a Token
+                     OMUtils.printAttribute(Constants.ATTR_ELEMENT, qtu.getToken(), pw);
+                 }
+             }
+             printExtensibilityAttributes(msgRef.getExtensionAttributes(), msgRef, pw);
+             pw.println('>');
+             printDocumentation(msgRef.getDocumentationElements(), des, pw);
+             printExtensibilityElements(msgRef.getClass(), msgRef.getExtensionElements(), des, pw);
+             pw.println("    </" + tagName + '>');
+         }
+       }     
+    	
           
     }
 
@@ -427,7 +485,98 @@
                                                         DescriptionElement des,
                                                         PrintWriter pw)
                                                         throws WSDLException{
-        //TODO
+       for(int ind=0;ind<faulRefs.length;ind++){
+
+            InterfaceFaultReferenceElement faulRef=faulRefs[ind];
+            if(faulRef!=null){
+                String tagName =null;
+                Direction msgDirection=faulRef.getDirection();
+                if(msgDirection==Direction.IN){
+                    tagName=OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                            Constants.ELEM_INFAULT,
+                            faulRef);
+                }else if(msgDirection==Direction.OUT){
+
+                    tagName=OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                            Constants.ELEM_OUTFAULT,
+                            faulRef);
+
+                }
+                pw.print("      <" + tagName);
+                String msglable=faulRef.getMessageLabel().toString();
+                OMUtils.printAttribute(Constants.ATTR_MESSAGE_LABEL, msglable, pw);
+
+                QName attrQName=faulRef.getRef();
+                String attrName=
+                    OMUtils.getQualifiedValue(faulRef.getNamespaceURI(attrQName.getPrefix()).toString(),
+                        attrQName.getLocalPart(),
+                        faulRef);
+                OMUtils.printAttribute(Constants.ATTR_REF, attrName, pw);
+
+                printExtensibilityAttributes(faulRef.getExtensionAttributes(), faulRef, pw);
+                pw.println('>');
+                printDocumentation(faulRef.getDocumentationElements(), des, pw);
+                printExtensibilityElements(faulRef.getClass(), faulRef.getExtensionElements(), des, pw);
+                pw.println("    </" + tagName + '>');
+            }
+
+
+
+        }
+    }
+    
+    
+    /**
+     * Serialize  the InterfaceInterfaceFaultElement of the  WSDL element model.
+     *
+     * @param faulEles an array of InterfaceFaultElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printFaults(InterfaceFaultElement[] faulEles,
+                                                        DescriptionElement des,
+                                                        PrintWriter pw)
+                                                        throws WSDLException{
+        for(int ind=0;ind<faulEles.length;ind++){
+
+        	InterfaceFaultElement faulEle=faulEles[ind];
+            if(faulEle!=null){
+
+                String tagName =null;
+                
+                    tagName=OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                            Constants.ELEM_FAULT,
+                            faulEle);
+               
+
+                
+
+                pw.print("      <" + tagName);
+
+                
+                String attrName=faulEle.getName().getLocalPart();                   
+                OMUtils.printAttribute(Constants.ATTR_NAME, attrName, pw);
+                //TODO check here - returns  QNameTokenUnion but only take QName
+                QName attrElement=faulEle.getElement().getQName();
+                String attrEle=
+                    OMUtils.getQualifiedValue(faulEle.getNamespaceURI(attrElement.getPrefix()).toString(),
+                    		attrElement.getLocalPart(),
+                        faulEle);
+                OMUtils.printAttribute(Constants.ATTR_ELEMENT, attrEle, pw);
+
+
+                printExtensibilityAttributes(faulEle.getExtensionAttributes(), faulEle, pw);
+                pw.println('>');
+                printDocumentation(faulEle.getDocumentationElements(), des, pw);
+                printExtensibilityElements(faulEle.getClass(), faulEle.getExtensionElements(), des, pw);
+                pw.println("    </" + tagName + '>');
+            }
+
+
+
+        }
+
+
     }
 
     /**
@@ -442,7 +591,45 @@
                                  PrintWriter pw)
                                  throws WSDLException
     {
-        //TODO
+        String tagName =
+            OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                        Constants.ELEM_BINDING,
+                        des);
+        for(int ind=0;ind<bindings.length;ind++){
+
+            BindingElement binding=bindings[ind];
+            if (bindings != null){
+
+                pw.print("  <" + tagName);
+                QName name = binding.getName();
+                if (name != null){
+                    OMUtils.printAttribute(Constants.ATTR_NAME,
+                            name.getLocalPart(),
+                            pw);
+                }
+                InterfaceElement intrface = binding.getInterfaceElement();
+                if (intrface != null){
+                    QName interfaceName=intrface.getName();
+                    if(interfaceName!=null)
+                    OMUtils.printQualifiedAttribute(Constants.ATTR_INTERFACE,
+                            interfaceName,
+                            des,
+                            pw);
+                    OMUtils.printAttribute(Constants.ATTR_TYPE,
+                            binding.getType().toString(),
+                            pw);
+                   printExtensibilityAttributes(binding.getExtensionAttributes(), binding, pw);
+                   pw.println('>');       
+
+                }
+                printDocumentation(binding.getDocumentationElements(), des, pw);
+                printExtensibilityElements(binding.getClass(), binding.getExtensionElements(), des, pw);
+                printBindingOperations(binding.getBindingOperationElements(), des, pw);
+                printBindingFaults(binding.getBindingFaultElements(), des, pw);
+                pw.println("  </" + tagName + '>');
+            }
+        }
+      
       
     }
 
@@ -457,7 +644,31 @@
                                              DescriptionElement des,
                                              PrintWriter pw)
                                              throws WSDLException{
-        //TODO
+        if (faults != null){
+
+             String tagName =
+                 OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                           Constants.ELEM_FAULT,
+                           des);
+             for(int ind=0;ind<faults.length;ind++){
+
+                 BindingFaultElement fault =faults[ind] ;
+                 if (fault!=null){
+
+                     pw.print("    <" + tagName);
+                     OMUtils.printQualifiedAttribute(Constants.ATTR_REF,
+                             fault.getRef(),
+                              des,
+                              pw);
+
+                     printExtensibilityAttributes(fault.getExtensionAttributes(), fault, pw);
+                     pw.println("/>");
+
+                 }
+             }
+
+
+         }
        
 
     }
@@ -474,7 +685,27 @@
                                                  PrintWriter pw)
                                                  throws WSDLException
      {
-        //TODO      
+       if (operations != null){
+            String tagName =
+                OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                          Constants.ELEM_OPERATION,
+                          des);
+            for(int ind=0;ind<operations.length;ind++){
+
+                BindingOperationElement operation =operations[ind] ;
+                if (operation!=null){
+                    pw.print("    <" + tagName);
+                    OMUtils.printQualifiedAttribute(Constants.ATTR_REF,
+                             operation.getRef(),
+                             des,
+                             pw);
+                    printExtensibilityAttributes(operation.getExtensionAttributes(), operation, pw);
+                    pw.println("/>");
+                }
+            }
+
+
+        }      
 
      }
 
@@ -490,7 +721,35 @@
                                  PrintWriter pw)
                                  throws WSDLException
      {
-        //TODO
+       String tagName =
+            OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                        Constants.ELEM_SERVICE,
+                        des);
+        for(int ind=0;ind<services.length;ind++){
+
+            ServiceElement service=services[ind];
+            if(service!=null){
+                pw.print("  <" + tagName);
+                QName name = service.getName();
+                if (name != null){
+                    OMUtils.printAttribute(Constants.ATTR_NAME,
+                            name.getLocalPart(),
+                            pw);
+                }
+                QName interfaceName = service.getInterfaceName();
+                if (name != null){
+
+                    OMUtils.printQualifiedAttribute(Constants.ATTR_INTERFACE,
+                            interfaceName,des, pw);
+                }
+                printExtensibilityAttributes(service.getExtensionAttributes(), service, pw);
+                pw.println('>');
+                printEndpoints(service.getEndpointElements(), des, pw);
+                printDocumentation(service.getDocumentationElements(), des, pw);
+                printExtensibilityElements(service.getClass(),service.getExtensionElements(), des, pw);
+                pw.println("    </" + tagName + '>');
+            }
+        }
        
      }
 
@@ -506,7 +765,43 @@
                                  PrintWriter pw)
                                  throws WSDLException
       {
-        //TODO    
+        String tagName =
+            OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                                       Constants.ELEM_ENDPOINT,
+                                       des);
+        for(int ind=0;ind<endpoints.length;ind++){
+
+            EndpointElement endPoint=endpoints[ind];
+            if(endPoint!=null){
+
+                pw.print("    <" + tagName);
+                String name=endPoint.getName().toString();
+                OMUtils.printAttribute(Constants.ATTR_NAME,
+                        name, pw);
+
+                BindingElement binding =endPoint.getBindingElement();
+                if (binding != null){
+                    OMUtils.printQualifiedAttribute(Constants.ATTR_BINDING,
+                            binding.getName(),
+                            des,
+                            pw);
+                }
+
+                URI address =endPoint.getAddress();
+                if (address != null){
+                    OMUtils.printAttribute(Constants.ATTR_ADDRESS,
+                            address.toString(),
+                            pw);
+                }
+
+
+                printExtensibilityAttributes(endPoint.getExtensionAttributes(), endPoint, pw);
+                pw.println('>');
+                printDocumentation(endPoint.getDocumentationElements(), des, pw);
+                printExtensibilityElements(endPoint.getClass(), endPoint.getExtensionElements(), des, pw);
+                pw.println("    </" + tagName + '>');
+            }
+        }   
       }
 
     /**
@@ -626,7 +921,26 @@
                                               DescriptionElement def,
                                               PrintWriter pw)
                                               throws WSDLException{
-        //TODO
+        if (extensibilityElements != null){
+             for(int ind=0;ind<extensibilityElements.length;ind++){
+                 ExtensionElement ext =extensibilityElements[ind];
+                 QName elementType = ext.getExtensionType();
+                 ExtensionRegistry extReg = fWsdlContext.extensionRegistry;
+                 if (extReg == null){
+                     throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
+                             "No ExtensionRegistry set for this " +
+                             "Description, so unable to serialize a '" +
+                             elementType +
+                             "' element in the context of a '" +
+                             parentType.getName() + "'.");
+                 }
+                 ExtensionSerializer extSer = extReg.querySerializer(parentType,
+                         elementType);
+                 extSer.marshall(parentType, elementType, ext, pw, def, extReg);
+             }
+
+         }
+       
       
 
     }
@@ -646,7 +960,27 @@
                                       PrintWriter pw)
                                       throws WSDLException
        {
-        //TODO
+        if(attrExts!=null){
+            for(int index=0;index<attrExts.length;index++){
+                XMLAttr attrExt=attrExts[index];
+                if(attrExt!=null){
+                    QName ns=attrExt.getAttributeType();
+                    String attrName;
+                    String attrLocalName=ns.getLocalPart();
+                    String attrValue=attrExt.toExternalForm();
+                    if(ns!=null){
+                        String attrPrefix=ns.getPrefix();
+                        attrName=
+                            OMUtils.getQualifiedValue(ownerElem.getNamespaceURI(attrPrefix).toString(),
+                                    attrLocalName, ownerElem);
+                    }else{
+                        attrName=attrLocalName;
+                    }
+                    OMUtils.printAttribute(attrName, attrValue, pw);
+                }
+            }
+
+        }
            
     }
 
@@ -664,11 +998,30 @@
                                        PrintWriter pw)
                                        throws WSDLException
     {
-        //TODO
+        if (docEles != null){
+            String tagName =
+                OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                          Constants.ELEM_DOCUMENTATION,
+                          def);
+            for(int ind=0;ind<docEles.length;ind++){
+                DocumentationElement docEle =docEles[ind] ;
+                if (docEle!=null){
+                    pw.print("    <" + tagName);                    
+                    pw.println('>');
+                    Object o = docEle.getContent().getSource();
+                    OMElement omEl = (OMElement)o;                 
+                    pw.println(((OMText)omEl.getFirstOMChild()).getText());                  
+                  //  printExtensibilityElements(Operation.class, extElements, def, pw);
+                    pw.println("    </" + tagName + '>');
+                }
+            }
+        }
+    }
+
         
     }
        
            
 
 
-}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org