Package org.apache.tuscany.model.assembly

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


    /**
     * Creates a module with a Java-based source component wired to a "target" external service configured
     * with the {@link FooBinding}
     */
    public static Module createModuleWithExternalService() throws ConfigurationLoadException {
        Component sourceComponent = createComponent("source", HelloWorldClient.class, Scope.MODULE);
        ExternalService targetES = createFooBindingExternalService("target", HelloWorldService.class);

        Service targetService = factory.createService();
        JavaServiceContract targetContract = factory.createJavaServiceContract();
        targetContract.setInterface(HelloWorldService.class);
        targetService.setServiceContract(targetContract);
        targetService.setName("HelloWorld");
        ConfiguredService cTargetService = factory.createConfiguredService();
        cTargetService.setPort(targetService);
        targetES.setConfiguredService(cTargetService);
        targetES.initialize(assemblyContext);

        Reference ref = factory.createReference();
        ref.setName("setHelloWorldService");
        JavaServiceContract inter = factory.createJavaServiceContract();
        inter.setInterface(HelloWorldService.class);
        ref.setServiceContract(inter);
        sourceComponent.getImplementation().getComponentType().getReferences().add(ref);

        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);
View Full Code Here


     * service offered by a Java-based component named "target"
     *
     * @param scope the scope of the target service
     */
    public static Module createModuleWithEntryPoint(Scope scope) throws ConfigurationLoadException {
        Component targetComponent = createComponent("target", HelloWorldImpl.class, scope);

        Service targetService = factory.createService();
        JavaServiceContract targetContract = factory.createJavaServiceContract();
        targetContract.setInterface(HelloWorldService.class);
        targetService.setServiceContract(targetContract);
        targetService.setName("HelloWorldService");
        ConfiguredService cTargetService = factory.createConfiguredService();
        cTargetService.setPort(targetService);
        targetComponent.getConfiguredServices().add(cTargetService);
        targetComponent.initialize(assemblyContext);

        Reference ref = factory.createReference();
        ConfiguredReference cref = factory.createConfiguredReference();
        ref.setName("setHelloWorldService");
        JavaServiceContract inter = factory.createJavaServiceContract();
View Full Code Here

     * @see ContextFactory
     */
    public static ContextFactory<Context> createCompositeConfiguration(String name
    ) throws BuilderException, ConfigurationLoadException {

        Component sc = createCompositeComponent(name);
        SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null);
        builder.build(sc);
        return (ContextFactory<Context>) sc.getContextFactory();
    }
View Full Code Here

        DefaultWireBuilder wireBuilder = new DefaultWireBuilder();
        RuntimeContext runtime = new RuntimeContextImpl(monitorFactory, builderRegistry, wireBuilder);
        runtime.start();
        runtime.getSystemContext().registerModelObject(createSystemCompositeComponent(SYSTEM_CHILD));
        SystemCompositeContext ctx = (SystemCompositeContext) runtime.getSystemContext().getContext(SYSTEM_CHILD);
        Component comp = systemFactory.createSystemComponent(POLICY_BUILDER_REGISTRY, PolicyBuilderRegistry.class, DefaultPolicyBuilderRegistry.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(DefaultPolicyBuilderRegistry.class));
        ctx.registerModelObject(comp);
        comp = systemFactory.createSystemComponent(MESSAGE_FACTORY, MessageFactory.class, MessageFactoryImpl.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(MessageFactoryImpl.class));
        ctx.registerModelObject(comp);
        comp = systemFactory.createSystemComponent(PROXY_FACTORY_FACTORY, WireFactoryFactory.class, JDKWireFactoryFactory.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(JDKWireFactoryFactory.class));
        ctx.registerModelObject(comp);
        comp = systemFactory.createSystemComponent(WIRE_FACTORY_SERVICE, org.apache.tuscany.core.wire.service.WireFactoryService.class, DefaultWireFactoryService.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(DefaultWireFactoryService.class));
        ctx.registerModelObject(comp);
        comp = systemFactory.createSystemComponent(JAVA_BUILDER, ContextFactoryBuilder.class, JavaContextFactoryBuilder.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(JavaContextFactoryBuilder.class));
        ctx.registerModelObject(comp);
        comp = systemFactory.createSystemComponent(JAVA_WIRE_BUILDER, WireBuilder.class, JavaTargetWireBuilder.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(JavaTargetWireBuilder.class));
        ctx.registerModelObject(comp);
        ctx.publish(new ModuleStart(new Object()));
        return runtime;
    }
View Full Code Here

     * @throws ConfigurationException
     */
    public static RuntimeContext registerFooBinding(RuntimeContext runtime) throws ConfigurationException {
        CompositeContext child = (CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD);
        child.getContext(MockFactory.JAVA_BUILDER).getInstance(null);
        Component comp = systemFactory.createSystemComponent(FOO_BUILDER, ContextFactoryBuilder.class, FooBindingBuilder.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(FooBindingBuilder.class));
        child.registerModelObject(comp);
        comp = systemFactory.createSystemComponent(FOO_WIRE_BUILDER, WireBuilder.class, FooBindingWireBuilder.class, Scope.MODULE);
        comp.getImplementation().setComponentType(getIntrospector().introspect(FooBindingWireBuilder.class));
        child.registerModelObject(comp);
        // since the child context is already started, we need to manually retrieve the components to init them
        Assert.assertNotNull(child.getContext(FOO_BUILDER).getInstance(null));
        Assert.assertNotNull(child.getContext(FOO_WIRE_BUILDER).getInstance(null));
        return runtime;
View Full Code Here

    private SystemAssemblyFactory factory;
    private SystemCompositeContextImpl system;

    public void testChildLocate() throws Exception {
        system.start();
        Component compositeComponent = MockFactory.createCompositeComponent("system.child");
        system.registerModelObject(compositeComponent);
        CompositeContext childContext = (CompositeContext) system.getContext("system.child");
        Assert.assertNotNull(childContext);

        Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE);
        EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component);
        childContext.registerModelObject(component);
        childContext.registerModelObject(ep);
        childContext.publish(new ModuleStart(this));
        Assert.assertNotNull(system.getContext("system.child").getInstance(new QualifiedName("./TestService1EP")));
View Full Code Here

        Assert.assertNotNull(system.getContext("system.child").getInstance(new QualifiedName("./TestService1EP")));
        childContext.publish(new ModuleStop(this));
    }

    public void testAutowireRegisterBeforeStart() throws Exception {
        Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE);
        EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component);
        system.registerModelObject(component);
        system.registerModelObject(ep);
        system.start();
        system.publish(new ModuleStart(this));
View Full Code Here

        system.publish(new ModuleStart(this));
        Assert.assertSame(system.getContext("TestService1EP").getInstance(null), system.resolveInstance(ModuleScopeSystemComponent.class));
    }

    public void testAutowireRegisterAfterStart() throws Exception {
        Component component = factory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE);
        system.registerModelObject(component);
        system.start();
        system.publish(new ModuleStart(this));
        EntryPoint ep = MockFactory.createEPSystemBinding("TestService1EP", ModuleScopeSystemComponent.class, "TestService1", component);
        system.registerModelObject(ep);
View Full Code Here

    private SystemAssemblyFactory factory = new SystemAssemblyFactoryImpl();

    public void testComponentContextBuilder() throws Exception {
        SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null);
        Component component = factory.createSystemComponent("test", null, SystemComponentImpl.class, Scope.AGGREGATE);
        component.getImplementation().setComponentType(MockFactory.getIntrospector().introspect(SystemComponentImpl.class));
        ConfiguredProperty cProp = factory.createConfiguredProperty();
        Property prop = factory.createProperty();
        prop.setName("testInt");
        cProp.setValue(1);
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        cProp = factory.createConfiguredProperty();
        prop = factory.createProperty();
        prop.setName("testString");
        cProp.setValue("test");
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        cProp = factory.createConfiguredProperty();
        prop = factory.createProperty();
        prop.setName("testDouble");
        cProp.setValue(1d);
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        cProp = factory.createConfiguredProperty();
        prop = factory.createProperty();
        prop.setName("testFloat");
        cProp.setValue(1f);
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        cProp = factory.createConfiguredProperty();
        prop = factory.createProperty();
        prop.setName("testShort");
        cProp.setValue((short) 1);
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        cProp = factory.createConfiguredProperty();
        prop = factory.createProperty();
        prop.setName("testByte");
        cProp.setValue((byte) 1);
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        cProp = factory.createConfiguredProperty();
        prop = factory.createProperty();
        prop.setName("testBoolean");
        cProp.setValue(Boolean.TRUE);
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        cProp = factory.createConfiguredProperty();
        prop = factory.createProperty();
        prop.setName("testChar");
        cProp.setValue('1');
        cProp.setProperty(prop);
        component.getConfiguredProperties().add(cProp);

        builder.build(component);
        ContextFactory<AtomicContext> contextFactory = (ContextFactory<AtomicContext>) component.getContextFactory();
        Assert.assertNotNull(contextFactory);
        contextFactory.prepare(createContext());
        AtomicContext ctx = contextFactory.createContext();

        ctx.start();
View Full Code Here

    }


    public void testDefaultScopeIsModuleScope() throws Exception {
        SystemContextFactoryBuilder builder = new SystemContextFactoryBuilder(null);
        Component component = createSystemComponentWithNoScope("test", null, SystemComponentImpl.class);
        builder.build(component);
        ContextFactory<AtomicContext> contextFactory = (ContextFactory<AtomicContext>) component.getContextFactory();
        Assert.assertEquals(Scope.MODULE, contextFactory.getScope());
    }
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.