Package org.apache.tuscany.spi.component

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


        }
       
        RubyScript rubyScript = implementation.getRubyScript();

        // TODO: have ComponentBuilderExtension pass ScopeContainer in on build method?
        ScopeContainer scopeContainer;
        Scope scope = componentType.getLifecycleScope();
        if (Scope.MODULE == scope) {
            scopeContainer = deploymentContext.getModuleScope();
        } else {
            scopeContainer = scopeRegistry.getScopeContainer(scope);
View Full Code Here


        this.workContext = workContext;
    }

    public ScopeContainer getScopeContainer(Scope scope) {
        assert Scope.MODULE != scope : "Cannot get MODULE scope from the registry";
        ScopeContainer container = scopeCache.get(scope);
        if (container == null) {
            ObjectFactory<? extends ScopeContainer> factory = factoryCache.get(scope);
            if (factory == null) {
                ScopeNotFoundException e = new ScopeNotFoundException("Scope object factory not registered for scope");
                e.setIdentifier(scope.getScope());
               
                throw e;
            }
            container = factory.getInstance();
            container.setWorkContext(workContext);
            container.start();
            scopeCache.put(scope, container);
        }
        return container;
    }
View Full Code Here

    }

    public <I extends Implementation<?>> Component deploy(CompositeComponent parent,
                                                             ComponentDefinition<I> componentDefinition)
        throws LoaderException {
        ScopeContainer moduleScope = new ModuleScopeContainer();
        DeploymentContext deploymentContext = new RootDeploymentContext(null, xmlFactory, moduleScope, null);
        try {
            load(parent, componentDefinition, deploymentContext);
        } catch (LoaderException e) {
            e.addContextName(componentDefinition.getName());
View Full Code Here

    public void testDifferentInterfaceInjection() throws Exception {
        Map<String, Member> members = new HashMap<String, Member>();
        Method m = SourceImpl.class.getMethod("setTarget", Target.class);
        members.put("target", m);
        ScopeContainer scope = createMock();
        scope.start();
        Map<String, AtomicComponent> contexts =
            MockFactory.createWiredComponents("source",
                SourceImpl.class,
                Target.class,
                scope,
                members,
                "target",
                OtherTarget.class,
                OtherTargetImpl.class,
                scope);
        AtomicComponent sourceComponent = contexts.get("source");
        Source source = (Source) sourceComponent.getServiceInstance();
        Target target = source.getTarget();
        assertTrue(Proxy.isProxyClass(target.getClass()));
        assertNotNull(target);
        scope.stop();
        EasyMock.verify(scope);
    }
View Full Code Here

    public void testDifferentInterfaceMultiplicityInjection() throws Exception {
        Map<String, Member> members = new HashMap<String, Member>();
        Method m = SourceImpl.class.getMethod("setTargets", List.class);
        members.put("target", m);
        ScopeContainer scope = createMock();
        scope.start();
        Map<String, AtomicComponent> contexts =
            MockFactory.createWiredMultiplicity("source", SourceImpl.class, Target.class, scope,
                "target", OtherTarget.class, OtherTargetImpl.class, members, scope);
        AtomicComponent sourceComponent = contexts.get("source");
        Source source = (Source) sourceComponent.getServiceInstance();
        List<Target> targets = source.getTargets();
        assertEquals(1, targets.size());
        Target target = targets.get(0);
        target.setString("foo");
        assertEquals("foo", target.getString());
        assertTrue(Proxy.isProxyClass(target.getClass()));
        scope.stop();
        EasyMock.verify(scope);
    }
View Full Code Here

    protected void tearDown() throws Exception {
        super.tearDown();
    }

    private ScopeContainer createMock() {
        ScopeContainer scope = EasyMock.createMock(ScopeContainer.class);
        scope.start();
        scope.stop();
        scope.register(EasyMock.isA(AtomicComponent.class));
        EasyMock.expectLastCall().atLeastOnce();
        EasyMock.expect(scope.getScope()).andReturn(Scope.MODULE).atLeastOnce();
        scope.getInstance(EasyMock.isA(AtomicComponent.class));
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>();

            public Object answer() throws Throwable {
                AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
View Full Code Here

public class ReferenceInjectionTestCase extends TestCase {

    private Map<String, Member> members;

    public void testProxiedReferenceInjection() throws Exception {
        ScopeContainer scope = new ModuleScopeContainer(null);
        scope.start();
        Map<String, AtomicComponent> contexts =
            MockFactory.createWiredComponents("source", SourceImpl.class, scope,
                members, "target", Target.class, TargetImpl.class, scope);
        AtomicComponent sourceComponent = contexts.get("source");
        Source source = (Source) sourceComponent.getServiceInstance();
        Target target = source.getTarget();
        assertTrue(Proxy.isProxyClass(target.getClass()));

        assertNotNull(target);
        scope.stop();
    }
View Full Code Here

* @version $$Rev: 441935 $$ $$Date: 2006-09-10 02:57:47 -0700 (Sun, 10 Sep 2006) $$
*/
public class JavaReferenceWireTestCase extends TestCase {

    public void testReferenceSet() throws Exception {
        ScopeContainer scope = createMock();
        scope.start();
        final Target target = new TargetImpl();
        PojoConfiguration configuration = new PojoConfiguration();
        configuration.addReferenceSite("target", SourceImpl.class.getMethod("setTarget", Target.class));
        configuration.addServiceInterface(Source.class);
        Constructor<SourceImpl> ctr = SourceImpl.class.getConstructor();
        configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(ctr));
        configuration.setScopeContainer(scope);
        OutboundWire wire = EasyMock.createMock(OutboundWire.class);
        wire.getInvocationChains();
        EasyMock.expectLastCall().andReturn(new HashMap<Operation<?>, OutboundInvocationChain>());
        EasyMock.expect(wire.getReferenceName()).andReturn("target").atLeastOnce();
        EasyMock.replay(wire);
        WireService service = EasyMock.createMock(WireService.class);
        EasyMock.expect(service.createProxy(EasyMock.eq(wire))).andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                OutboundWire wire = (OutboundWire) EasyMock.getCurrentArguments()[0];
                wire.getInvocationChains();
                return target;
            }

        }).atLeastOnce();
        EasyMock.replay(service);
        configuration.setWireService(service);
        JavaAtomicComponent sourceContext = new JavaAtomicComponent("source", configuration, null);
        sourceContext.addOutboundWire(wire);
        sourceContext.start();
        Source source = (Source) sourceContext.getServiceInstance();
        assertSame(target, source.getTarget());
        scope.stop();
        EasyMock.verify(wire);
        EasyMock.verify(scope);
        EasyMock.verify(service);
    }
View Full Code Here

        EasyMock.verify(scope);
        EasyMock.verify(service);
    }

    private ScopeContainer createMock() {
        ScopeContainer scope = EasyMock.createMock(ScopeContainer.class);
        scope.start();
        scope.stop();
        scope.register(EasyMock.isA(AtomicComponent.class));
        EasyMock.expectLastCall().atLeastOnce();
        EasyMock.expect(scope.getScope()).andReturn(Scope.MODULE).atLeastOnce();
        scope.getInstance(EasyMock.isA(AtomicComponent.class));
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>();

            public Object answer() throws Throwable {
                AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
View Full Code Here

        super.setUp();
        deploymentContext = new RootDeploymentContext(null, null, createMock(), null);
    }

    private ScopeContainer createMock() {
        ScopeContainer scope = EasyMock.createMock(ScopeContainer.class);
        scope.start();
        scope.stop();
        scope.register(EasyMock.isA(AtomicComponent.class));
        EasyMock.expectLastCall().atLeastOnce();
        EasyMock.expect(scope.getScope()).andReturn(Scope.MODULE).atLeastOnce();
        scope.getInstance(EasyMock.isA(AtomicComponent.class));
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>();

            public Object answer() throws Throwable {
                AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
View Full Code Here

TOP

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

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.