Package org.apache.tuscany.sca.interfacedef.wsdl

Examples of org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition


       }       
     }

    public WSDLDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException {
        try {
            WSDLDefinition definition = indexRead(artifactURL);
            definition.setURI(artifactURI);
            return definition;
        } catch (Exception e) {
          ContributionReadException ce = new ContributionReadException(e);
          error("ContributionReadException", artifactURL, ce);
            //throw ce;
View Full Code Here


                        continue;
                    }
                    if (imp.getLocationURI() == null) {
                        // FIXME: [rfeng] By the WSDL 1.1 Specification, the location attribute is required
                        // We need to resolve it by QName
                        WSDLDefinition proxy = factory.createWSDLDefinition();
                        proxy.setUnresolved(true);
                        proxy.setNamespace(imp.getNamespaceURI());
                        WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy);
                        if (resolved != null && !resolved.isUnresolved()) {
                            imp.setDefinition(resolved.getDefinition());
                            if (!model.getImportedDefinitions().contains(resolved)) {
                                model.getImportedDefinitions().add(resolved);
                            }
                        }
                    } else {
                        String location = imp.getLocationURI();
                        URI uri = URI.create(location);
                        if (uri.isAbsolute()) {
                            WSDLDefinition resolved;
                            try {
                                resolved = read(null, uri, uri.toURL());
                                imp.setDefinition(resolved.getDefinition());
                                if (!model.getImportedDefinitions().contains(resolved)) {
                                    model.getImportedDefinitions().add(resolved);
                                }
                            } catch (Exception e) {
                              ContributionResolveException ce = new ContributionResolveException(e);
                              error("ContributionResolveException", resolver, ce);
                                //throw ce;
                            }
                        } else {
                            if (location.startsWith("/")) {
                                // This is a relative URI against a contribution
                                location = location.substring(1);
                                // TODO: Need to resolve it against the contribution
                            } else {
                                // This is a relative URI against the WSDL document
                                URI baseURI = URI.create(model.getDefinition().getDocumentBaseURI());
                                URI locationURI = baseURI.resolve(location);
                                WSDLDefinition resolved;
                                try {
                                    resolved = read(null, locationURI, locationURI.toURL());
                                    imp.setDefinition(resolved.getDefinition());
                                    if (!model.getImportedDefinitions().contains(resolved)) {
                                        model.getImportedDefinitions().add(resolved);
                                    }
                                } catch (Exception e) {
                                  ContributionResolveException ce = new ContributionResolveException(e);
View Full Code Here

     * @return
     * @throws IOException
     * @throws XMLStreamException
     */
    protected WSDLDefinition indexRead(URL doc) throws Exception {
        WSDLDefinition wsdlDefinition = factory.createWSDLDefinition();
        wsdlDefinition.setUnresolved(true);
        wsdlDefinition.setLocation(doc.toURI());

        InputStream is = doc.openStream();
        try {
            XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
            int eventType = reader.getEventType();
            int index = 0;
            while (true) {
                if (eventType == XMLStreamConstants.START_ELEMENT) {
                    if (WSDL11.equals(reader.getName())) {
                        String tns = reader.getAttributeValue(null, "targetNamespace");
                        wsdlDefinition.setNamespace(tns);
                        // The definition is marked as resolved but not loaded
                        wsdlDefinition.setUnresolved(false);
                        wsdlDefinition.setDefinition(null);
                    }
                    if (XSD.equals(reader.getName())) {
                        String tns = reader.getAttributeValue(null, "targetNamespace");
                        XSDefinition xsd = xsdFactory.createXSDefinition();
                        xsd.setUnresolved(true);
                        xsd.setNamespace(tns);
                        xsd.setLocation(URI.create(doc.toURI() + "#" + index));
                        index++;
                        // The definition is marked as resolved but not loaded
                        xsd.setUnresolved(false);
                        xsd.setSchema(null);
                        wsdlDefinition.getXmlSchemas().add(xsd);
                    }
                }
                if (reader.hasNext()) {
                    eventType = reader.next();
                } else {
View Full Code Here

        }

    }

    public void addModel(Object resolved) {
        WSDLDefinition definition = (WSDLDefinition)resolved;
        for (XSDefinition d : definition.getXmlSchemas()) {
            if (contribution != null) {
                contribution.getModelResolver().addModel(d);
            }
        }
        List<WSDLDefinition> list = map.get(definition.getNamespace());
        if (list == null) {
            list = new ArrayList<WSDLDefinition>();
            map.put(definition.getNamespace(), list);
        }
        list.add(definition);
    }
View Full Code Here

        }
        list.add(definition);
    }

    public Object removeModel(Object resolved) {
        WSDLDefinition definition = (WSDLDefinition)resolved;
        List<WSDLDefinition> list = map.get(definition.getNamespace());
        if (list == null) {
            return null;
        } else {
            return list.remove(definition);
        }
View Full Code Here

    private WSDLDefinition aggregate(List<WSDLDefinition> definitions) {
        if (definitions == null || definitions.size() == 0) {
            return null;
        }
        if (definitions.size() == 1) {
            WSDLDefinition d = definitions.get(0);
            loadOnDemand(d);
            return d;
        }
        WSDLDefinition aggregated = wsdlFactory.createWSDLDefinition();
        for (WSDLDefinition d : definitions) {
            loadOnDemand(d);
        }
        Definition facade = wsdl4jFactory.newDefinition();
        String ns = definitions.get(0).getNamespace();
        facade.setQName(new QName(ns, "$aggregated$"));
        facade.setTargetNamespace(ns);

        for (WSDLDefinition d : definitions) {
            if (d.getDefinition() != null) {
                javax.wsdl.Import imp = facade.createImport();
                imp.setNamespaceURI(d.getNamespace());
                imp.setDefinition(d.getDefinition());
                imp.setLocationURI(d.getDefinition().getDocumentBaseURI());
                facade.addImport(imp);
                aggregated.getXmlSchemas().addAll(d.getXmlSchemas());
                aggregated.getImportedDefinitions().add(d);
            }
        }
        aggregated.setDefinition(facade);
        definitions.clear();
        definitions.add(aggregated);
        return aggregated;
    }
View Full Code Here

        String namespace = ((WSDLDefinition)unresolved).getNamespace();
        if (namespace == null) {
            return modelClass.cast(unresolved);
        }
        List<WSDLDefinition> list = map.get(namespace);
        WSDLDefinition resolved = aggregate(list);
        if (resolved != null && !resolved.isUnresolved()) {
            return modelClass.cast(resolved);
        }

        // No definition found, delegate the resolution to the imports
        for (Import import_ : this.contribution.getImports()) {
            if (import_ instanceof NamespaceImport) {
                NamespaceImport namespaceImport = (NamespaceImport)import_;
                if (namespaceImport.getNamespace().equals(namespace)) {

                    // Delegate the resolution to the namespace import resolver
                    resolved =
                        namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class,
                                                                        (WSDLDefinition)unresolved);
                    if (!resolved.isUnresolved()) {
                        return modelClass.cast(resolved);
                    }
                }
            } else if (import_ instanceof DefaultImport) {
               
                // Delegate the resolution to the default import resolver
                resolved =
                    import_.getModelResolver().resolveModel(WSDLDefinition.class,
                                                                    (WSDLDefinition)unresolved);
                if (!resolved.isUnresolved()) {
                    return modelClass.cast(resolved);
                }
            }
        }
        return modelClass.cast(unresolved);
View Full Code Here

            // If this definition imports any definitions from other namespaces,
            // set the correct WSDLDefinition import relationships.
            for (Map.Entry<String, List<javax.wsdl.Import>> entry :
                    ((Map<String, List<javax.wsdl.Import>>)definition.getImports()).entrySet()) {
                if (!entry.getKey().equals(definition.getTargetNamespace())) {
                    WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition();
                    wsdlDefinition.setUnresolved(true);
                    wsdlDefinition.setNamespace(entry.getKey());
                    WSDLDefinition resolved = resolveModel(WSDLDefinition.class, wsdlDefinition);
                    if (!resolved.isUnresolved()) {
                        for (javax.wsdl.Import imp : entry.getValue()) {
                            if (resolved.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) {
                                // this WSDLDefinition contains the imported document
                                wsdlDef.getImportedDefinitions().add(resolved);
                            } else {
                                // this is a facade, so look in its imported definitions
                                for (WSDLDefinition def : resolved.getImportedDefinitions()) {
                                    if (def.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) {
                                        wsdlDef.getImportedDefinitions().add(def);
                                        break;
                                    }
                                }
View Full Code Here

    @Test
    public void testWSDL() throws Exception {
      
        URL url = getClass().getResource("/wsdl/helloworld-service.wsdl");
        WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, URI.create("wsdl/helloworld-service.wsdl"), url);
       
        Assert.assertNull(definition.getDefinition());
        Assert.assertEquals("http://helloworld", definition.getNamespace());
        URL url1 = getClass().getResource("/wsdl/helloworld-interface.wsdl");
        WSDLDefinition definition1 = (WSDLDefinition)documentProcessor.read(null, URI.create("wsdl/helloworld-interface.wsdl"), url1);
        Assert.assertNull(definition1.getDefinition());
        Assert.assertEquals("http://helloworld", definition1.getNamespace());

        resolver.addModel(definition);
        resolver.addModel(definition1);
        resolver.resolveModel(WSDLDefinition.class, definition);
        resolver.resolveModel(WSDLDefinition.class, definition1);
        WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, definition);
        List imports = (List)definition.getDefinition().getImports().get("http://helloworld");
        Assert.assertNotNull(imports);
        Assert.assertNotNull(((Import)imports.get(0)).getDefinition());
        Assert.assertNotNull(resolved.getDefinition().getPortType(new QName("http://helloworld", "HelloWorld")));
        Assert.assertNotNull(resolved.getDefinition().getService(new QName("http://helloworld", "HelloWorldService")));
       
        assertNotNull(resolved.getXmlSchemaType(new QName("http://greeting", "Name")));
    }
View Full Code Here

    }

    @Test
    public void testReadWSDLDocument() throws Exception {
        URL url = getClass().getResource("example.wsdl");
        WSDLDefinition definition = documentProcessor.read(null, new URI("example.wsdl"), url, WSDLDefinition.class);
        assertNotNull(definition);
        assertNull(definition.getDefinition());
        assertEquals(definition.getNamespace(), "http://www.example.org");
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.