Package org.apache.tuscany.core.context

Examples of org.apache.tuscany.core.context.ScopeContext


    }


    public void removeContext(String name){
       configurations.remove(name);
       ScopeContext ctx = scopeIndex.remove(name);
        if (ctx != null){
            ctx.removeContext(name);
        }

    }
View Full Code Here


        ScopeStrategy strategy = new DefaultScopeStrategy();
        DefaultWireBuilder wireBuilder = new DefaultWireBuilder();
        wireBuilder.addWireBuilder(javaWireBuilder);
        Module module = MockFactory.createModule();
        EventContext eCtx = new EventContextImpl();
        ScopeContext scopeContext = new ModuleScopeContext(eCtx);
        scopeContext.start();
        scopeContext.onEvent(new ModuleStart(this));
        List<Component> components = module.getComponents();
        Map<String, Component> compMap = new HashMap<String, Component>(components.size());

        for (Component component : components) {
            compMap.put(component.getName(), component);
            builder.build(component);
            ContextFactory contextFactory = (ContextFactory) component.getContextFactory();
            Assert.assertNotNull(contextFactory);
        }
        for (Component component : components) {
            ContextFactory<Context> source = (ContextFactory<Context>) component.getContextFactory();
            Assert.assertNotNull(source);
            for (SourceWireFactory pFactory : source.getSourceWireFactories()) {
                WireConfiguration pConfig = pFactory.getConfiguration();
                Component target = compMap.get(pConfig.getTargetName().getPartName());

                if (target != null) {
                    ContextFactory targetConfig = (ContextFactory) target.getContextFactory();
                    boolean downScope = strategy.downScopeReference(source.getScope(), targetConfig.getScope());
                    wireBuilder.connect(pFactory, targetConfig.getTargetWireFactory(pFactory.getConfiguration().getTargetName()
                            .getPortName()), targetConfig.getClass(), downScope, scopeContext);
                }
                pFactory.initialize();
            }
            scopeContext.registerFactory(source);
        }
        for (Component component : components) {
            ContextFactory config = (ContextFactory) component.getContextFactory();
            Context context = config.createContext();
            if ("source".equals(component.getName())) {
View Full Code Here

        echoMethod = SimpleTarget.class.getDeclaredMethod("echo", String.class);
        Assert.assertNotNull(echoMethod);
    }

    public void testScopedInvoke() throws Exception {
        ScopeContext container = new MockScopeContext();
        ScopedJavaComponentInvoker invoker = new ScopedJavaComponentInvoker(new QualifiedName("foo"), echoMethod, container,false);
        Object ret = invoker.invokeTarget("foo");
        Assert.assertEquals("foo", ret);
    }
View Full Code Here

        TargetInvocationConfiguration barInvocation = new TargetInvocationConfiguration(m);
        barConfigs.put(m, barInvocation);
        targetFooFactory.setConfiguration(new WireTargetConfiguration(null, fooConfigs, null, null));
        TargetWireFactory targetBarFactory = new JDKTargetWireFactory();
        targetBarFactory.setConfiguration(new WireTargetConfiguration(null, barConfigs, null, null));
        ScopeContext ctx = new MockScopeContext();
        defaultBuilder.completeTargetChain(targetFooFactory, FooContextFactory.class, ctx);
        defaultBuilder.completeTargetChain(targetBarFactory, BarContextFactory.class, ctx);
        assertEquals(FooInvoker.class, targetFooFactory.getConfiguration().getInvocationConfigurations().get(m).getTargetInvoker().getClass());
        assertEquals(BarInvoker.class, targetBarFactory.getConfiguration().getInvocationConfigurations().get(m).getTargetInvoker().getClass());
View Full Code Here

    public RuntimeScopeStrategy() {
    }

    public Map<Scope, ScopeContext> getScopeContexts(EventContext eventContext) {
        ScopeContext aggregrateScope = new CompositeScopeContext(eventContext);
        Map<Scope, ScopeContext> scopes = new HashMap<Scope, ScopeContext>();
        scopes.put(Scope.AGGREGATE, aggregrateScope);
        return scopes;
    }
View Full Code Here

    public DefaultScopeStrategy() {
    }

    public Map<Scope,ScopeContext> getScopeContexts(EventContext eventContext) {
        ScopeContext moduleScope = new ModuleScopeContext(eventContext);
        ScopeContext sessionScope = new SessionScopeContext(eventContext);
        ScopeContext requestScope = new RequestScopeContext(eventContext);
        ScopeContext statelessScope = new StatelessScopeContext(eventContext);
        ScopeContext aggregrateScope = new CompositeScopeContext(eventContext);
        Map<Scope,ScopeContext> scopes = new HashMap<Scope,ScopeContext>();
        scopes.put(Scope.MODULE,moduleScope);
        scopes.put(Scope.SESSION,sessionScope);
        scopes.put(Scope.REQUEST,requestScope);
        scopes.put(Scope.INSTANCE,statelessScope);
View Full Code Here

    // ----------------------------------

    public Object locateService(String qualifiedName) throws ServiceUnavailableException {
        checkInit();
        QualifiedName qName = new QualifiedName(qualifiedName);
        ScopeContext scope = scopeIndex.get(qName.getPartName());
        if (scope == null) {
            throw new ServiceNotFoundException(qualifiedName);
        }
        Context ctx = scope.getContext(qName.getPartName());
        try {
            Object o = ctx.getInstance(qName);
            if (o == null) {
                throw new ServiceNotFoundException(qualifiedName);
            }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.core.context.ScopeContext

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.