Package org.apache.tuscany.spi.component

Examples of org.apache.tuscany.spi.component.CompositeComponent


        verify(component);
    }


    public void testNonExistentAutowire() {
        CompositeComponent component = createMock(CompositeComponent.class);
        expect(component.resolveSystemInstance(Object.class)).andReturn(null);
        replay(component);
        SystemOutboundAutowire wire = new SystemOutboundAutowire("foo", Object.class, component, true);
        try {
            wire.getTargetService();
            fail();
View Full Code Here


        verify(component);
    }


    public void testNonExistentAutowireNotRequired() {
        CompositeComponent component = createMock(CompositeComponent.class);
        expect(component.resolveSystemInstance(Object.class)).andReturn(null);
        replay(component);
        SystemOutboundAutowire wire = new SystemOutboundAutowire("foo", Object.class, component, false);
        try {
            assertNull(wire.getTargetService());
        } catch (TargetNotFoundException e) {
View Full Code Here

        }
        */

        // create the composite component
        String name = componentDefinition.getName();
        CompositeComponent component = new CompositeComponentImpl(name, parent, connector, null);
        for (ComponentDefinition<? extends Implementation> childComponentDefinition : allComponents) {
            component.register(builderRegistry.build(component, childComponentDefinition, deploymentContext));
        }

        for (BoundServiceDefinition<? extends Binding> serviceDefinition : allBoundServices) {
            component.register(builderRegistry.build(component, serviceDefinition, deploymentContext));
        }
        return component;
    }
View Full Code Here

* @version $$Rev: 451895 $$ $$Date: 2006-10-01 23:58:18 -0700 (Sun, 01 Oct 2006) $$
*/
public class CompositeComponentResolutionTestCase extends TestCase {

    public void testSystemComponentResolution() throws NoSuchMethodException {
        CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null);
        parent.start();
        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        Source originalSource = new SourceImpl();
        SystemAtomicComponent component = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(component.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(originalSource);
        EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(interfaces);
        EasyMock.replay(component);
        parent.register(component);
        assertNull(parent.getChild("source"));
        AtomicComponent target = (AtomicComponent) parent.getSystemChild("source");
        Source source = (Source) target.getServiceInstance();
        assertNotNull(source);
        EasyMock.verify(component);
    }
View Full Code Here

        assertNotNull(source);
        EasyMock.verify(component);
    }

    public void testLocateSystemService() throws NoSuchMethodException {
        CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null);
        parent.start();
        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        Source originalSource = new SourceImpl();
        SystemAtomicComponent component = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(component.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(originalSource);
        EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(interfaces);
        EasyMock.replay(component);
        parent.register(component);
        Source source = parent.locateSystemService(Source.class, "source");
        assertNotNull(source);
        EasyMock.verify(component);
    }
View Full Code Here

        assertNotNull(source);
        EasyMock.verify(component);
    }

    public void testLocateService() throws NoSuchMethodException {
        CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null);
        parent.start();
        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        Source originalSource = new SourceImpl();
        AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
        EasyMock.expect(component.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(originalSource);
        EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(interfaces);
        EasyMock.replay(component);
        parent.register(component);
        Source source = parent.locateService(Source.class, "source");
        assertNotNull(source);
        EasyMock.verify(component);
    }
View Full Code Here

        assertNotNull(source);
        EasyMock.verify(component);
    }

    public void testComponentResolution() throws NoSuchMethodException {
        CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null);
        parent.start();
        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        Source originalSource = new SourceImpl();
        AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
        EasyMock.expect(component.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(originalSource);
        EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(interfaces);
        EasyMock.replay(component);
        parent.register(component);
        assertNull(parent.getSystemChild("source"));
        AtomicComponent target = (AtomicComponent) parent.getChild("source");
        Source source = (Source) target.getServiceInstance();
        assertNotNull(source);
        EasyMock.verify(component);
    }
View Full Code Here

        EasyMock.verify(component);
    }


    public void testGetService() throws NoSuchMethodException {
        CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null);
        parent.start();
        Service service = EasyMock.createMock(Service.class);
        EasyMock.expect(service.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
        service.getInterface();
        EasyMock.expectLastCall().andReturn(Source.class);
        EasyMock.replay(service);
        parent.register(service);
        assertNotNull(parent.getService("source"));
        try {
            parent.getSystemService("source");
            fail();
        } catch (ComponentNotFoundException e) {
            // expected
        }
        EasyMock.verify(service);
View Full Code Here

        this.scheduler = scheduler;
        this.workContext = workContext;
    }

    public void connect(SCAObject source) {
        CompositeComponent parent = source.getParent();
        if (source instanceof AtomicComponent) {
            AtomicComponent sourceComponent = (AtomicComponent) source;
            // connect outbound wires for component references to their targets
            for (List<OutboundWire> referenceWires : sourceComponent.getOutboundWires().values()) {
                for (OutboundWire outboundWire : referenceWires) {
                    if (outboundWire instanceof OutboundAutowire) {
                        continue;
                    }
                    try {
                        SCAObject target;
                        if (sourceComponent.isSystem()) {
                            target = parent.getSystemChild(outboundWire.getTargetName().getPartName());
                        } else {
                            target = parent.getChild(outboundWire.getTargetName().getPartName());
                        }
                        connect(sourceComponent, outboundWire, target);
                    } catch (BuilderConfigException e) {
                        e.addContextName(source.getName());
                        e.addContextName(parent.getName());
                        throw e;
                    }
                }
            }
            // connect inbound wires
            for (InboundWire inboundWire : sourceComponent.getInboundWires().values()) {
                for (InboundInvocationChain chain : inboundWire.getInvocationChains().values()) {
                    Operation<?> operation = chain.getOperation();
                    String serviceName = inboundWire.getServiceName();
                    TargetInvoker invoker = sourceComponent.createTargetInvoker(serviceName, operation);
                    chain.setTargetInvoker(invoker);
                    chain.prepare();
                }
            }
        } else if (source instanceof Reference) {
            Reference reference = (Reference) source;
            InboundWire inboundWire = reference.getInboundWire();
            Map<Operation<?>, InboundInvocationChain> inboundChains = inboundWire.getInvocationChains();
            for (InboundInvocationChain chain : inboundChains.values()) {
                //TODO handle async
                // add target invoker on inbound side
                ServiceContract contract = inboundWire.getServiceContract();
                Operation operation = chain.getOperation();
                TargetInvoker invoker = reference.createTargetInvoker(contract, operation);
                chain.setTargetInvoker(invoker);
                chain.prepare();
            }
            OutboundWire outboundWire = reference.getOutboundWire();
            // connect the reference's inbound and outbound wires
            connect(inboundWire, outboundWire, true);
           
            if (reference instanceof CompositeReference) {
                // For a composite reference only, since its outbound wire comes
                // from its parent composite,
                // the corresponding target would not lie in its parent but
                // rather in its parent's parent
                parent = parent.getParent();
                assert parent != null : "Parent of parent was null";
                SCAObject target = parent.getChild(outboundWire.getTargetName().getPartName());
                connect((Component)parent, outboundWire, target);
            }           
        } else if (source instanceof Service) {
            Service service = (Service) source;
            InboundWire inboundWire = service.getInboundWire();
            OutboundWire outboundWire = service.getOutboundWire();
            // For a composite reference only, since its outbound wire comes from its parent composite,
            // the corresponding target would not lie in its parent but rather in its parent's parent
            if (source instanceof CompositeReference) {
                parent = parent.getParent();
                assert parent != null : "Parent of parent was null";
            }
            SCAObject target;
            if (service.isSystem()) {
                target = parent.getSystemChild(outboundWire.getTargetName().getPartName());
            } else {
                target = parent.getChild(outboundWire.getTargetName().getPartName());
            }
            // connect the outbound service wire to the target
            connect(service, outboundWire, target);
            // NB: this connect must be done after the outbound service chain is connected to its target above
            if (!(source instanceof CompositeService)) {
View Full Code Here

            assert targetWire != null;
            checkIfWireable(sourceWire, targetWire);
            boolean optimizable = isOptimizable(source.getScope(), target.getScope());
            connect(sourceWire, targetWire, optimizable);
        } else if (target instanceof CompositeComponent) {
            CompositeComponent composite = (CompositeComponent) target;
            InboundWire targetWire = null;
            if (source.isSystem()) {
                for (Object child : composite.getSystemChildren()) {
                    if (child instanceof CompositeService) {
                        CompositeService compServ = (CompositeService) child;
                        targetWire = compServ.getInboundWire();
                        assert targetWire != null;
                        Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
                        Class<?> targetInterface = targetWire.getServiceContract().getInterfaceClass();
                        if (sourceInterface.isAssignableFrom(targetInterface)) {
                            target = compServ;
                            break;
                        } else {
                            targetWire = null;
                        }
                    }
                }
            } else {
                for (Object child : composite.getChildren()) {
                    if (child instanceof CompositeService) {
                        CompositeService compServ = (CompositeService) child;
                        targetWire = compServ.getInboundWire();
                        assert targetWire != null;
                        Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.component.CompositeComponent

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.