Package org.apache.tuscany.model.assembly

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


    private List<ContextFactory<Context>> createConfigurations() throws BuilderException, ConfigurationLoadException {
        WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry());
        JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService);
        AtomicComponent component = MockFactory.createComponent("TestService1", SessionScopeComponentImpl.class, Scope.SESSION);
        ComponentTypeIntrospector introspector = MockFactory.getIntrospector();
        ComponentType type = introspector.introspect(SessionScopeComponentImpl.class);
        component.getImplementation().setComponentType(type);
        builder.build(component);
        List<ContextFactory<Context>> configs = new ArrayList<ContextFactory<Context>>();
        configs.add((ContextFactory<Context>) component.getContextFactory());
        return configs;
View Full Code Here


    private ContextFactory<Context> createConfiguration(String name) throws BuilderException, ConfigurationLoadException {
        WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), new DefaultPolicyBuilderRegistry());
        JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService);
        AtomicComponent component = MockFactory.createComponent(name, SessionScopeInitDestroyComponent.class, Scope.SESSION);
        ComponentTypeIntrospector introspector = MockFactory.getIntrospector();
        ComponentType type = introspector.introspect(SessionScopeInitDestroyComponent.class);
        component.getImplementation().setComponentType(type);
        builder.build(component);
        return (ContextFactory<Context>) component.getContextFactory();
    }
View Full Code Here

            }
        }
    }

    protected void loadProperties(XMLStreamReader reader, ResourceLoader resourceLoader, Component<?> component) throws XMLStreamException, ConfigurationLoadException {
        ComponentType componentType = component.getImplementation().getComponentType();
        List<ConfiguredProperty> configuredProperties = component.getConfiguredProperties();

        while (true) {
            switch (reader.next()) {
                case START_ELEMENT:
                    String name = reader.getLocalName();
                    Property property = componentType.getProperty(name);
                    if (property == null) {
                        throw new ConfigurationLoadException(name);
                    }
                    OverrideOption override = StAXUtil.overrideOption(reader.getAttributeValue(null, "override"), OverrideOption.NO);
View Full Code Here

            throw new AssemblyInitializationException("No implementation for component [" + getName() + ']');
        }
        implementation.initialize(modelContext);

        // Derive the configured services from the component implementation
        ComponentType componentType=implementation.getComponentType();
        AssemblyFactory factory = modelContext.getAssemblyFactory();
        for (Service service : componentType.getServices()) {
            ConfiguredService configuredService = factory.createConfiguredService();
            configuredService.setPort(service);
            configuredServices.add(configuredService);
            configuredService.initialize(modelContext);
        }

        // Derive the configured references from the references on the component info
        for (Reference reference : componentType.getReferences()) {
            ConfiguredReference configuredReference = configuredReferencesMap.get(reference.getName());
            if (configuredReference==null) {
                configuredReference=factory.createConfiguredReference();
                configuredReference.setPort(reference);
                configuredReferences.add(configuredReference);
                configuredReference.initialize(modelContext);
            } else {
                configuredReference.setPort(reference);
                configuredReference.initialize(modelContext);
            }
        }
        for (ConfiguredReference configuredReference : configuredReferences) {
            if (configuredReference.getPort()==null) {
                throw new AssemblyInitializationException("Undefined reference ["+configuredReference.getName()+"]");
            }
        }

        // Derive the configured properties from the properties on the component info
        for (Property property : componentType.getProperties()) {
            ConfiguredProperty configuredProperty = configuredPropertiesMap.get(property.getName());
            if (configuredProperty != null) {
                configuredProperty.setProperty(property);
                configuredProperty.initialize(modelContext);
            }
View Full Code Here

        target.getConfiguredServices().add(cTargetService);
        target.initialize(assemblyContext);

        // create the source component
        AtomicComponent source = factory.createSimpleComponent();
        ComponentType componentType = factory.createComponentType();
        source.setName("source");
        JavaImplementation impl = factory.createJavaImplementation();
        impl.setComponentType(componentType);
        impl.setImplementationClass(SourceImpl.class);
        source.setImplementation(impl);
        Service s = systemFactory.createService();
        JavaServiceContract contract = systemFactory.createJavaServiceContract();
        contract.setInterface(Source.class);
        s.setServiceContract(contract);
        contract.setScope(sourceScope);
        impl.getComponentType().getServices().add(s);
        source.setImplementation(impl);

        // wire source to target
        JavaServiceContract refContract = systemFactory.createJavaServiceContract();
        refContract.setInterface(Target.class);
        Reference reference = systemFactory.createReference();
        reference.setName("setTarget");
        reference.setServiceContract(refContract);
        componentType.getReferences().add(reference);
        ConfiguredReference cReference = systemFactory.createConfiguredReference(reference.getName(), "target");
        cReference.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference);

        // wire multiplicity using a setter
        JavaServiceContract refContract2 = systemFactory.createJavaServiceContract();
        refContract2.setInterface(Target.class);
        Reference reference2 = systemFactory.createReference();
        reference2.setName("setTargets");
        reference2.setServiceContract(refContract2);
        reference2.setMultiplicity(Multiplicity.ONE_N);
        componentType.getReferences().add(reference2);
        ConfiguredReference cReference2 = systemFactory.createConfiguredReference(reference2.getName(), "target");
        cReference2.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference2);

        // wire multiplicity using a field
        JavaServiceContract refContract3 = systemFactory.createJavaServiceContract();
        refContract3.setInterface(Target.class);
        Reference reference3 = systemFactory.createReference();
        reference3.setName("targetsThroughField");
        reference3.setServiceContract(refContract3);
        reference3.setMultiplicity(Multiplicity.ONE_N);
        componentType.getReferences().add(reference3);
        ConfiguredReference cReference3 = systemFactory.createConfiguredReference(reference3.getName(), "target");
        cReference3.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference3);

        // wire multiplicity using a array
        JavaServiceContract refContract4 = systemFactory.createJavaServiceContract();
        refContract4.setInterface(Target.class);
        Reference reference4 = systemFactory.createReference();
        reference4.setName("setArrayOfTargets");
        reference4.setServiceContract(refContract4);
        reference4.setMultiplicity(Multiplicity.ONE_N);
        componentType.getReferences().add(reference4);
        ConfiguredReference cReference4 = systemFactory.createConfiguredReference(reference4.getName(), "target");
        cReference4.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference4);

        source.initialize(assemblyContext);
View Full Code Here

        target.getConfiguredServices().add(cTargetService);
        target.initialize(assemblyContext);

        // create the source component
        AtomicComponent source = factory.createSimpleComponent();
        ComponentType componentType = factory.createComponentType();
        source.setName("source");
        JavaImplementation impl = factory.createJavaImplementation();
        impl.setComponentType(componentType);
        impl.setImplementationClass(SourceImpl.class);
        source.setImplementation(impl);
        Service s = systemFactory.createService();
        JavaServiceContract contract = systemFactory.createJavaServiceContract();
        contract.setInterface(Source.class);
        s.setServiceContract(contract);
        contract.setScope(sourceScope);
        impl.getComponentType().getServices().add(s);
        source.setImplementation(impl);

        // wire source to target
        JavaServiceContract refContract = systemFactory.createJavaServiceContract();
        refContract.setInterface(Target.class);
        Reference reference = systemFactory.createReference();
        reference.setName("setTarget");
        reference.setServiceContract(refContract);
        componentType.getReferences().add(reference);
        ConfiguredReference cReference = systemFactory.createConfiguredReference(reference.getName(), "target");
        cReference.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference);

        // wire multiplicity using a setter
        JavaServiceContract refContract2 = systemFactory.createJavaServiceContract();
        refContract2.setInterface(Target.class);
        Reference reference2 = systemFactory.createReference();
        reference2.setName("setTargets");
        reference2.setServiceContract(refContract2);
        reference2.setMultiplicity(Multiplicity.ONE_N);
        componentType.getReferences().add(reference2);
        ConfiguredReference cReference2 = systemFactory.createConfiguredReference(reference2.getName(), "target");
        cReference2.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference2);

        // wire multiplicity using a field
        JavaServiceContract refContract3 = systemFactory.createJavaServiceContract();
        refContract3.setInterface(Target.class);
        Reference reference3 = systemFactory.createReference();
        reference3.setName("targetsThroughField");
        reference3.setServiceContract(refContract3);
        reference3.setMultiplicity(Multiplicity.ONE_N);
        componentType.getReferences().add(reference3);
        ConfiguredReference cReference3 = systemFactory.createConfiguredReference(reference3.getName(), "target");
        cReference3.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference3);

        // wire multiplicity using a array
        JavaServiceContract refContract4 = systemFactory.createJavaServiceContract();
        refContract4.setInterface(Target.class);
        Reference reference4 = systemFactory.createReference();
        reference4.setName("setArrayOfTargets");
        reference4.setServiceContract(refContract4);
        reference4.setMultiplicity(Multiplicity.ONE_N);
        componentType.getReferences().add(reference4);
        ConfiguredReference cReference4 = systemFactory.createConfiguredReference(reference4.getName(), "target");
        cReference4.initialize(assemblyContext);
        source.getConfiguredReferences().add(cReference4);

        source.initialize(assemblyContext);
View Full Code Here

public class JavaImplementationLoaderTestCase extends TestCase {
    private JavaImplementationLoader loader;
    private ComponentType mockType;

    public void testNakedHelloWorld() throws ConfigurationLoadException {
        ComponentType type = loader.loadComponentTypeByIntrospection(NakedHelloWorld.class);
        Assert.assertNotNull(type);
        Assert.assertEquals(1,type.getProperties().size());
        Assert.assertTrue(type.getReferences().isEmpty());
        List<Service> services = type.getServices();
        Assert.assertEquals(1, services.size());
        Assert.assertEquals("NakedHelloWorld", services.get(0).getName());
    }
View Full Code Here

    public void testHelloWorldWithSidefile() throws XMLStreamException, ConfigurationLoadException {
        StAXLoaderRegistry mockRegistry = new MockRegistry(mockType);
        loader.setRegistry(mockRegistry);
        URL sidefile = HelloWorldImpl.class.getResource("HelloWorldImpl.componentType");
        ComponentType type = loader.loadComponentTypeFromSidefile(sidefile, null);
        assertSame(mockType, type);
    }
View Full Code Here

        ComponentType type = loader.loadComponentTypeFromSidefile(sidefile, null);
        assertSame(mockType, type);
    }

    public void testHelloWorldWithFieldProperties() throws ConfigurationLoadException {
        ComponentType type = loader.loadComponentTypeByIntrospection(HelloWorldWithFieldProperties.class);
        type.initialize(null);
        Assert.assertNotNull(type);
        List<Property> props = type.getProperties();
        Assert.assertEquals(5, props.size());

        Property prop = type.getProperty("text");
        Assert.assertNotNull(prop);
        Assert.assertEquals("text", prop.getName());
        Assert.assertEquals(false, prop.isRequired());
        Assert.assertEquals(String.class, prop.getType());

        prop = type.getProperty("text2");
        Assert.assertNotNull(prop);
        Assert.assertEquals("text2", prop.getName());
        Assert.assertEquals(true, prop.isRequired());
        Assert.assertEquals(Integer.class, prop.getType());

        prop = type.getProperty("foo");
        Assert.assertNotNull(prop);
        Assert.assertEquals("foo", prop.getName());
        Assert.assertEquals(false, prop.isRequired());
        Assert.assertEquals(Integer.TYPE, prop.getType());
    }
View Full Code Here

        JavaServiceContract jsc = factory.createJavaServiceContract();
        jsc.setInterface(service);
        Service s = factory.createService();
        s.setServiceContract(jsc);

        ComponentType componentType = factory.createComponentType();
        componentType.getServices().add(s);

        SystemImplementation sysImpl = factory.createSystemImplementation();
        sysImpl.setImplementationClass(impl);
        sysImpl.setComponentType(componentType);
View Full Code Here

TOP

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

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.