Package org.apache.tuscany.sca.assembly

Examples of org.apache.tuscany.sca.assembly.Composite


    }

    private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
        try {
            AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
            Composite composite = assemblyFactory.createComposite();
            composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
            RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
            component.setName("default");
            component.setURI("default");
            runtime.getCompositeActivator().configureComponentContext(component);
            composite.getComponents().add(component);
            RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
            reference.setName("default");
            ModelFactoryExtensionPoint factories =
                runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
            JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
View Full Code Here


                     bos.toString());
    }

    public void testReadWriteComposite() throws Exception {
        InputStream is = getClass().getResourceAsStream("/Calculator.composite");
        Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is));
        assertNotNull(composite);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos));
        assertEquals("<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\"><binding.sca /></service><component name=\"CalculatorServiceComponent\"><reference name=\"addService\" target=\"AddServiceComponent\"><binding.sca /></reference><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\"><service><binding.sca /></service></component><component name=\"SubtractServiceComponent\" /><component name=\"MultiplyServiceComponent\" /><component name=\"DivideServiceComponent\" /></composite>",
            bos.toString() );
View Full Code Here

                        compositeArtifacts.put(artifact.getURI(), (Composite)artifact.getModel());
                    }
                }
            }
            for (String compositePath : composites) {
                Composite composite = compositeArtifacts.get(compositePath);
                if (composite == null) {
                    throw new ServiceRuntimeException("Composite not found: " + compositePath);
                }
                domainComposite.getIncludes().add(composite);
            }
        } else {
            // in this case, a sca-contribution.xml should have been specified
            for (Contribution contribution : contributions) {
                for (Composite composite : contribution.getDeployables()) {
                    domainComposite.getIncludes().add(composite);
                }
            }
        }

        //update the runtime for all SCA Definitions processed from the contribution..
        //so that the policyset determination done during 'build' has the all the defined
        //intents and policysets
        //runtime.updateSCADefinitions(null);

        // Build the SCA composites
        for (Composite composite : domainComposite.getIncludes()) {
            try {
                runtime.buildComposite(composite);
                analyseProblems();
            } catch (CompositeBuilderException e) {
                throw new ServiceRuntimeException(e);
            }
        }

        // Activate and start composites
        CompositeActivator compositeActivator = runtime.getCompositeActivator();
        compositeActivator.setDomainComposite(domainComposite);
        for (Composite composite : domainComposite.getIncludes()) {
            try {
                compositeActivator.activate(composite);
            } catch (Exception e) {
                throw new ServiceRuntimeException(e);
            }
        }
        for (Composite composite : domainComposite.getIncludes()) {
            try {
                for (Component component : composite.getComponents()) {
                    compositeActivator.start(component);
                }
            } catch (Exception e) {
                throw new ServiceRuntimeException(e);
            }
        }

        // Index the top level components
        for (Composite composite : domainComposite.getIncludes()) {
            for (Component component : composite.getComponents()) {
                components.put(component.getName(), component);
            }
        }

        this.componentManager = new DefaultSCADomainComponentManager(this);
View Full Code Here

    }

    private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
        try {
            AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
            Composite composite = assemblyFactory.createComposite();
            composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
            RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
            component.setName("default");
            component.setURI("default");
            runtime.getCompositeActivator().configureComponentContext(component);
            composite.getComponents().add(component);
            RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
            reference.setName("default");
            ModelFactoryExtensionPoint factories =
                runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
            JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
View Full Code Here

    }

    private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
        try {
            AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
            Composite composite = assemblyFactory.createComposite();
            composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
            RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
            component.setName("default");
            component.setURI("default");
            nodeRuntime.getCompositeActivator().configureComponentContext(component);
            composite.getComponents().add(component);
            RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
            reference.setName("default");
            ModelFactoryExtensionPoint factories =
                nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
            JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
View Full Code Here

    }

    private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
        try {
            AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
            Composite composite = assemblyFactory.createComposite();
            composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
            RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
            component.setName("default");
            component.setURI("default");
            runtime.getCompositeActivator().configureComponentContext(component);
            composite.getComponents().add(component);
            RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
            reference.setName("default");
            ModelFactoryExtensionPoint factories =
                runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
            JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
View Full Code Here

        TestUtils.checkProblems(customBuilder);
        checkScenario1Results(true);
    }

    private void checkScenario1Results(boolean nonWiring) {
        Composite domainComposite = customBuilder.getDomainComposite();

        Component componentD = TestUtils.getComponent(domainComposite, "ComponentD");
        if (!nonWiring) {
            // Should create component service $promoted$.Service1 on innermost component
            //  ComponentD, with <binding.ws> and uri="/Service1"
            // No other services on ComponentD should have <binding.ws>
            WebServiceBinding wsBinding = null;
            for (ComponentService service : componentD.getServices()) {
                WebServiceBinding wsb = service.getBinding(WebServiceBinding.class);
                if ("$promoted$.Service1".equals(service.getName())) {
                    wsBinding = wsb;
                } else {
                    assert wsb == null;
                }
            }
            assert "/Service1".equals(wsBinding.getURI());

            // Should create WSDL document for ComponentD/$promoted$.Service1 with endpoint uri="/Service1"
            Definition def = wsBinding.getWSDLDocument();
            javax.wsdl.Service svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
            Port port = svc.getPort("Service3Port");
            assert "/Service1".equals(TestUtils.getPortAddress(port));
        } else {
            // Should not create component service $promoted$.Service1 on innermost component ComponentD
            // No component services on ComponentD should have <binding.ws>
            for (ComponentService service : componentD.getServices()) {
                assert !"$promoted$.Service1".equals(service.getName());
                assert service.getBinding(WebServiceBinding.class) == null;
            }
        }

        // No services on ComponentB should have <binding.ws>
        Component componentB = TestUtils.getComponent(domainComposite, "ComponentB");
        for (ComponentService service : componentB.getServices()) {
            assert service.getBinding(WebServiceBinding.class) == null;
        }

        // No services on CompositeC should have <binding.ws>
        Composite compositeC = TestUtils.getComposite(domainComposite, new QName("http://scenario1", "CompositeC"));
        for (Service service : compositeC.getServices()) {
            assert service.getBinding(WebServiceBinding.class) == null;
        }

        if (nonWiring) {
            // Should not add a WSDL document to domain composite service Service1
View Full Code Here

        TestUtils.checkProblems(customBuilder);
        checkScenario2and3Results("http://scenario2", true);
    }

    private void checkScenario2and3Results(String namespace, boolean nonWiring) {
        Composite domainComposite = customBuilder.getDomainComposite();

        // Should create WSDL document for ComponentB/Service2 with endpoint uri="/ComponentB/Service2"
        // No other services on ComponentB should have <binding.ws>
        Component componentB = TestUtils.getComponent(domainComposite, "ComponentB");
        WebServiceBinding wsBinding = null;
        for (ComponentService service : componentB.getServices()) {
            WebServiceBinding wsb = service.getBinding(WebServiceBinding.class);
            if ("Service2".equals(service.getName())) {
                wsBinding = wsb;
            } else {
                assert wsb == null;
            }
        }
        Definition def = wsBinding.getWSDLDocument();
        javax.wsdl.Service svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
        Port port = svc.getPort("Service3Port");
        assert "/ComponentB/Service2".equals(TestUtils.getPortAddress(port));

        Component componentD = TestUtils.getComponent(domainComposite, "ComponentD");
        if (!nonWiring) {
            // Should create component service $promoted$.ComponentB.Service2 on innermost component
            //  ComponentD, with <binding.ws> and uri="/ComponentB/Service2"
            wsBinding = null;
            for (ComponentService service : componentD.getServices()) {
                if ("$promoted$.ComponentB.Service2".equals(service.getName())) {
                    wsBinding = service.getBinding(WebServiceBinding.class);
                }
            }
            assert "/ComponentB/Service2".equals(wsBinding.getURI());

            // Should create WSDL document for ComponentD/$promoted$.ComponentB.Service2 with endpoint uri="/ComponentB/Service2"
            def = wsBinding.getWSDLDocument();
            svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
            port = svc.getPort("Service3Port");
            assert "/ComponentB/Service2".equals(TestUtils.getPortAddress(port));
        } else {
            // Should not create component service $promoted$.ComponentB.Service2 on innermost component ComponentD
            for (ComponentService service : componentD.getServices()) {
                assert !"$promoted$.ComponentB.Service2".equals(service.getName());
            }
        }

        // Should add <binding.ws> to outer composite service CompositeA/Service1
        wsBinding = null;
        for (Service service : domainComposite.getServices()) {
            if ("Service1".equals(service.getName())) {
                wsBinding = service.getBinding(WebServiceBinding.class);
            }
        }
        assert wsBinding != null;
        if (nonWiring) {
            // Should not add a WSDL document to domain composite service Service1
            assert wsBinding.getWSDLDocument() == null;
        }

        if (!nonWiring) {
            // Should create component service $promoted$.Service1 on innermost component
            //  ComponentD, with <binding.ws> and uri="/Service1"
            wsBinding = null;
            for (ComponentService service : componentD.getServices()) {
                if ("$promoted$.Service1".equals(service.getName())) {
                    wsBinding = service.getBinding(WebServiceBinding.class);
                }
            }
            assert "/Service1".equals(wsBinding.getURI());

            // Should create WSDL document for ComponentD/$promoted$.Service1 with endpoint uri="/Service1"
            def = wsBinding.getWSDLDocument();
            svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
            port = svc.getPort("Service3Port");
            assert "/Service1".equals(TestUtils.getPortAddress(port));
        } else {
            // Should not create component service $promoted$.Service1 on innermost component ComponentD
            for (ComponentService service : componentD.getServices()) {
                assert !"$promoted$.Service1".equals(service.getName());
            }
        }

        // No services on ComponentD should have <binding.ws>, except for $promoted$.Service1
        // and $promoted$.ComponentB.Service2 
        for (ComponentService service : componentD.getServices()) {
            if (!"$promoted$.Service1".equals(service.getName()) &&
                !"$promoted$.ComponentB.Service2".equals(service.getName())) {
                assert service.getBinding(WebServiceBinding.class) == null;
            }
        }

        // No services on CompositeC should have <binding.ws>, except for Service2 in Scenario 3
        Composite compositeC = TestUtils.getComposite(domainComposite, new QName(namespace, "CompositeC"));
        for (Service service : compositeC.getServices()) {
            if ("http://scenario3".equals(namespace) && "Service2".equals(service.getName())) {
                assert service.getBinding(WebServiceBinding.class) != null;
            } else {
                assert service.getBinding(WebServiceBinding.class) == null;
            }
View Full Code Here

        TestUtils.checkProblems(customBuilder);
        checkScenario4Results(true);
    }

    private void checkScenario4Results(boolean nonWiring) {
        Composite domainComposite = customBuilder.getDomainComposite();

        // Should create WSDL document for ComponentD/Service3 with endpoint uri="/ComponentD/Service3"
        Component componentD = TestUtils.getComponent(domainComposite, "ComponentD");
        WebServiceBinding wsBinding = null;
        for (ComponentService service : componentD.getServices()) {
            if ("Service3".equals(service.getName())) {
                wsBinding = service.getBinding(WebServiceBinding.class);
            }
        }
        Definition def = wsBinding.getWSDLDocument();
        javax.wsdl.Service svc = def.getService(new QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
        Port port = svc.getPort("Service3Port");
        assert "/ComponentB/ComponentD/Service3".equals(TestUtils.getPortAddress(port));

        // Should add <binding.ws> to inner composite service CompositeC/Service2
        // No other services on CompositeC should have <binding.ws>
        Composite compositeC = TestUtils.getComposite(domainComposite, new QName("http://scenario4", "CompositeC"));
        wsBinding = null;
        for (Service service : compositeC.getServices()) {
            WebServiceBinding wsb = service.getBinding(WebServiceBinding.class);
            if ("Service2".equals(service.getName())) {
                wsBinding = wsb;
            } else {
                assert wsb == null;
View Full Code Here

        TestUtils.checkProblems(customBuilder);
        checkScenario5Results(true);
    }

    private void checkScenario5Results(boolean nonWiring) {
        Composite domainComposite = customBuilder.getDomainComposite();

        // Should not add <binding.ws> to any outer component references
        Component componentB = TestUtils.getComponent(domainComposite, "ComponentB");
        for (ComponentReference reference : componentB.getReferences()) {
            assert reference.getBinding(WebServiceBinding.class) == null;
        }

        Definition def;
        javax.wsdl.Service svc;
        Port port;
        WebServiceBinding wsBinding;
        Component componentD = TestUtils.getComponent(domainComposite, "ComponentD");
        if (!nonWiring) {
            // Should add <binding.ws> to inner component reference ComponentD/reference3 with uri="http://foo.com/bar"
            // Should set <interface.wsdl> on inner component reference ComponentD/reference3
            wsBinding = null;
            for (ComponentReference reference : componentD.getReferences()) {
                if ("reference3".equals(reference.getName())) {
                    wsBinding = reference.getBinding(WebServiceBinding.class);
                    assert reference.getInterfaceContract(wsBinding) instanceof WSDLInterfaceContract;
                }
            }
            assert "http://foo.com/bar".equals(wsBinding.getURI());

            // Should create WSDL document for ComponentD/reference3 with endpoint uri="http://foo.com/bar"
            def = wsBinding.getWSDLDocument();
            svc = def.getService(new QName("http://scenarios/ComponentD/reference3", "Service3aService"));
            port = svc.getPort("Service3aPort");
            assert "http://foo.com/bar".equals(TestUtils.getPortAddress(port));
        } else {
            // Should not add <binding.ws> to any inner component references
            for (ComponentReference reference : componentD.getReferences()) {
                assert reference.getBinding(WebServiceBinding.class) == null;
            }
        }

        // Should not add <binding.ws> or <interface.wsdl> to inner composite reference CompositeC/reference2
        Composite compositeC = TestUtils.getComposite(domainComposite, new QName("http://scenario5", "CompositeC"));
        for (Reference reference : compositeC.getReferences()) {
            assert reference.getBinding(WebServiceBinding.class) == null;
            assert reference.getInterfaceContract() instanceof JavaInterfaceContract;
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.assembly.Composite

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.