Package org.apache.tuscany.model.assembly

Examples of org.apache.tuscany.model.assembly.Module


        return servletConfig;
    }

    public static CompositeContext createModuleWithJSONRPCEntryPoint(String entryPointName, Object instance) {
        MockCompositeContextImpl cci = new MockCompositeContextImpl();
        Module module = (Module) cci.getComposite();
        List<EntryPoint> entryPoints = module.getEntryPoints();
        EntryPoint ep = createMockEntryPoint(entryPointName);
        addJSONRPCBinding(ep);
        entryPoints.add(ep);
        cci.start();
View Full Code Here


            }
        }
        ContextFactory<Context> configuration;
        if (model instanceof Module) {
            // merge new module definition with the existing one
            Module oldModule = module;
            Module newModule = (Module) model;
            module = newModule;
            for (Component component : newModule.getComponents()) {
                Implementation componentImplementation = component.getImplementation();
                if (componentImplementation == null) {
                    ConfigurationException e = new MissingImplementationException("Component implementation not set");
                    e.addContextName(component.getName());
                    e.addContextName(getName());
                    throw e;
                }
                configuration = (ContextFactory<Context>) component.getContextFactory();
                if (configuration == null) {
                    ConfigurationException e = new MissingContextFactoryException("Context factory not set");
                    e.addContextName(component.getName());
                    e.addContextName(getName());
                    throw e;
                }
                registerConfiguration(configuration);
                if (component instanceof ModuleComponent) {
                    registerAutowire((ModuleComponent) component);
                } else {
                    registerAutowire(component);
                }
            }
            for (EntryPoint ep : newModule.getEntryPoints()) {
                configuration = (ContextFactory<Context>) ep.getContextFactory();
                if (configuration == null) {
                    ConfigurationException e = new MissingContextFactoryException("Context factory not set");
                    e.setIdentifier(ep.getName());
                    e.addContextName(getName());
                    throw e;
                }
                registerConfiguration(configuration);
                registerAutowire(ep);
            }
            for (ExternalService service : newModule.getExternalServices()) {
                configuration = (ContextFactory<Context>) service.getContextFactory();
                if (configuration == null) {
                    ConfigurationException e = new MissingContextFactoryException("Context factory not set");
                    e.setIdentifier(service.getName());
                    e.addContextName(getName());
                    throw e;
                }
                registerConfiguration(configuration);
                registerAutowire(service);
            }
            if (lifecycleState == RUNNING) {
                for (Component component : newModule.getComponents()) {
                    ContextFactory<Context> contextFactory = (ContextFactory<Context>) component.getContextFactory();
                    wireSource(contextFactory);
                    buildTarget(contextFactory);
                    contextFactory.prepare(this);
                    try {
                        if (contextFactory.getSourceWireFactories() != null) {
                            for (SourceWireFactory sourceWireFactory : contextFactory.getSourceWireFactories())
                            {
                                sourceWireFactory.initialize();
                            }
                        }
                        if (contextFactory.getTargetWireFactories() != null) {
                            for (TargetWireFactory targetWireFactory : contextFactory.getTargetWireFactories()
                                    .values()) {
                                targetWireFactory.initialize();
                            }
                        }
                    } catch (WireFactoryInitException e) {
                        ProxyConfigurationException ce = new ProxyConfigurationException(e);
                        ce.addContextName(getName());
                        throw ce;
                    }

                }
                for (EntryPoint ep : newModule.getEntryPoints()) {
                    ContextFactory<Context> contextFactory = (ContextFactory<Context>) ep.getContextFactory();
                    wireSource(contextFactory);
                    buildTarget(contextFactory);
                    contextFactory.prepare(this);
                    try {
                        if (contextFactory.getSourceWireFactories() != null) {
                            for (SourceWireFactory sourceWireFactory : contextFactory.getSourceWireFactories())
                            {
                                sourceWireFactory.initialize();
                            }
                        }
                        if (contextFactory.getTargetWireFactories() != null) {
                            for (TargetWireFactory targetWireFactory : contextFactory.getTargetWireFactories()
                                    .values()) {
                                targetWireFactory.initialize();
                            }
                        }
                    } catch (WireFactoryInitException e) {
                        ProxyConfigurationException ce = new ProxyConfigurationException(e);
                        ce.addContextName(getName());
                        throw ce;
                    }

                }
                for (ExternalService es : newModule.getExternalServices()) {
                    ContextFactory<Context> contextFactory = (ContextFactory<Context>) es.getContextFactory();
                    wireSource(contextFactory);
                    buildTarget(contextFactory);
                    contextFactory.prepare(this);
                    try {
View Full Code Here

        JavaTargetWireBuilder javaWireBuilder = new JavaTargetWireBuilder();
        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);
View Full Code Here

    }

    public static ModuleComponent bootstrapLoader(String name, AssemblyContext context) throws ConfigurationLoadException {
        SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl();
        ComponentTypeIntrospector introspector = ProcessorUtils.createCoreIntrospector(factory);
        Module module = factory.createModule();
        module.setName("org.apache.tuscany.core.system.loader");

        List<Component> components = module.getComponents();

        // bootstrap the minimal set of loaders needed to read the system module files
        // all others should be defined in the system.module file
        components.add(bootstrapLoader(factory, introspector, ModuleLoader.class));
        components.add(bootstrapLoader(factory, introspector, ModuleFragmentLoader.class));
View Full Code Here

    /**
     * Creates an composite component with the given name
     */
    public static Component createCompositeComponent(String name) throws ConfigurationLoadException {
        Component sc = systemFactory.createModuleComponent();
        Module impl = systemFactory.createModule();
        impl.setName(name);
        //impl.setImplementationClass(CompositeContextImpl.class);
        sc.setImplementation(impl);
        Service s = systemFactory.createService();
        JavaServiceContract ji = systemFactory.createJavaServiceContract();
        s.setServiceContract(ji);
        ji.setScope(Scope.AGGREGATE);
        //impl.setComponentType(systemFactory.createComponentType());
        impl.setImplementationClass(CompositeContextImpl.class);
        impl.setComponentType(getCompositeComponentType());
        impl.getComponentType().getServices().add(s);
        sc.setName(name);
        sc.setImplementation(impl);

        return sc;
    }
View Full Code Here

    /**
     * Creates a system composite component with the given name
     */
    public static Component createSystemCompositeComponent(String name) throws ConfigurationLoadException {
        Component sc = systemFactory.createModuleComponent();
        Module impl = systemFactory.createSystemModule();
        impl.setName(name);
        //impl.setImplementationClass(SystemCompositeContextImpl.class);
        sc.setImplementation(impl);
        Service s = systemFactory.createService();
        JavaServiceContract ji = systemFactory.createJavaServiceContract();
        s.setServiceContract(ji);
        ji.setScope(Scope.AGGREGATE);
        impl.setComponentType(getComponentType());
        //impl.setComponentType(systemFactory.createComponentType());
        impl.getComponentType().getServices().add(s);
        sc.setName(name);
        sc.setImplementation(impl);
        return sc;
    }
View Full Code Here

        ConfiguredReference cref = factory.createConfiguredReference("setGenericComponent", "target");
        cref.initialize(assemblyContext);
        sourceComponent.getConfiguredReferences().add(cref);
        sourceComponent.initialize(assemblyContext);

        Module module = factory.createModule();
        module.setName("test.module");
        module.getComponents().add(sourceComponent);
        module.getComponents().add(targetComponent);
        module.initialize(assemblyContext);
        return module;
    }
View Full Code Here

        ConfiguredReference cref = factory.createConfiguredReference(ref.getName(), "target");
        cref.initialize(assemblyContext);
        sourceComponent.getConfiguredReferences().add(cref);
        sourceComponent.initialize(assemblyContext);

        Module module = factory.createModule();
        module.setName("test.module");
        module.getComponents().add(sourceComponent);
        module.getExternalServices().add(targetES);
        module.initialize(assemblyContext);
        return module;
    }
View Full Code Here

        EntryPoint sourceEP = createFooBindingEntryPoint("source", HelloWorldService.class);
        sourceEP.setConfiguredReference(cref);
        sourceEP.getConfiguredService().getPort().setName("HelloWorldService");
        sourceEP.initialize(assemblyContext);

        Module module = factory.createModule();
        module.setName("test.module");
        module.getEntryPoints().add(sourceEP);
        module.getComponents().add(targetComponent);
        module.setImplementationClass(CompositeContextImpl.class);
        module.setComponentType(getCompositeComponentType());
        module.initialize(assemblyContext);
        return module;
    }
View Full Code Here

        ComponentType componentType;
        Service service;
        SystemImplementation impl;
        Component component;

        Module module = factory.createModule();

        // create target component
        componentType = factory.createComponentType();
        service = factory.createService();
        service.setName("target");
        componentType.getServices().add(service);
        impl = factory.createSystemImplementation();
        impl.setComponentType(componentType);
        component = factory.createSimpleComponent();
        component.setName("target");
        component.setImplementation(impl);
        component.initialize(assemblyContext);
        module.getComponents().add(component);

        // create source component
        componentType = factory.createComponentType();
        Reference ref = factory.createReference();
        ref.setName("ref");
        componentType.getReferences().add(ref);
        impl = factory.createSystemImplementation();
        impl.setComponentType(componentType);
        component = factory.createSimpleComponent();
        component.setName("source");
        component.setImplementation(impl);
        ConfiguredReference cRef = factory.createConfiguredReference("ref", "target");
        component.getConfiguredReferences().add(cRef);
        component.initialize(assemblyContext);
        module.getComponents().add(component);

        EntryPoint ep = factory.createEntryPoint();
        JavaServiceContract contract = factory.createJavaServiceContract();
        contract.setInterface(ModuleScopeSystemComponent.class);
        service = factory.createService();
        service.setServiceContract(contract);
        ConfiguredService cService = factory.createConfiguredService();
        cService.setPort(service);
        cService.initialize(assemblyContext);
        ep.setConfiguredService(cService);
        SystemBinding binding = factory.createSystemBinding();
        ep.getBindings().add(binding);
        ConfiguredReference cEpRef = factory.createConfiguredReference();
        Reference epRef = factory.createReference();
        cEpRef.setPort(epRef);
        ep.setConfiguredReference(cEpRef);
        ep.initialize(assemblyContext);
        module.getEntryPoints().add(ep);

        List<ContextFactoryBuilder> builders = new ArrayList<ContextFactoryBuilder>();
        builders.add(new TestBuilder());
        AssemblyVisitorImpl visitor = new AssemblyVisitorImpl(builders);
        module.initialize(assemblyContext);
        visitor.start(module);

        Assert.assertSame(MARKER, component.getContextFactory());
        Assert.assertSame(MARKER, cRef.getProxyFactory());
        Assert.assertSame(MARKER, ep.getContextFactory());
View Full Code Here

TOP

Related Classes of org.apache.tuscany.model.assembly.Module

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.