You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/02/21 02:20:08 UTC

svn commit: r509856 - in /incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src: main/java/org/apache/tuscany/idl/wsdl/ test/java/org/apache/tuscany/idl/wsdl/ test/resources/org/apache/tuscany/idl/wsdl/

Author: rfeng
Date: Tue Feb 20 17:20:07 2007
New Revision: 509856

URL: http://svn.apache.org/viewvc?view=rev&rev=509856
Log:
[sca-integration-bracnh] Add WSDL and XSD contribution processors

Added:
    incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl
    incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl

Added: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java?view=auto&rev=509856
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java Tue Feb 20 17:20:07 2007
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.idl.wsdl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLLocator;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry;
+import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
+import org.xml.sax.InputSource;
+
+/**
+ * The WSDL processor
+ * @version $Rev$ $Date$
+ */
+public class WSDLContributionProcessor extends ContributionProcessorExtension {
+
+    private final WSDLFactory wsdlFactory;
+
+    private final ExtensionRegistry extensionRegistry;
+
+    private final Map<String, List<Definition>> definitionsByNamespace = new HashMap<String, List<Definition>>();
+
+    private Monitor monitor;
+
+    private XMLSchemaRegistry schemaRegistry;
+
+    private ArtifactResolverRegistry artifactResolverRegistry;
+
+    public WSDLContributionProcessor() throws WSDLException {
+        wsdlFactory = WSDLFactory.newInstance();
+        extensionRegistry = wsdlFactory.newPopulatedExtensionRegistry();
+    }
+
+    @Autowire
+    public void setSchemaRegistry(XMLSchemaRegistry schemaRegistry) {
+        this.schemaRegistry = schemaRegistry;
+    }
+
+    @org.apache.tuscany.api.annotation.Monitor
+    public void setMonitor(Monitor monitor) {
+        this.monitor = monitor;
+    }
+
+    public ExtensionRegistry getExtensionRegistry() {
+        return extensionRegistry;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Definition loadDefinition(Contribution contribution, String namespace, URI location, InputStream inputStream)
+        throws IOException, WSDLException, DeploymentException {
+        if (monitor != null) {
+            monitor.readingWSDL(namespace, location);
+        }
+
+        WSDLReader reader = wsdlFactory.newWSDLReader();
+        reader.setFeature("javax.wsdl.verbose", false);
+        reader.setExtensionRegistry(extensionRegistry);
+
+        WSDLLocatorImpl locator = new WSDLLocatorImpl(contribution.getUri(), location, inputStream);
+        Definition definition = reader.readWSDL(locator);
+        String definitionNamespace = definition.getTargetNamespace();
+        if (namespace != null && !namespace.equals(definitionNamespace)) {
+            throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != "
+                + definition.getTargetNamespace());
+        }
+
+        // Load inline schemas
+        registry.processModel(contribution, location, definition);
+        for (Object i : definition.getImports().values()) {
+            List<Import> imps = (List<Import>)i;
+            for (Import imp : imps) {
+                Definition imported = imp.getDefinition();
+                if (imported != null) {
+                    // TODO: 
+                    registry.processModel(contribution, URI.create(imp.getDefinition().getDocumentBaseURI()), definition);
+                }
+            }
+        }
+
+        if (monitor != null) {
+            monitor.cachingDefinition(definitionNamespace, location);
+        }
+        List<Definition> definitions = definitionsByNamespace.get(definitionNamespace);
+        if (definitions == null) {
+            definitions = new ArrayList<Definition>();
+            definitionsByNamespace.put(definitionNamespace, definitions);
+        }
+        definitions.add(definition);
+
+        DeployedArtifact artifact = contribution.getArtifact(location);
+        artifact.addModelObject(Definition.class, definition.getTargetNamespace(), definition);
+
+        return definition;
+    }
+
+    public PortType getPortType(QName name) {
+        String namespace = name.getNamespaceURI();
+        List<Definition> definitions = definitionsByNamespace.get(namespace);
+        if (definitions == null) {
+            return null;
+        }
+        for (Definition definition : definitions) {
+            PortType portType = definition.getPortType(name);
+            if (portType != null) {
+                return portType;
+            }
+        }
+        return null;
+    }
+
+    public Service getService(QName name) {
+        String namespace = name.getNamespaceURI();
+        List<Definition> definitions = definitionsByNamespace.get(namespace);
+        if (definitions == null) {
+            return null;
+        }
+        for (Definition definition : definitions) {
+            Service service = definition.getService(name);
+            if (service != null) {
+                return service;
+            }
+        }
+        return null;
+    }
+
+    public static interface Monitor {
+        /**
+         * Monitor event emitted immediately before an attempt is made to read
+         * WSDL for the supplied namespace from the supplied location.
+         * 
+         * @param namespace the target namespace expected in the WSDL; may be
+         *            null
+         * @param location the location where we will attempt to read the WSDL
+         *            definition from
+         */
+        void readingWSDL(String namespace, URI location);
+
+        /**
+         * Monitor event emitted immediately before registering a WSDL
+         * definition in the cache.
+         * 
+         * @param namespace the target namespace for the WSDL
+         * @param location the location where the WSDL definition was read from
+         */
+        void cachingDefinition(String namespace, URI location);
+    }
+
+    public XMLSchemaRegistry getSchemaRegistry() {
+        if (schemaRegistry == null) {
+            // Default
+            schemaRegistry = new XMLSchemaRegistryImpl();
+        }
+        return schemaRegistry;
+    }
+
+    public class WSDLLocatorImpl implements WSDLLocator {
+        private URI contribution;
+        private InputStream inputStream;
+        private String baseURI;
+        private URI latestImportURI;
+
+        public WSDLLocatorImpl(URI contribution, URI baseURI, InputStream is) {
+            this.contribution = contribution;
+            this.baseURI = baseURI.toString();
+            this.inputStream = is;
+        }
+
+        public void close() {
+            // inputStream.close();
+        }
+
+        public InputSource getBaseInputSource() {
+            return new InputSource(inputStream);
+        }
+
+        public String getBaseURI() {
+            return baseURI;
+        }
+
+        public InputSource getImportInputSource(String parentLocation, String importLocation) {
+            try {
+                URL url = artifactResolverRegistry.resolve(contribution, null, importLocation, parentLocation);
+                latestImportURI = url.toURI();
+                return new InputSource(url.openStream());
+            } catch (Exception e) {
+                e.printStackTrace();
+                return null;
+            }
+        }
+
+        public String getLatestImportURI() {
+            return latestImportURI.toString();
+        }
+
+    }
+
+    public String getContentType() {
+        return "application/vnd.tuscany.wsdl";
+    }
+
+    /**
+     * @param artifactResolverRegistry the artifactResolverRegistry to set
+     */
+    @Autowire
+    public void setArtifactResolverRegistry(ArtifactResolverRegistry artifactResolverRegistry) {
+        this.artifactResolverRegistry = artifactResolverRegistry;
+    }
+
+    public void processContent(Contribution contribution, URI source, InputStream inputStream)
+        throws DeploymentException, IOException {
+        try {
+            loadDefinition(contribution, null, source, inputStream);
+        } catch (WSDLException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } 
+    }
+
+    public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+        IOException {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java?view=auto&rev=509856
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java Tue Feb 20 17:20:07 2007
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.idl.wsdl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URL;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Types;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.schema.Schema;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry;
+import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaException;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+
+/**
+ * The XSD processor
+ * 
+ * @version $Rev$ $Date$
+ */
+public class XSDContributionProcessor extends ContributionProcessorExtension {
+
+    private ArtifactResolverRegistry artifactResolverRegistry;
+
+    public XSDContributionProcessor() throws WSDLException {
+    }
+
+    /**
+     * URI resolver implementation for xml schema
+     */
+    protected class URIResolverImpl implements URIResolver {
+        private URI contribution;
+
+        public URIResolverImpl(URI contriution) {
+            this.contribution = contriution;
+        }
+
+        public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace,
+                                                     java.lang.String schemaLocation,
+                                                     java.lang.String baseUri) {
+            try {
+                URL url = artifactResolverRegistry.resolve(contribution, targetNamespace, schemaLocation, baseUri);
+                return new InputSource(url.openStream());
+            } catch (IOException e) {
+                return null;
+            }
+        }
+
+    }
+
+    @SuppressWarnings("unchecked")
+    public XmlSchema loadSchema(Contribution contribution, String namespace, URI location, InputStream inputStream)
+        throws IOException, DeploymentException {
+        XmlSchemaCollection collection = new XmlSchemaCollection();
+        collection.setSchemaResolver(new URIResolverImpl(contribution.getUri()));
+        XmlSchema schema = collection.read(new InputStreamReader(inputStream), null);
+
+        if (namespace != null && schema != null && !namespace.equals(schema.getTargetNamespace())) {
+            throw new XmlSchemaException(namespace + " != " + schema.getTargetNamespace());
+        }
+
+        DeployedArtifact artifact = contribution.getArtifact(location);
+        artifact.addModelObject(XmlSchema.class, schema.getTargetNamespace(), schema);
+        return schema;
+    }
+
+    public void loadSchemas(Contribution contribution, URI source, Definition definition) {
+        Types types = definition.getTypes();
+        if (types != null) {
+            DeployedArtifact artifact = contribution.getArtifact(source);
+            XmlSchemaCollection collection = new XmlSchemaCollection();
+            for (Object ext : types.getExtensibilityElements()) {
+                if (ext instanceof Schema) {
+                    Element element = ((Schema)ext).getElement();
+                    XmlSchema s = collection.read(element, element.getBaseURI());
+                    artifact.addModelObject(XmlSchema.class, s.getTargetNamespace(), s);
+                }
+            }
+        }
+    }
+
+    public String getContentType() {
+        return "application/vnd.tuscany.xsd";
+    }
+
+    /**
+     * @param artifactResolverRegistry the artifactResolverRegistry to set
+     */
+    @Autowire
+    public void setArtifactResolverRegistry(ArtifactResolverRegistry artifactResolverRegistry) {
+        this.artifactResolverRegistry = artifactResolverRegistry;
+    }
+
+    public void processContent(Contribution contribution, URI source, InputStream inputStream)
+        throws DeploymentException, IOException {
+        loadSchema(contribution, null, source, inputStream);
+    }
+
+    public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+        IOException {
+        if (modelObject instanceof Definition) {
+            loadSchemas(contribution, source, (Definition)modelObject);
+        }
+    }
+
+}

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java?view=auto&rev=509856
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java Tue Feb 20 17:20:07 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.idl.wsdl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+
+import java.net.URI;
+import java.net.URL;
+
+import javax.wsdl.Definition;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WSDLContributionProcessorTestCase extends TestCase {
+    private WSDLContributionProcessor processor;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        processor = new WSDLContributionProcessor();
+        ArtifactResolverRegistry registry = createMock(ArtifactResolverRegistry.class);
+        URL url = getClass().getResource("test2.wsdl");
+        expect(registry.resolve(isA(URI.class),
+                                (String)isNull(),
+                                isA(String.class),
+                                isA(String.class))).andReturn(url).anyTimes();
+        processor.setArtifactResolverRegistry(registry);
+        replay(registry);
+
+        ContributionProcessorRegistry processorRegistry = createMock(ContributionProcessorRegistry.class);
+        processorRegistry.processModel(isA(Contribution.class), isA(URI.class), isA(Definition.class));
+        expectLastCall().anyTimes();
+        replay(processorRegistry);
+        processor.setContributionProcessorRegistry(processorRegistry);
+    }
+
+    public void testLoad() throws Exception {
+        URI uri = URI.create("sca://contribution/001");
+        Contribution contribution = new Contribution(uri);
+
+        addArtifact(contribution, "sca://contribution/001/test1.wsdl");
+        addArtifact(contribution, "sca://contribution/001/test2.wsdl");
+        addArtifact(contribution, "sca://contribution/001/ipo.xsd");
+
+        URL url = getClass().getResource("test1.wsdl");
+        try {
+            processor.processContent(contribution, URI.create("sca://contribution/001/test1.wsdl"), url.openStream());
+        } catch (Throwable e) {
+            fail(e.getMessage());
+        }
+    }
+
+    private DeployedArtifact addArtifact(Contribution contribution, String artifact) {
+        DeployedArtifact a1 = new DeployedArtifact(URI.create(artifact));
+        contribution.addArtifact(a1);
+        return a1;
+    }
+}

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java?view=auto&rev=509856
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java Tue Feb 20 17:20:07 2007
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.idl.wsdl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+
+import javax.wsdl.Definition;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaImport;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XSDContributionProcessorTestCase extends TestCase {
+    private XSDContributionProcessor processor;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        processor = new XSDContributionProcessor();
+        ArtifactResolverRegistry registry = createMock(ArtifactResolverRegistry.class);
+        URL url = getClass().getResource("ipo.xsd");
+        expect(registry.resolve(isA(URI.class), isA(String.class), isA(String.class), (String)isNull())).andReturn(url)
+            .anyTimes();
+        processor.setArtifactResolverRegistry(registry);
+        replay(registry);
+
+        ContributionProcessorRegistry processorRegistry = createMock(ContributionProcessorRegistry.class);
+        processorRegistry.processModel(isA(Contribution.class), isA(URI.class), isA(Definition.class));
+        replay(processorRegistry);
+        processor.setContributionProcessorRegistry(processorRegistry);
+    }
+
+    public void testLoad() throws Exception {
+        URI uri = URI.create("sca://contribution/001");
+        Contribution contribution = new Contribution(uri);
+
+        URI a1 = URI.create("sca://contribution/001/test1.xsd");
+        addArtifact(contribution, a1);
+        URI a2 = URI.create("sca://contribution/001/ipo.xsd");
+        addArtifact(contribution, a2);
+
+        URL url = getClass().getResource("test1.xsd");
+        processor.processContent(contribution, new URI("sca://contribution/001/test1.xsd"), url.openStream());
+        DeployedArtifact da1 = contribution.getArtifact(a1);
+        Map<String, Object> schemas = da1.getModelObjects(XmlSchema.class);
+        assertEquals(1, schemas.size());
+        assertTrue(schemas.containsKey("http://www.example.com/Customer"));
+        XmlSchema schema = (XmlSchema) schemas.values().iterator().next();
+        XmlSchemaObjectCollection includes = schema.getIncludes();
+        assertEquals(1, includes.getCount());
+        XmlSchemaImport imported = (XmlSchemaImport) includes.getItem(0);
+        assertEquals("http://www.example.com/IPO", imported.getSchema().getTargetNamespace());
+    }
+
+    private DeployedArtifact addArtifact(Contribution contribution, URI artifact) {
+        DeployedArtifact a1 = new DeployedArtifact(artifact);
+        contribution.addArtifact(a1);
+        return a1;
+    }
+}

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl?view=auto&rev=509856
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl Tue Feb 20 17:20:07 2007
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * Licensed to the Apache Software Foundation (ASF) under one
+    * or more contributor license agreements.  See the NOTICE file
+    * distributed with this work for additional information
+    * regarding copyright ownership.  The ASF licenses this file
+    * to you 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.    
+-->
+<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld"
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="helloworld">
+
+    <wsdl:import location="test2.wsdl" namespace="http://helloworld"></wsdl:import>
+
+    <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld">
+        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
+        <wsdl:operation name="getGreetings">
+            <wsdlsoap:operation soapAction="" />
+            <wsdl:input name="getGreetingsRequest">
+                <wsdlsoap:body use="literal" />
+            </wsdl:input>
+            <wsdl:output name="getGreetingsResponse">
+                <wsdlsoap:body use="literal" />
+            </wsdl:output>
+        </wsdl:operation>
+    </wsdl:binding>
+
+    <wsdl:service name="HelloWorldService">
+        <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort">
+            <wsdlsoap:address location="http://localhost:8080/sample-helloworldws-1.0-SNAPSHOT/services/HelloWorldWebService" />
+        </wsdl:port>
+    </wsdl:service>
+
+</wsdl:definitions>

Added: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd?view=auto&rev=509856
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd Tue Feb 20 17:20:07 2007
@@ -0,0 +1,15 @@
+<schema targetNamespace="http://www.example.com/Customer" xmlns="http://www.w3.org/2001/XMLSchema"
+    xmlns:ipo="http://www.example.com/IPO" xmlns:tns="http://www.example.com/Customer">
+    <import namespace="http://www.example.com/IPO" schemaLocation="ipo.xsd" />
+
+    <complexType name="Customer">
+        <sequence>
+            <element name="customerID" type="string"></element>
+            <element name="name" type="string"></element>
+            <element name="order" type="ipo:PurchaseOrderType" />
+        </sequence>
+    </complexType>
+    <element name="customer" type="tns:Customer"></element>
+
+</schema>
+

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl?view=auto&rev=509856
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl Tue Feb 20 17:20:07 2007
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * Licensed to the Apache Software Foundation (ASF) under one
+    * or more contributor license agreements.  See the NOTICE file
+    * distributed with this work for additional information
+    * regarding copyright ownership.  The ASF licenses this file
+    * to you 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.    
+-->
+<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld"
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="helloworld">
+
+    <wsdl:types>
+        <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns="http://www.w3.org/2001/XMLSchema">
+
+            <import namespace="http://www.example.com/IPO" schemaLocation="ipo.xsd" />
+
+            <element name="getGreetings">
+                <complexType>
+                    <sequence>
+                        <element name="name" type="xsd:string" />
+                    </sequence>
+                </complexType>
+            </element>
+
+            <element name="getGreetingsResponse">
+                <complexType>
+                    <sequence>
+                        <element name="getGreetingsReturn" type="xsd:string" />
+                    </sequence>
+                </complexType>
+            </element>
+
+        </schema>
+    </wsdl:types>
+
+    <wsdl:message name="getGreetingsRequest">
+        <wsdl:part element="tns:getGreetings" name="parameters" />
+    </wsdl:message>
+
+    <wsdl:message name="getGreetingsResponse">
+        <wsdl:part element="tns:getGreetingsResponse" name="parameters" />
+    </wsdl:message>
+
+    <wsdl:portType name="HelloWorld">
+        <wsdl:operation name="getGreetings">
+            <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest" />
+            <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse" />
+        </wsdl:operation>
+    </wsdl:portType>
+
+</wsdl:definitions>



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