ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kei...@apache.org
Subject svn commit: r585057 - /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java
Date Tue, 16 Oct 2007 06:40:26 GMT
Author: keithc
Date: Mon Oct 15 23:40:24 2007
New Revision: 585057

URL: http://svn.apache.org/viewvc?rev=585057&view=rev
Log:
Adding support for styles in ?wsdl2. Now it infers for the style an adds it in.


Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java?rev=585057&r1=585056&r2=585057&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL20.java
Mon Oct 15 23:40:24 2007
@@ -31,9 +31,17 @@
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamConstants;
@@ -45,7 +53,9 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.HashSet;
+import java.util.HashMap;
 import java.net.URI;
+import java.net.URISyntaxException;
 
 public class AxisService2WSDL20 implements WSDL2Constants {
 
@@ -312,7 +322,8 @@
      * @return The generated interface element
      */
     private OMElement getInterfaceElement(OMNamespace wsdl, OMNamespace tns, OMNamespace
wsdlx,
-                                          OMFactory fac, String interfaceName) {
+                                          OMFactory fac, String interfaceName)
+            throws URISyntaxException, AxisFault {
 
         OMElement interfaceElement = fac.createOMElement(WSDL2Constants.INTERFACE_LOCAL_NAME,
wsdl);
         interfaceElement.addAttribute(fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_NAME,
null,
@@ -344,7 +355,7 @@
                     interfaceElement.addChild(faultElement);
                 }
             }
-
+                     
         }
         for (i = 0; i < interfaceOperations.size(); i++) {
             interfaceElement.addChild((OMNode) interfaceOperations.get(i));
@@ -388,7 +399,8 @@
     public OMElement generateInterfaceOperationElement(AxisOperation axisOperation,
                                                        OMNamespace wsdl,
                                                        OMNamespace tns,
-                                                       OMNamespace wsdlx) {
+                                                       OMNamespace wsdlx) throws
+            URISyntaxException, AxisFault {
         OMFactory omFactory = OMAbstractFactory.getOMFactory();
         OMElement axisOperationElement =
                 omFactory.createOMElement(WSDL2Constants.OPERATION_LOCAL_NAME, wsdl);
@@ -397,6 +409,13 @@
                                                                       null,
                                                                       axisOperation.getName().getLocalPart()));
         URI[] opStyle = (URI[]) axisOperation.getParameterValue(WSDL2Constants.OPERATION_STYLE);
+        if (opStyle == null) {
+            opStyle = checkStyle(axisOperation);
+            Parameter opStyleParameter = new Parameter();
+            opStyleParameter.setName(WSDL2Constants.OPERATION_STYLE);
+            opStyleParameter.setValue(opStyle);
+            axisOperation.addParameter(opStyleParameter);
+        }
         if (opStyle != null && opStyle.length > 0) {
             String style = opStyle[0].toString();
             for (int i = 1; i < opStyle.length; i++) {
@@ -459,5 +478,170 @@
 
     public void setEPRs(String[] eprs) {
         this.eprs = eprs;
+    }
+
+    /**
+     * This function checks the schema and returns the WSDL 2.0 styles that it conform to.
+     * It checks for RPC, IRI and Multipart styles.
+     * For full details on the rules please refer http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#styles
+     * @param axisOperation - The axisOperation that needs to be checked
+     * @return String [] - An array of styles that the operation adheres to.
+     */
+    private URI [] checkStyle(AxisOperation axisOperation) throws URISyntaxException {
+        boolean isRPC = true;
+        boolean isMultipart = true;
+        boolean isIRI = true;
+        ArrayList styles = new ArrayList(3);
+
+        String mep = axisOperation.getMessageExchangePattern();
+        if (!(WSDL2Constants.MEP_URI_IN_ONLY.equals(mep) ||
+                WSDL2Constants.MEP_URI_IN_OUT.equals(mep))) {
+            isRPC = false;
+        }
+
+        QName inMessageElementQname;
+        Map inMessageElementDetails = new HashMap();
+        AxisMessage inMessage = axisOperation.getMessage(WSDL2Constants.MESSAGE_LABEL_IN);
+        if (inMessage != null) {
+            QName qName = inMessage.getElementQName();
+            if (qName == null || Constants.XSD_ANY.equals(qName)) {
+                return new URI [0];
+            }
+            XmlSchemaElement schemaElement = inMessage.getSchemaElement();
+            if (schemaElement != null) {
+                if (!axisOperation.getName().getLocalPart().equals(schemaElement.getName()))
{
+                    return new URI [0];
+                }
+                inMessageElementQname = schemaElement.getQName();
+                XmlSchemaType type = schemaElement.getSchemaType();
+                if (type != null && type instanceof XmlSchemaComplexType){
+                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                    XmlSchemaParticle particle = complexType.getParticle();
+                    if (particle != null && particle instanceof XmlSchemaSequence){
+                        XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) particle;
+                        XmlSchemaObjectCollection schemaObjectCollection = xmlSchemaSequence.getItems();
+                        if (schemaObjectCollection != null) {
+                            Iterator iterator = schemaObjectCollection.getIterator();
+                            while (iterator.hasNext()) {
+                                Object next = iterator.next();
+                                if (!(next instanceof XmlSchemaElement)) {
+                                    return new URI [0];
+                                }
+                                XmlSchemaElement innerElement = (XmlSchemaElement) next;
+                                if (innerElement.getRefName() != null) {
+                                    return new URI [0];
+                                }
+                                if (innerElement.getMinOccurs() != 1 || innerElement.getMaxOccurs()
!= 1) {
+                                    isMultipart = false;
+                                }
+                                XmlSchemaType schemaType = innerElement.getSchemaType();
+                                QName innerElementQName = innerElement.getSchemaTypeName();
+                                if (schemaType instanceof XmlSchemaSimpleType) {
+                                    if (Constants.XSD_QNAME.equals(innerElementQName) ||
+                                            Constants.XSD_NOTATION.equals(innerElementQName)
||
+                                            Constants.XSD_HEXBIN.equals(innerElementQName)
||
+                                            Constants.XSD_BASE64.equals(innerElementQName))
{
+                                            isIRI = false;
+                                    }
+                                } else {
+                                    isIRI = false;
+                                }
+                                if (Constants.XSD_ANY.equals(innerElementQName) &&
iterator.hasNext()) {
+                                    isRPC = false;
+                                }
+                                String name = innerElement.getName();
+                                if (inMessageElementDetails.get(name) != null) {
+                                    isRPC = false;
+                                    isMultipart = false;
+                                }
+                                inMessageElementDetails.put(name, innerElementQName);
+                            }
+                        }
+                    } else {
+                        return new URI [0];
+                    }
+                } else {
+                        return new URI [0];
+                    }
+            } else {
+                return new URI [0];
+            }
+        } else {
+            return new URI [0];
+        }
+        if (isRPC && !WSDL2Constants.MEP_URI_IN_ONLY.equals(mep)) {
+            AxisMessage outMessage = axisOperation.getMessage(WSDL2Constants.MESSAGE_LABEL_OUT);
+            QName qName = outMessage.getElementQName();
+            if (qName == null && Constants.XSD_ANY.equals(qName)) {
+                isRPC = false;
+            }
+            XmlSchemaElement schemaElement = outMessage.getSchemaElement();
+            if (schemaElement != null) {
+                if (!(axisOperation.getName().getLocalPart() + Java2WSDLConstants.RESPONSE)
+                        .equals(schemaElement.getName())) {
+                    isRPC = false;
+                }
+                if (!schemaElement.getQName().getNamespaceURI()
+                        .equals(inMessageElementQname.getNamespaceURI())) {
+                    isRPC = false;
+                }
+                XmlSchemaType type = schemaElement.getSchemaType();
+                if (type != null && type instanceof XmlSchemaComplexType) {
+                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                    XmlSchemaParticle particle = complexType.getParticle();
+                    if (particle != null && particle instanceof XmlSchemaSequence)
{
+                        XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) particle;
+                        XmlSchemaObjectCollection schemaObjectCollection =
+                                xmlSchemaSequence.getItems();
+                        if (schemaObjectCollection != null) {
+                            Iterator iterator = schemaObjectCollection.getIterator();
+                            Map outMessageElementDetails = new HashMap();
+                            while (iterator.hasNext()) {
+                                Object next = iterator.next();
+                                if (!(next instanceof XmlSchemaElement)) {
+                                    isRPC = false;
+                                }
+                                XmlSchemaElement innerElement = (XmlSchemaElement) next;
+                                QName schemaTypeName = innerElement.getSchemaTypeName();
+                                String name = innerElement.getName();
+                                if (innerElement.getRefName() != null) {
+                                    isRPC = false;
+                                }
+                                if (outMessageElementDetails.get(name) != null) {
+                                    isRPC = false;
+                                }
+                                QName inMessageElementType =
+                                        (QName) inMessageElementDetails.get(name);
+                                if (inMessageElementType != null &&
+                                        inMessageElementType != schemaTypeName) {
+                                    isRPC = false;
+                                }
+                                outMessageElementDetails.put(name, schemaTypeName);
+                            }
+                        }
+                    } else {
+                        isRPC = false;
+                    }
+                } else {
+                    isRPC = false;
+                }
+            } else {
+                isRPC = false;
+            }
+        }
+        int count = 0;
+        if (isRPC) {
+            styles.add(new URI(WSDL2Constants.STYLE_RPC));
+            count ++;
+        }
+        if (isIRI) {
+            styles.add(new URI(WSDL2Constants.STYLE_IRI));
+            count ++;
+        }
+        if (isMultipart) {
+            styles.add(new URI(WSDL2Constants.STYLE_MULTIPART));
+            count ++;
+        }
+        return (URI[]) styles.toArray(new URI[count]);
     }
 }



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


Mime
View raw message