Package org.apache.tuscany.sca.assembly

Examples of org.apache.tuscany.sca.assembly.Composite


     *
     * @return the domain composite
     * @throws ServiceRuntimeException
     */
    private Composite readCompositeCollection() throws ServiceRuntimeException {
        Composite compositeCollection;
        File file = new File(compositeFile);
        if (file.exists()) {
            XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
            try {
                FileInputStream is = new FileInputStream(file);
                XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
                compositeCollection = compositeProcessor.read(reader);
            } catch (Exception e) {
                throw new ServiceRuntimeException(e);
            }
        } else {
            compositeCollection = assemblyFactory.createComposite();
            String name;
            int d = compositeFile.lastIndexOf('.');
            if (d != -1) {
                name = compositeFile.substring(0, d);
            } else {
                name = compositeFile;
            }
            compositeCollection.setName(new QName(Constants.SCA10_TUSCANY_NS, name));
        }
        return compositeCollection;
    }
View Full Code Here


                        compositeArtifacts.put(artifact.getURI(), (Composite)artifact.getModel());
                    }
                }
            }
            for (String compositePath : composites) {
                Composite composite = compositeArtifacts.get(compositePath);
                if (composite == null) {
                    throw new ServiceRuntimeException("Composite not found: " + compositePath);
                }
                domainComposite.getIncludes().add(composite);
            }
        } else {
            // in this case, a sca-contribution.xml should have been specified
            for (Contribution contribution : contributions) {
                for (Composite composite : contribution.getDeployables()) {
                    domainComposite.getIncludes().add(composite);
                }
            }
        }
       
        //update the runtime for all SCA Definitions processed from the contribution..
        //so that the policyset determination done during 'build' has the all the defined
        //intents and policysets
        //runtime.updateSCADefinitions(null);

        // Build the SCA composites
        for (Composite composite : domainComposite.getIncludes()) {
            try {
                runtime.buildComposite(composite);
            } catch (CompositeBuilderException e) {
                throw new ServiceRuntimeException(e);
            }
        }

        // Activate and start composites
        CompositeActivator compositeActivator = runtime.getCompositeActivator();
        compositeActivator.setDomainComposite(domainComposite);
        for (Composite composite : domainComposite.getIncludes()) {
            try {
                compositeActivator.activate(composite);
            } catch (ActivationException e) {
                throw new ServiceRuntimeException(e);
            }
        }
        for (Composite composite : domainComposite.getIncludes()) {
            try {
                for (Component component : composite.getComponents()) {
                    compositeActivator.start(component);
                }
            } catch (ActivationException e) {
                throw new ServiceRuntimeException(e);
            }
        }

        // Index the top level components
        for (Composite composite : domainComposite.getIncludes()) {
            for (Component component : composite.getComponents()) {
                components.put(component.getName(), component);
            }
        }

        this.componentManager = new DefaultSCADomainComponentManager(this);
View Full Code Here

    }

    private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
        try {
            AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
            Composite composite = assemblyFactory.createComposite();
            composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
            RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
            component.setName("default");
            component.setURI("default");
            runtime.getCompositeActivator().configureComponentContext(component);
            composite.getComponents().add(component);
            RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
            reference.setName("default");
            ModelFactoryExtensionPoint factories =
                runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
            JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
View Full Code Here

        if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) {
            reader.nextTag();
        }
        Object model = extensionProcessor.read(reader, context);
        if (model instanceof Composite) {
            Composite composite = (Composite)model;
            Component component = composite.getComponents().get(0);
            ComponentReference reference = component.getReferences().get(0);
            Binding binding = reference.getBindings().get(0);
            endpointReference.setComponent(component);
            endpointReference.setReference(reference);
            reference.getEndpointReferences().add(endpointReference);
View Full Code Here

        extensionProcessor.write(wrap(model), writer, context);
    }

    private Composite wrap(EndpointReference endpointReference) {
        try {
            Composite composite = assemblyFactory.createComposite();
            composite.setName(ENDPOINT_REFERENCE_QNAME);
            composite.setLocal(false);
            Component component = (Component)endpointReference.getComponent().clone();
            composite.getComponents().add(component);
            component.getReferences().clear();
            component.getServices().clear();
            ComponentReference reference = (ComponentReference)endpointReference.getReference().clone();
            component.getReferences().add(reference);
            reference.getBindings().clear();
View Full Code Here

    }

    public Composite read(URI uri, URL url, InputStream scdlStream, ProcessorContext context) throws ContributionReadException {
        try {      
           
            Composite composite = null;
            Monitor monitor = context.getMonitor();
            // Tag the monitor with the name of the composite artifact
            if( monitor != null ) {
              monitor.setArtifactName(uri.toString());
            } //end if
           
            // Set up a StreamSource for the composite file, since this has an associated URL that
            // can be used by the parser to find references to other files such as DTDs
            StreamSource scdlSource = new StreamSource( scdlStream, url.toString() );
            XMLStreamReader reader = inputFactory.createXMLStreamReader(scdlSource);
           
            // set the monitor on the input factory as the standard XMLInputFactory
            // methods used for creating readers don't allow for the context to
            // be passed in
            ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor());
           
            // Read the header (i.e. text before the <composite> element, if any
            readCompositeFileHeader( reader );
           
            // Read the composite model
            composite = (Composite)extensionProcessor.read(reader, context);
            if (composite != null) {
                composite.setURI(uri.toString());
            }

            return composite;
           
        } catch (XMLStreamException e) {
View Full Code Here

        return this.composite;
    }

    public Component read(XMLStreamReader reader)
            throws ContributionReadException, XMLStreamException {
        Composite include = null;
        Component component = null;
        Property property = null;
        ComponentService componentService = null;
        ComponentReference componentReference = null;
        ComponentProperty componentProperty = null;
        CompositeService compositeService = null;
        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;

        // Read the component scdl

        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
            case START_ELEMENT:
                QName itemName = reader.getName();
                if (!itemName.getNamespaceURI().equals(SCA10_NS))
                    name = new QName(SCA10_NS, itemName.getLocalPart());
                else
                    name = itemName;

                if (SERVICE_QNAME.equals(name)) {
                    if (component != null) {

                        // Read a <component><service>
                        componentService = assemblyFactory
                                .createComponentService();
                        contract = componentService;
                        componentService.setName(getString(reader, NAME));
                        component.getServices().add(componentService);
                        policyProcessor.readPolicies(contract, reader);
                    }

                } else if (REFERENCE_QNAME.equals(name)) {
                    if (component != null) {
                        // Read a <component><reference>
                        componentReference = assemblyFactory
                                .createComponentReference();
                        contract = componentReference;
                        componentReference.setName(getString(reader, NAME));
                        readMultiplicity(componentReference, reader);
                        if (isSet(reader, AUTOWIRE)) {
                            componentReference.setAutowire(getBoolean(reader,
                                    AUTOWIRE));
                        }
                        readTargets(componentReference, reader);
                        componentReference.setWiredByImpl(getBoolean(reader,
                                WIRED_BY_IMPL));
                        component.getReferences().add(componentReference);
                        policyProcessor.readPolicies(contract, reader);
                    }

                } else if (PROPERTY_QNAME.equals(name)) {
                    if (component != null) {

                        // Read a <component><property>
                        componentProperty = assemblyFactory
                                .createComponentProperty();
                        property = componentProperty;
                        componentProperty.setSource(getString(reader, SOURCE));
                        componentProperty.setFile(getString(reader, FILE));
                        policyProcessor.readPolicies(property, reader);
                        readAbstractProperty(componentProperty, reader);

                        // Read the property value
                        Document value = readPropertyValue(property
                                .getXSDElement(), property.getXSDType(), reader);
                        property.setValue(value);

                        component.getProperties().add(componentProperty);
                    }
                } else if (COMPONENT_QNAME.equals(name)) {

                    // Read a <component>
                    component = assemblyFactory.createComponent();
                    component.setName(getString(reader, NAME));
                    if (isSet(reader, AUTOWIRE)) {
                        component.setAutowire(getBoolean(reader, AUTOWIRE));
                    }
                    if (isSet(reader, URI)) {
                        component.setURI(getString(reader, URI));
                    }
                    component.setConstrainingType(readConstrainingType(reader));
                    composite.getComponents().add(component);
                    policyProcessor.readPolicies(component, reader);

                } else if (WIRE_QNAME.equals(name)) {

                    // Read a <wire>
                    wire = assemblyFactory.createWire();
                    ComponentReference source = assemblyFactory
                            .createComponentReference();
                    source.setUnresolved(true);
                    source.setName(getString(reader, SOURCE));
                    wire.setSource(source);

                    ComponentService target = assemblyFactory
                            .createComponentService();
                    target.setUnresolved(true);
                    target.setName(getString(reader, TARGET));
                    wire.setTarget(target);

                    composite.getWires().add(wire);
                    policyProcessor.readPolicies(wire, reader);

                } else if (CALLBACK_QNAME.equals(name)) {

                    // Read a <callback>
                    callback = assemblyFactory.createCallback();
                    contract.setCallback(callback);
                    policyProcessor.readPolicies(callback, reader);

                } else if (OPERATION_QNAME.equals(name)) {

                    // Read an <operation>
                    Operation operation = assemblyFactory.createOperation();
                    operation.setName(getString(reader, NAME));
                    operation.setUnresolved(true);
                    if (callback != null) {
                        policyProcessor.readPolicies(callback, operation,
                                reader);
                    } else {
                        policyProcessor.readPolicies(contract, operation,
                                reader);
                    }
                } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {

                    // Read an implementation.composite
                    Composite implementation = assemblyFactory
                            .createComposite();
                    implementation.setName(getQName(reader, NAME));
                    implementation.setUnresolved(true);
                    component.setImplementation(implementation);
                    policyProcessor.readPolicies(implementation, reader);
                } else {

                    // Read an extension element
View Full Code Here

            composite.setConstrainingType(constrainingType);
        }

        // Resolve includes in the composite
        for (int i = 0, n = composite.getIncludes().size(); i < n; i++) {
            Composite include = composite.getIncludes().get(i);
            if (include != null) {
                include = resolver.resolveModel(Composite.class, include);
                composite.getIncludes().set(i, include);
            }
        }
View Full Code Here

    public void testReadComposite() throws Exception {
        CompositeProcessor compositeProcessor = new CompositeProcessor(new DefaultContributionFactory(), assemblyFactory, policyFactory, staxProcessor);
        InputStream is = getClass().getResourceAsStream("/Calculator.composite");
        XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
        Composite composite = compositeProcessor.read(reader);
        assertNotNull(composite);

        CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, new DefaultIntentAttachPointTypeFactory(), mapper, null);
        compositeUtil.build(composite);
       
        SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0);
        SCABinding serviceSCABinding   = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0);
       
        Assert.assertNotNull(referenceSCABinding);
        Assert.assertNotNull(serviceSCABinding);       

        //new PrintUtil(System.out).print(composite);
View Full Code Here

        ConfiguredNodeImplementation implementation = implementationFactory.createConfiguredNodeImplementation();
        implementation.setUnresolved(true);

        // Read a feed containing links to the composite and the contributions assigned to
        // the node
        Composite composite = null;
        Contribution contribution = null;
        boolean id = false;
        QName name = null;
       
        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {

                case START_ELEMENT:
                    name = reader.getName();

                    if (ENTRY_QNAME.equals(name)) {

                        // Read an <entry>
                        if (implementation.getComposite() == null) {
                            composite = assemblyFactory.createComposite();
                        } else {
                            contribution = contributionFactory.createContribution();
                        }
                    } else if (ID_QNAME.equals(name)) {
                       
                        // Read an <id>
                        id = true;
                       
                    } else if (LINK_QNAME.equals(name)) {

                        // Read a <link>
                        String href = getString(reader, HREF);
                       
                        if (composite != null) {
                            composite.setURI(href);
                        } else if (contribution != null) {
                            contribution.setLocation(href);
                        }
                    }
                    break;
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.assembly.Composite

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.