Package org.apache.tuscany.model.assembly

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


    protected SystemAssemblyFactory factory;

    public void testParentContextIsolation() throws Exception {
        CompositeContext parent = createContextHierachy();
        CompositeContext child = (CompositeContext) parent.getContext("test.child");
        Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE);
        parent.registerModelObject(component);
        EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component);
        parent.registerModelObject(ep);
        parent.publish(new ModuleStart(this));
        child.publish(new ModuleStart(this));
View Full Code Here


     * @throws Exception
     */
    public void testChildContextIsolation() throws Exception {
        CompositeContext parent = createContextHierachy();
        CompositeContext child = (CompositeContext) parent.getContext("test.child");
        Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE);
       
        component.initialize(new AssemblyContextImpl(factory, null, null));
        child.registerModelObject(component);
        parent.publish(new ModuleStart(this));
        child.publish(new ModuleStart(this));
        Assert.assertNotNull(child.getContext("TestService1").getInstance(null));
        try {
View Full Code Here

    protected CompositeContext createContextHierachy() throws Exception {
        List<ContextFactoryBuilder> systemBuilders = MockFactory.createSystemBuilders();
        CompositeContext parent = new CompositeContextImpl("test.parent", null, new DefaultScopeStrategy(),
                new EventContextImpl(), new MockConfigContext(systemBuilders));
        Component component = MockFactory.createCompositeComponent("test.child");
        parent.registerModelObject(component);
        parent.start();
        CompositeContext child = (CompositeContext) parent.getContext("test.child");
        Assert.assertNotNull(child);
        return parent;
View Full Code Here

        SystemImplementation sysImpl = createSystemImplementation();
        sysImpl.setImplementationClass(impl);
        sysImpl.setComponentType(componentType);

        Component sc = createSimpleComponent();
        sc.setName(name);
        sc.setImplementation(sysImpl);
        return sc;
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public void build(AssemblyObject modelObject) throws BuilderException {
        if (!(modelObject instanceof Component)) {
            return;
        }
        Component component = (Component) modelObject;

        Class implClass;
        Scope scope;
        // Get the component implementation
        Implementation componentImplementation = component.getImplementation();
        if (componentImplementation instanceof SystemImplementation
                && component.getContextFactory() == null) {

            // The component is a system component, implemented by a Java class
            SystemImplementation implementation = (SystemImplementation) componentImplementation;
            if (componentImplementation.getComponentType().getServices() == null
                    || componentImplementation.getComponentType().getServices().size() < 1) {
                BuilderConfigException e = new BuilderConfigException("No service configured on component type");
                e.setIdentifier(component.getName());
                throw e;
            }
            implClass = implementation.getImplementationClass();
            Scope previous = null;
            scope = Scope.MODULE;
            List<Service> services = component.getImplementation().getComponentType().getServices();
            for (Service service : services) {
                // calculate and validate the scope of the component; ensure that all service scopes are the same unless
                // a scope is stateless
                Scope current = service.getServiceContract().getScope();
                if (previous != null && current != null && current != previous
                        && (current != Scope.INSTANCE && previous != Scope.INSTANCE)) {
                    BuilderException e = new BuilderConfigException("Incompatible scopes specified for services on component");
                    e.setIdentifier(component.getName());
                    throw e;
                }
                if (current != null && current != Scope.MODULE) {
                    scope = current;
                }
            }

        } else if (componentImplementation instanceof Composite) {
            implClass = ((Composite) componentImplementation).getImplementationClass();
            if (implClass == null) {
                // FIXME this is a hack
                if (((Module) componentImplementation).getName().startsWith("org.apache.tuscany.core.system"))
                {
                    // The component is a system module component, fix the implementation class to our implementation
                    // of system module component context
                    implClass = SystemCompositeContextImpl.class;
                } else if (componentImplementation instanceof SystemModule) {
                    implClass = SystemCompositeContextImpl.class;
                } else {
                    // The component is an app module component, fix the implementation class to our implementation
                    // of app module component context
                    //FIXME this should be extensible, i.e. the model should specify the impl class of the module
                    implClass = CompositeContextImpl.class;
                }
                //END hack
            }
            scope = Scope.AGGREGATE;
        } else {
            return;
        }
        Set<Field> fields;
        Set<Method> methods;
        SystemContextFactory contextFactory;
        try {
            fields = JavaIntrospectionHelper.getAllFields(implClass);
            methods = JavaIntrospectionHelper.getAllUniqueMethods(implClass);
            String name = component.getName();
            if (componentImplementation instanceof Module) {
                Module module = (Module) componentImplementation;
                contextFactory = new SystemContextFactory(name, module, JavaIntrospectionHelper.getDefaultConstructor(implClass), scope);

            } else {
                contextFactory = new SystemContextFactory(name, JavaIntrospectionHelper.getDefaultConstructor(implClass), scope);
            }

            //ContextObjectFactory contextObjectFactory = new ContextObjectFactory(contextFactory);

            List<Injector> injectors = new ArrayList<Injector>();

            // handle properties
            List<ConfiguredProperty> configuredProperties = component.getConfiguredProperties();
            if (configuredProperties != null) {
                for (ConfiguredProperty property : configuredProperties) {
                    Injector injector = createPropertyInjector(property, fields, methods);
                    injectors.add(injector);
                }
            }

            // FIXME do not inject references on an application module yet
            if (implClass != CompositeContextImpl.class) {
                // handle references
                List<ConfiguredReference> configuredReferences = component.getConfiguredReferences();
                if (configuredReferences != null) {
                    for (ConfiguredReference reference : configuredReferences) {
                        Injector injector = createReferenceInjector(reference, fields, methods, contextFactory);
                        injectors.add(injector);
                    }
                }
            }
            List<Object> elements = componentImplementation.getComponentType().getExtensibilityElements();
            for (Object element : elements) {
                if (element instanceof InitInvokerExtensibilityElement) {
                    InitInvokerExtensibilityElement invokerElement = (InitInvokerExtensibilityElement) element;
                    EventInvoker<Object> initInvoker = invokerElement.getEventInvoker();
                    boolean eagerInit = invokerElement.isEager();
                    contextFactory.setEagerInit(eagerInit);
                    contextFactory.setInitInvoker(initInvoker);
                } else if (element instanceof DestroyInvokerExtensibilityElement) {
                    DestroyInvokerExtensibilityElement invokerElement = (DestroyInvokerExtensibilityElement) element;
                    EventInvoker<Object> destroyInvoker = invokerElement.getEventInvoker();
                    contextFactory.setDestroyInvoker(destroyInvoker);
                } else if (element instanceof ComponentNameExtensibilityElement) {
                    ComponentNameExtensibilityElement nameElement = (ComponentNameExtensibilityElement) element;
                    injectors.add(nameElement.getEventInvoker(name));
                } else if (element instanceof ContextExtensibilityElement) {
                    ContextExtensibilityElement contextElement = (ContextExtensibilityElement) element;
                    injectors.add(contextElement.getInjector(contextFactory));
                } else if (element instanceof InjectorExtensibilityElement) {
                    InjectorExtensibilityElement injectorElement = (InjectorExtensibilityElement) element;
                    injectors.add(injectorElement.getInjector(contextFactory));
                } else if (element instanceof SystemInjectorExtensibilityElement) {
                    SystemInjectorExtensibilityElement injectorElement = (SystemInjectorExtensibilityElement) element;
                    injectors.add(injectorElement.getInjector(contextFactory));
                } else if (element instanceof MonitorExtensibilityElement) {
                    MonitorExtensibilityElement monitorElement = (MonitorExtensibilityElement) element;
                    injectors.add(monitorElement.getInjector(monitorFactory));
                }
            }
            contextFactory.setSetters(injectors);
            // decorate the logical model
            component.setContextFactory(contextFactory);
        } catch (BuilderConfigException e) {
            e.addContextName(component.getName());
            throw e;
        } catch (NoSuchMethodException e) {
            BuilderConfigException ce = new BuilderConfigException("Class does not have a no-arg constructor", e);
            ce.setIdentifier(implClass.getName());
            throw ce;
        } catch (FactoryInitException e) {
            BuilderConfigException ce = new BuilderConfigException("Error building component", e);
            ce.addContextName(component.getName());
            throw ce;
        }
    }
View Full Code Here

    public static Module createSystemModule() throws ConfigurationLoadException {
        Module module = systemFactory.createSystemModule();
        module.setName("system.module");

        // create test component
        Component component = systemFactory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class,
                ModuleScopeSystemComponentImpl.class, Scope.MODULE);
        component.getImplementation().setComponentType(getIntrospector().introspect(ModuleScopeSystemComponent.class));
        module.getComponents().add(component);

        // create the entry point
        EntryPoint ep = createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "target", component);
        module.getEntryPoints().add(ep);
View Full Code Here

        module.setComponentType(getComponentType());
        return module;
    }

    public static <T> Component createSystemComponent(String name, Class<T> service, Class<? extends T> impl, Scope scope) throws ConfigurationLoadException {
        Component c = systemFactory.createSystemComponent(name, service, impl, scope);
        c.getImplementation().setComponentType(getIntrospector().introspect(impl));
        for (Service s : c.getImplementation().getComponentType().getServices()) {
             s.getServiceContract().setScope(scope);    //hack
        }

        return c;
    }
View Full Code Here

     * @see org.apache.tuscany.core.mock.component.Target
     */
    public static Module createSystemModuleWithWiredComponents(String moduleName, Scope sourceScope, Scope targetScope) throws ConfigurationLoadException {

        // create the target component
        Component target = systemFactory.createSystemComponent("target", Target.class, TargetImpl.class, targetScope);
        target.initialize(assemblyContext);

        // create the source componentType
        Component source = systemFactory.createSystemComponent("source", Source.class, SourceImpl.class, sourceScope);
        ComponentType sourceComponentType = source.getImplementation().getComponentType();
        List<Reference> references = sourceComponentType.getReferences();
        List<ConfiguredReference> configuredReferences = source.getConfiguredReferences();

        // wire source to target
        references.add(systemFactory.createReference("setTarget", Target.class));
        ConfiguredReference configuredReference = systemFactory.createConfiguredReference("setTarget", "target");
        configuredReferences.add(configuredReference);

        // wire multiplicity using a setter
        references.add(systemFactory.createReference("setTargets", Target.class, Multiplicity.ONE_N));
        configuredReference = systemFactory.createConfiguredReference("setTargets", "target");
        configuredReferences.add(configuredReference);

        // wire multiplicity using a field
        references.add(systemFactory.createReference("targetsThroughField", Target.class, Multiplicity.ONE_N));
        configuredReference = systemFactory.createConfiguredReference("targetsThroughField", "target");
        configuredReferences.add(configuredReference);

        // wire multiplicity using a setter
        references.add(systemFactory.createReference("setArrayOfTargets", Target.class, Multiplicity.ONE_N));
        configuredReference = systemFactory.createConfiguredReference("setArrayOfTargets", "target");
        configuredReferences.add(configuredReference);

        source.initialize(assemblyContext);

        Module module = systemFactory.createSystemModule();
        module.setImplementationClass(SystemCompositeContextImpl.class);
        module.setComponentType(getComponentType());
        module.setName(moduleName);
View Full Code Here

        module.setName("system.test.module");
        module.setImplementationClass(SystemCompositeContextImpl.class);
        module.setComponentType(getComponentType());

        // create test component
        Component component = systemFactory.createSystemComponent("TestService2", ModuleScopeSystemComponent.class,
                ModuleScopeSystemComponentImpl.class, Scope.MODULE);
        module.getComponents().add(component);

        // create the entry point
        EntryPoint ep = createEPSystemBinding("TestService2EP", ModuleScopeSystemComponent.class, "target", component);
View Full Code Here

    private ComponentLoader loader;
    private ComponentTypeIntrospector introspector;

    public void testStringProperty() throws XMLStreamException, ConfigurationLoadException {
        String xml = "<properties><propString>HelloWorld</propString></properties>";
        Component component = createFooComponent();
        loadProperties(xml, component);
        ConfiguredProperty prop = component.getConfiguredProperty("propString");
        assertEquals("HelloWorld", prop.getValue());
    }
View Full Code Here

TOP

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

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.