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

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


  private WSDLDefinition aggregate(List<WSDLDefinition> definitions, ProcessorContext context) throws ContributionReadException {
        if (definitions == null || definitions.size() == 0) {
            return null;
        }
        if (definitions.size() == 1) {
            WSDLDefinition d = definitions.get(0);
            loadDefinition(d, context);
            return d;
        }
        WSDLDefinition aggregated = wsdlFactory.createWSDLDefinition();
        for (WSDLDefinition d : definitions) {
          loadDefinition(d, context);
        }
        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);
                // Deal with extensibility elements in the imported Definitions...
                List<ExtensibilityElement> extElements = (List<ExtensibilityElement>) d.getDefinition().getExtensibilityElements();
                for( ExtensibilityElement extElement : extElements ) {
                  facade.addExtensibilityElement(extElement);
                } // end for
            }
        }
        aggregated.setDefinition(facade);
        definitions.clear();
        definitions.add(aggregated);
        return aggregated;
    }
View Full Code Here


        return aggregated;
    }

    public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {

      WSDLDefinition resolved = null;
      String namespace = ((WSDLDefinition)unresolved).getNamespace();
      if (namespace == null) {
            return modelClass.cast(unresolved);
        }     
     
      // Lookup based on wsdli:location
      if (((WSDLDefinition)unresolved).getWsdliLocations().containsKey(namespace)) {
            try {
                loadDefinition(((WSDLDefinition)unresolved), context);
            } catch (ContributionReadException e) {
                context.getMonitor().error(context.getMonitor(), this, "interface-wsdlxml-validation-messages", "wsdliLocationException", e, ((WSDLDefinition)unresolved).getNamespace());
            }
            return modelClass.cast((WSDLDefinition)unresolved);
      }
     
     
      // Lookup a definition for the given namespace, from 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, context);
                  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, context);
                if (!resolved.isUnresolved()) {
                    return modelClass.cast(resolved);
                }
            }
        }
       
       
        // Not found, lookup a definition for the given namespace, within contribution
        List<WSDLDefinition> list = map.get(namespace);
        try {
          resolved = aggregate(list, context);
        } catch (ContributionReadException e) {
          throw new RuntimeException(e);
        }       
        if (resolved != null && !resolved.isUnresolved()) {
            // check that the WSDL we just found has the requisite
            // port type, binding and/or service. If not return
            // the input WSDL to force the resolution process to continue
            WSDLDefinition inputWSDL = (WSDLDefinition)unresolved;
            WSDLDefinition outputWSDL = (WSDLDefinition)resolved;
           
            if (inputWSDL.getNameOfPortTypeToResolve() != null){
                if (outputWSDL.getWSDLObject(PortType.class, inputWSDL.getNameOfPortTypeToResolve()) == null){
                    return modelClass.cast(unresolved);
                }
            }
           
            if (inputWSDL.getNameOfBindingToResolve() != null){
                if (outputWSDL.getWSDLObject(Binding.class, inputWSDL.getNameOfBindingToResolve()) == null){
                    return modelClass.cast(unresolved);
                }
            }
           
            if (inputWSDL.getNameOfServiceToResolve() != null){
                if (outputWSDL.getWSDLObject(Service.class, inputWSDL.getNameOfServiceToResolve()) == null){
                    return modelClass.cast(unresolved);
                }
            }           
           
            return modelClass.cast(resolved);
View Full Code Here

     * @param context
     * @throws ContributionReadException
     */
    private <T> T resolveImports (Class<T> modelClass, WSDLDefinition unresolved, ProcessorContext context) throws ContributionReadException {
     
      WSDLDefinition resolved = null;
      if (unresolved.getDefinition() == null && unresolved.getLocation() != null) {           
            try {
              // Load the definition using non-sca mechanism.
              List<WSDLDefinition> list = new ArrayList<WSDLDefinition>();
                list.add(unresolved);
                map.put(unresolved.getNamespace(), list);             
              resolved = aggregate(list, context);             
              // if no exception then its resolved.
              if (unresolved.getNamespace().equals(resolved.getDefinition().getTargetNamespace())) {
                resolved.setNamespace(resolved.getDefinition().getTargetNamespace());
                resolved.setUnresolved(false);
                resolved.setURI(resolved.getLocation());
                return modelClass.cast(resolved);
              }
            } catch (ContributionReadException e) {
              // Resolve the wsdl definition using the namespace, by searching the
              // contribution artifacts for wsdl definition for the given namespace.
              for (Artifact artifact : contribution.getArtifacts()) {
              if (artifact.getModel() instanceof WSDLDefinitionImpl) {
                String namespace = ((WSDLDefinitionImpl)artifact.getModel()).getNamespace();
                if (unresolved.getNamespace().equals(namespace)) {                 
                  WSDLDefinition wsdlDefinition = (WSDLDefinition)artifact.getModel();
                  if (wsdlDefinition.getDefinition() == null) {
                    loadDefinition(wsdlDefinition, context);
                  }
                            return modelClass.cast(wsdlDefinition);
                }
              }
View Full Code Here

        WSDLInterfaceContract wsdlContract = wsdlFactory.createWSDLInterfaceContract();
        WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface();
        wsdlContract.setInterface(wsdlInterface);

        WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition();
        JavaInterface iface = (JavaInterface)contract.getInterface();

        Definition def = null;
        try {
            Interface2WSDLGenerator wsdlGenerator =
                new Interface2WSDLGenerator(requiresSOAP12, resolver, dataBindings, xsdFactory, monitor);
            def = wsdlGenerator.generate(iface, wsdlDefinition);
        } catch (WSDLException e) {
            throw new WSDLGenerationException(e);
        }

        // for debugging
        if (printWSDL) {
            try {
                System.out.println("Generated WSDL for Java interface " + iface.getName() + " class " + iface.getJavaClass().getName());
                WSDLWriter writer =  javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter();
                writer.writeWSDL(def, System.out);
            } catch (WSDLException e) {
                throw new WSDLGenerationException(e);
            }
        }

        wsdlDefinition.setDefinition(def);
        wsdlInterface.setWsdlDefinition(wsdlDefinition);
        wsdlInterface.setRemotable(true);
        wsdlInterface.setConversational(contract.getInterface().isConversational());
        wsdlInterface.setUnresolved(false);
        wsdlInterface.setRemotable(true);
View Full Code Here

        String contractName = (contract instanceof CompositeService ? "$promoted$." : "") + contract.getName();
        */
        String contractName = contract.getName();

        List<Port> ports = new ArrayList<Port>();
        WSDLDefinition wsdlDefinition = wsBinding.getWSDLDefinition();
        if (wsdlDefinition == null) {
            error(monitor, "NoWsdlInterface", wsBinding, component.getName(), contract.getName());
            return null;
        }
        Definition def = wsdlDefinition.getDefinition();
        if (wsdlDefinition.getBinding() == null) {
            // The WSDL document was provided by the user.  Generate a new
            // WSDL document with imports from the user-provided document.
            WSDLFactory factory = null;
            try {
                factory = WSDLFactory.newInstance();
View Full Code Here

                                     WSDLDefinition wsdlDef,
                                     Definition newDef,
                                     List<WSDLDefinition> imports) {
        String namespace = name.getNamespaceURI();
        if (newDef.getImports(namespace) == null) {
            WSDLDefinition impDef = findDefinition(wsdlDef, name, type);
            if (impDef != null) {
                Import imp = newDef.createImport();
                imp.setNamespaceURI(namespace);
                imp.setLocationURI(impDef.getURI().toString());
                imp.setDefinition(impDef.getDefinition());
                newDef.addNamespace("ns" + imports.size(), namespace);
                newDef.addImport(imp);
                imports.add(impDef);
                return true;
            } else {
View Full Code Here

            if (types.get(name) != null) {
                return wsdlDef;
            }
        }
        for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) {
            WSDLDefinition d = findDefinition(impDef, name, type);
            if (d != null) {
                return d;
            }
        }
        return null;
View Full Code Here

        WSDLInterfaceContract wsdlIC = (WSDLInterfaceContract)getGeneratedWSDLContract(getComponentServiceInterfaceContract());
        if (wsdlIC == null) {
            return "";
        }
        WSDLInterface wsdl = (WSDLInterface)wsdlIC.getInterface();
        WSDLDefinition d = wsdl.getWsdlDefinition();
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        try {
            WSDLWriter writer = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter();
            writer.writeWSDL(d.getDefinition(), outStream);
        } catch (Exception e){
            throw new RuntimeException(e);
        }
        return outStream.toString();
    }
View Full Code Here

    @Test
    public void testWSDL() throws Exception {
      
        URL url = getClass().getResource("/wsdl/helloworld-service.wsdl");
        WSDLDefinition definition = processor.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 = processor.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

        documentProcessors = null;
    }

    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.