Author: antelder
Date: Wed Feb 28 04:49:25 2007
New Revision: 512738

URL: http://svn.apache.org/viewvc?view=rev&rev=512738
Log:
Start support for the binding.ws 1.0 spec scdl in the Axis2 WS binding

Modified:
    
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingDefinition.java
    
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java

Modified: 
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingDefinition.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingDefinition.java?view=diff&rev=512738&r1=512737&r2=512738
==============================================================================
--- 
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingDefinition.java
 (original)
+++ 
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingDefinition.java
 Wed Feb 28 04:49:25 2007
@@ -19,6 +19,9 @@
 package org.apache.tuscany.binding.axis2;
 
 
+import java.util.Map;
+
+import javax.wsdl.Binding;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
 import javax.wsdl.Service;
@@ -37,21 +40,63 @@
     private Definition definition;
     private Port port;
     private Service service;
-    //private String portURI;
     private String uri;
+    private String namespace;
+    private String serviceName;
+    private String portName;
+    private String bindingName;
+    private Binding binding;
+
+    /**
+     * @deprecated pre 1.0 binding.ws spec
+     */
+    @Deprecated
     public WebServiceBindingDefinition(Definition definition, Port port, 
String uri, String portURI, Service service) {
         this.definition = definition;
         this.port = port;
         this.uri = uri;
-        //this.portURI = portURI;
         this.service = service;
     }
 
+    public WebServiceBindingDefinition(String ns, Definition definition, 
String serviceName, String portName, String bindingName, String uri) {
+        this.namespace = ns;
+        this.definition = definition;
+        this.serviceName = serviceName;
+        this.portName = portName;
+        this.bindingName = bindingName;
+        this.uri = uri;
+    }
+
     public Port getWSDLPort() {
+        if (port == null) {
+            Service service = getWSDLService();
+            port = service.getPort(portName);
+        }
         return port;
     }
 
     public Service getWSDLService() {
+        if (service == null) {
+            if (definition == null) {
+                throw new IllegalStateException("WSDL definition is null");
+            }
+            Map services = definition.getServices();
+            if (serviceName != null) {
+                QName serviceQN = new QName(namespace, serviceName);
+                for (Object o : services.values()) {
+                    Service s = (Service) o;
+                    if (s.getQName().equals(serviceQN)) {
+                        service = s;
+                        break;
+                    }
+                }
+                if (service == null) {
+                    throw new IllegalStateException("no service: " + 
serviceQN);
+                }
+            } else {
+                service = (Service)services.values().iterator().next();
+            }
+        }
         return service;
     }
 
@@ -67,15 +112,25 @@
         definition = def;
     }
 
-    //    public void setPortURI(String uri) {
-    //        portURI = uri;
-    //    }
-
     public String getURI() {
         return uri;
     }
 
     public void setURI(String theUri) {
         this.uri = theUri;
+    }
+    
+    public Binding getBinding() {
+        if (binding == null) {
+            if (definition == null) {
+                throw new IllegalStateException("WSDL definition is null");
+            }
+            QName bindingQN = new QName(namespace, bindingName);
+            this.binding = definition.getBinding(bindingQN);
+            if (binding == null) {
+                throw new IllegalStateException("no binding: " + bindingQN);
+            }
+        }
+        return binding;
     }
 }

Modified: 
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java?view=diff&rev=512738&r1=512737&r2=512738
==============================================================================
--- 
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
 (original)
+++ 
incubator/tuscany/branches/sca-java-integration/sca/extensions/axis2/binding/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
 Wed Feb 28 04:49:25 2007
@@ -70,21 +70,120 @@
     public WebServiceBindingDefinition load(CompositeComponent parent, 
ModelObject object, XMLStreamReader reader,
                                   DeploymentContext deploymentContext)
         throws XMLStreamException, LoaderException {
-        // not sure what uri was here ? String uri = 
reader.getAttributeValue(null, "uri");
-        String uri = null;
+
+        String uri = reader.getAttributeValue(null, "uri");
+        String wsdlElement = reader.getAttributeValue(null, "wsdlElement");
+        String wsdliLocation = reader.getAttributeValue(null, "wsdlLocation");
+
+        // TODO: keep these old attributes for now for backward compatability
         String endpoint = reader.getAttributeValue(null, "endpoint");
         String wsdlLocation = reader.getAttributeValue(null, "location");
+
+        // TODO: support wsa:endpointreference
+        
         LoaderUtil.skipToEndElement(reader);
-        try {
-            return createBinding(uri, endpoint, wsdlLocation, 
deploymentContext);
-        } catch (Exception e) {
-            throw new LoaderException(e);
+
+        WebServiceBindingDefinition wsBinding;
+        if (endpoint != null && endpoint.length() > 0) {
+            // TODO: support these old attributes for now for backward 
compatability
+            try {
+                wsBinding = createBindingOld(uri, endpoint, wsdlLocation, 
deploymentContext);
+            } catch (Exception e) {
+                throw new LoaderException(e);
+            }
+        } else {
+            wsBinding = createWSBinding(wsdlElement, wsdliLocation, uri, 
deploymentContext);
+        }
+        
+        return wsBinding;
+    }
+
+    protected WebServiceBindingDefinition createWSBinding(String wsdlElement, 
String wsdliLocation, String uri, DeploymentContext deploymentContext) throws 
LoaderException {
+        if (wsdlElement == null || wsdlElement.length() < 1) {
+            throw new IllegalArgumentException("missing wsdlElement 
attribute");
+        }
+        if (wsdlElement.indexOf("#wsdl.") < 1) {
+            throw new IllegalArgumentException("missing '#wsdl.' in 
wsdlElement attribute");
         }
 
+        String ns = getWSDLNamespace(wsdlElement);
+
+        String serviceName = null;
+        String portName = null;
+        String bindingName = null;
+
+        String uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.service");
+        if (uriValue != null) {
+            serviceName = uriValue;
+        } else {
+            uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.port");
+            if (uriValue != null) {
+                int i = uriValue.lastIndexOf('/');
+                if (i == -1) {
+                    throw new IllegalArgumentException("Missing '/' seperator 
between service and port in wsdl.port() in wsdlElement attribute");
+                } 
+                serviceName = uriValue.substring(0, i);
+                portName = uriValue.substring(i);
+            } else {
+                uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.enpoint");
+                if (uriValue != null) {
+                    throw new IllegalArgumentException("WSDL 2.0 not supported 
for '#wsdl.endpoint' in wsdlElement attribute");
+                } 
+                uriValue = getWSDLElementURIValue(wsdlElement, "wsdl.binding");
+                if (uriValue == null) {
+                    throw new IllegalArgumentException("missing 
'#wsdl.service' or '#wsdl.port' or '#wsdl.endpoint'or '#wsdl.binding' in 
wsdlElement attribute");
+                }
+                bindingName = uriValue;
+            }
+        }
+
+        Definition definition = null;
+        if (wsdliLocation != null && wsdliLocation.length() > 0) {
+            try {
+                definition = 
wsdlDefinitionRegistry.loadDefinition(wsdliLocation, 
deploymentContext.getClassLoader());
+            } catch (Exception e) {
+                throw new LoaderException("Exception loading WSDL", e);
+            }
+        } else if (ns != null ){
+            definition = wsdlDefinitionRegistry.getDefinition(ns);
+        }
+        
+        WebServiceBindingDefinition wsBinding = new 
WebServiceBindingDefinition(ns, definition, serviceName, portName, bindingName, 
uri);
+
+        return wsBinding;
+    }
+    
+    protected String getWSDLElementURIValue(String wsdlElement, String type) { 
+        String value = null;
+        type = "#" + type + "(";
+        int i = wsdlElement.indexOf(type);
+        if (i > -1) {
+            int j = wsdlElement.indexOf(')',i);
+            if (j < 0) {
+                throw new IllegalArgumentException("missing closing bracket 
')' on " + type + " in wsdlElement attribute");
+            }
+            value = wsdlElement.substring(i, j);
+        }
+        return value;
+    }
+
+    private String getWSDLNamespace(String wsdlElement) {
+        String ns = null;
+        if (wsdlElement != null && wsdlElement.length() > 0) {
+            int i = wsdlElement.indexOf('#');
+            if (i < 0) {
+                throw new IllegalArgumentException("missing '#' namespace 
delimiter in wsdlElement attribute");
+            }
+            if (i == 0) {
+                throw new IllegalArgumentException("no namespace in 
wsdlElement attribute");
+            }
+            ns = wsdlElement.substring(0, i);
+        }
+        return ns;
     }
 
     @SuppressWarnings("unchecked")
-    private WebServiceBindingDefinition createBinding(String uri, String 
endpoint, String wsdlLocation, DeploymentContext deploymentContext)
+    private WebServiceBindingDefinition createBindingOld(String uri, String 
endpoint, String wsdlLocation, DeploymentContext deploymentContext)
         throws WSDLException, IOException, LoaderException {
         // Get the WSDL port namespace and name
         if (uri == null && endpoint != null) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to