Author: jboynes
Date: Mon Apr 24 08:03:51 2006
New Revision: 396572

URL: http://svn.apache.org/viewcvs?rev=396572&view=rev
Log:
support wsdlLocation for interface.wsdl elements

Added:
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java
   (with props)
Modified:
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/LoaderContext.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/WSDLDefinitionRegistry.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoader.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/LoaderContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/LoaderContext.java?rev=396572&r1=396571&r2=396572&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/LoaderContext.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/LoaderContext.java
 Mon Apr 24 08:03:51 2006
@@ -19,15 +19,28 @@
 import org.apache.tuscany.common.resource.ResourceLoader;
 
 /**
+ * Context holder that can be used during the load process to store information
+ * that is not part of the logical model. This should be regarded as transient
+ * and references to this context should not be stored inside the model.
+ *
  * @version $Rev$ $Date$
  */
 public class LoaderContext {
     private final ResourceLoader resourceLoader;
 
+    /**
+     * Constructor specifying the loader for application resources.
+     *
+     * @param resourceLoader the loader for application resources
+     */
     public LoaderContext(ResourceLoader resourceLoader) {
         this.resourceLoader = resourceLoader;
     }
 
+    /**
+     * Returns a resource loader that can be used to load application 
resources.
+     * @return a resource loader that can be used to load application resources
+     */
     public ResourceLoader getResourceLoader() {
         return resourceLoader;
     }

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/WSDLDefinitionRegistry.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/WSDLDefinitionRegistry.java?rev=396572&r1=396571&r2=396572&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/WSDLDefinitionRegistry.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/WSDLDefinitionRegistry.java
 Mon Apr 24 08:03:51 2006
@@ -25,6 +25,8 @@
 import javax.wsdl.extensions.ExtensionRegistry;
 import javax.xml.namespace.QName;
 
+import org.apache.tuscany.common.resource.ResourceLoader;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -35,12 +37,23 @@
      * @param namespace the expected namespace, or null if any namespace 
should be allowed
      * @param location  the location to load the definition from
      * @return the loaded Definition
-     * @throws IOException if there was a problem reading the document
+     * @throws IOException   if there was a problem reading the document
      * @throws WSDLException if there was a problem parsing the definition
      */
     Definition loadDefinition(String namespace, URL location) throws 
IOException, WSDLException;
 
     /**
+     * Load and register a WSDL definition as specified in a WSDL2.0 
wsdlLocation attribute.
+     *
+     * @param wsdlLocation   the value of the wsdlLocation attribute
+     * @param resourceLoader application resource loader used to support 
relative locations
+     * @return the loaded Definition
+     * @throws IOException   if there was a problem reading the document
+     * @throws WSDLException if there was a problem parsing the definition
+     */
+    Definition loadDefinition(String wsdlLocation, ResourceLoader 
resourceLoader) throws IOException, WSDLException;
+
+    /**
      * Returns the PortType with the supplied qualified name, or null if no 
such port has been defined.
      *
      * @param name the qualified name of the WSDL portType
@@ -56,12 +69,12 @@
      */
     Service getService(QName name);
 
-    
+
     /**
      * Returns the ExtensionRegistry that is used when parsing WSDL documents 
during the
      * loadDefinition call.
-     * 
-     * @return the ExtensionRegistry that is used when parsing WSDL documents. 
      
+     *
+     * @return the ExtensionRegistry that is used when parsing WSDL documents.
      */
     ExtensionRegistry getExtensionRegistry();
 }

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoader.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoader.java?rev=396572&r1=396571&r2=396572&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoader.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoader.java
 Mon Apr 24 08:03:51 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.tuscany.core.loader.assembly;
 
+import java.io.IOException;
+
 import org.apache.tuscany.core.config.ConfigurationLoadException;
 import org.apache.tuscany.core.config.MissingInterfaceException;
 import org.apache.tuscany.core.loader.WSDLDefinitionRegistry;
@@ -29,12 +31,16 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.wsdl.PortType;
+import javax.wsdl.WSDLException;
 
 /**
  * @version $Rev$ $Date$
  */
 @org.osoa.sca.annotations.Scope("MODULE")
 public class InterfaceWSDLLoader extends AbstractLoader {
+    private static final String WSDLI = 
"http://www.w3.org/2006/01/wsdl-instance";;
+    private static final String WSDLI_LOCATION = "wsdlLocation";
+
     private WSDLDefinitionRegistry wsdlRegistry;
 
     @Autowire
@@ -50,6 +56,17 @@
         assert AssemblyConstants.INTERFACE_WSDL.equals(reader.getName());
         WSDLServiceContract serviceContract = 
factory.createWSDLServiceContract();
         serviceContract.setScope(Scope.INSTANCE);
+
+        String location = reader.getAttributeValue(WSDLI, WSDLI_LOCATION);
+        if (location != null) {
+            try {
+                wsdlRegistry.loadDefinition(location, 
loaderContext.getResourceLoader());
+            } catch (IOException e) {
+                throw new MissingInterfaceException(e);
+            } catch (WSDLException e) {
+                throw new MissingInterfaceException(e);
+            }
+        }
 
         String portTypeURI = reader.getAttributeValue(null, "interface");
         if (portTypeURI != null) {

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java?rev=396572&r1=396571&r2=396572&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
 Mon Apr 24 08:03:51 2006
@@ -18,6 +18,8 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -31,9 +33,9 @@
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
 
-import org.osoa.sca.annotations.Scope;
-
+import org.apache.tuscany.common.resource.ResourceLoader;
 import org.apache.tuscany.core.loader.WSDLDefinitionRegistry;
+import org.osoa.sca.annotations.Scope;
 
 /**
  * @version $Rev$ $Date$
@@ -61,6 +63,30 @@
 
     public ExtensionRegistry getExtensionRegistry() {
         return registry;
+    }
+
+    public Definition loadDefinition(String wsdlLocation, ResourceLoader 
resourceLoader) throws IOException, WSDLException {
+        int index = wsdlLocation.indexOf(' ');
+        if (index == -1) {
+            throw new WSDLException(WSDLException.CONFIGURATION_ERROR, 
"Invalid wsdlLocation: " + wsdlLocation);
+        }
+        String namespace = wsdlLocation.substring(0, index).trim();
+        URL url;
+        URI uri;
+        try {
+            uri = new URI(wsdlLocation.substring(index + 1).trim());
+        } catch (URISyntaxException e) {
+            throw new WSDLException(WSDLException.CONFIGURATION_ERROR, 
"Invalid wsdlLocation: " + wsdlLocation);
+        }
+        if (uri.isAbsolute()) {
+            url = uri.toURL();
+        } else {
+            url = resourceLoader.getResource(uri.toString());
+            if (url == null) {
+                throw new WSDLException(WSDLException.CONFIGURATION_ERROR, 
"Resource not found: " + uri);
+            }
+        }
+        return loadDefinition(namespace, url);
     }
 
     public Definition loadDefinition(String namespace, URL location) throws 
IOException, WSDLException {

Modified: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java?rev=396572&r1=396571&r2=396572&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java
 Mon Apr 24 08:03:51 2006
@@ -41,8 +41,22 @@
         assertNotNull(sc);
     }
 
-    public void testInterface() throws XMLStreamException, 
ConfigurationLoadException {
+    public void testInterface() throws Exception {
+        wsdlRegistry.loadDefinition("http://www.example.org";, 
getClass().getResource("example.wsdl"));
         String xml = "<interface.wsdl 
xmlns='http://www.osoa.org/xmlns/sca/0.9' 
interface='http://www.example.org#HelloWorld'></interface.wsdl>";
+        XMLStreamReader reader = getReader(xml);
+        WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, 
loaderContext);
+        reader.require(XMLStreamConstants.END_ELEMENT, 
INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart());
+        assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next());
+        assertNotNull(sc);
+    }
+
+    public void testInterfaceWithLocation() throws Exception {
+        wsdlRegistry.loadDefinition("http://www.example.org";, 
getClass().getResource("example.wsdl"));
+        String xml = "<interface.wsdl 
xmlns='http://www.osoa.org/xmlns/sca/0.9' 
xmlns:wsdli='http://www.w3.org/2006/01/wsdl-instance' " +
+                "wsdli:wsdlLocation='http://www.example.org " + 
getClass().getResource("example.wsdl") + "' "+
+                "interface='http://www.example.org#HelloWorld'"+
+                "></interface.wsdl>";
         XMLStreamReader reader = getReader(xml);
         WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, 
loaderContext);
         reader.require(XMLStreamConstants.END_ELEMENT, 
INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart());

Added: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java
URL: 
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java?rev=396572&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java
 (added)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java
 Mon Apr 24 08:03:51 2006
@@ -0,0 +1,76 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tuscany.core.loader.assembly;
+
+import java.net.URL;
+import java.io.IOException;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.loader.impl.WSDLDefinitionRegistryImpl;
+import org.apache.tuscany.common.resource.ResourceLoader;
+import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WSDLDefinitionRegistryTestCase extends TestCase {
+    private static final String NS = "http://www.example.org";;
+    private WSDLDefinitionRegistryImpl wsdlRegistry;
+    private ResourceLoader rl;
+
+
+    public void testLoadFromAbsoluteWSDLLocation() {
+        try {
+            Definition def = wsdlRegistry.loadDefinition(NS + ' ' + 
rl.getResource("org/apache/tuscany/core/loader/assembly/example.wsdl"), rl);
+            assertNotNull(def.getPortType(new QName(NS, "HelloWorld")));
+        } catch (IOException e) {
+            fail(e.getMessage());
+        } catch (WSDLException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    public void testLoadFromRelativeWSDLLocation() {
+        try {
+            Definition def = wsdlRegistry.loadDefinition(NS + " 
org/apache/tuscany/core/loader/assembly/example.wsdl", rl);
+            assertNotNull(def.getPortType(new QName(NS, "HelloWorld")));
+        } catch (IOException e) {
+            fail(e.getMessage());
+        } catch (WSDLException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        wsdlRegistry = new WSDLDefinitionRegistryImpl();
+        wsdlRegistry.setMonitor(NULL_MONITOR);
+        rl = new ResourceLoaderImpl(getClass().getClassLoader());
+    }
+
+    private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new 
WSDLDefinitionRegistryImpl.Monitor() {
+        public void readingWSDL(String namespace, URL location) {
+        }
+
+        public void cachingDefinition(String namespace, URL location) {
+        }
+    };
+}

Propchange: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date


Reply via email to