Package org.apache.tuscany.sca.implementation.node

Examples of org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation


                artifactProcessors.getProcessor(ConfiguredNodeImplementation.class);
            URL configurationURL = new URL(configurationURI);
            InputStream is = configurationURL.openStream();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
            reader.nextTag();
            ConfiguredNodeImplementation configuration = configurationProcessor.read(reader);
            is.close();

            // Resolve contribution URLs
            for (Contribution contribution : configuration.getContributions()) {
                URL contributionURL = new URL(configurationURL, contribution.getLocation());
                contribution.setLocation(contributionURL.toString());
            }

            // Resolve composite URL
            URL compositeURL = new URL(configurationURL, configuration.getComposite().getURI());
            configuration.getComposite().setURI(compositeURL.toString());

            // Configure the node
            configureNode(configuration);

        } catch (Exception e) {
View Full Code Here


        try {
            // Initialize the runtime
            initRuntime();

            ConfiguredNodeImplementation config = findNodeConfiguration(compositeURI, classLoader);
            configureNode(config);
        } catch (Throwable e) {
            throw new ServiceRuntimeException(e);
        }
    }
View Full Code Here

    private ConfiguredNodeImplementation findNodeConfiguration(final String compositeURI, ClassLoader classLoader)
        throws Exception {
        NodeImplementationFactory nodeImplementationFactory =
            modelFactories.getFactory(NodeImplementationFactory.class);
        ConfiguredNodeImplementation config = nodeImplementationFactory.createConfiguredNodeImplementation();

        if (classLoader == null) {
            classLoader = Thread.currentThread().getContextClassLoader();
        }
        String contributionArtifactPath = compositeURI;
        URL contributionArtifactURL = null;
        if (compositeURI != null) {
            contributionArtifactURL = getResource(classLoader, compositeURI);
            if (contributionArtifactURL == null) {
                throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath);
            }
            composite = createComposite(contributionArtifactURL.toString());
            config.setComposite(composite);
        } else {

            // Here the SCADomain was started without any reference to a composite file
            // We are going to look for an sca-contribution.xml or sca-contribution-generated.xml

            // Look for META-INF/sca-contribution.xml
            contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
            contributionArtifactURL = getResource(classLoader, contributionArtifactPath);

            // Look for META-INF/sca-contribution-generated.xml
            if (contributionArtifactURL == null) {
                contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META;
                contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
            }

            // Look for META-INF/sca-deployables directory
            if (contributionArtifactURL == null) {
                contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
                contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
            } else {
                StAXArtifactProcessor<ContributionMetadata> processor =
                    artifactProcessors.getProcessor(ContributionMetadata.class);
                XMLStreamReader reader = inputFactory.createXMLStreamReader(contributionArtifactURL.openStream());
                metadata = processor.read(reader);
                reader.close();
                if (metadata.getDeployables().isEmpty()) {
                    throw new IllegalArgumentException(
                                                       "No deployable composite is declared in " + contributionArtifactPath);
                }
            }
        }

        if (contributionArtifactURL == null) {
            throw new IllegalArgumentException(
                                               "Can't determine contribution deployables. Either specify a composite file, or use an sca-contribution.xml file to specify the deployables.");
        }

        Contribution c = getContribution(contributionArtifactURL, contributionArtifactPath);
        config.getContributions().add(c);

        return config;
    }
View Full Code Here

        try {
            // Initialize the runtime
            initRuntime();

            ConfiguredNodeImplementation configuration = null;
            if (contributions == null || contributions.length == 0) {
                configuration = findNodeConfiguration(compositeURI, null);
            } else {

                // Create a node configuration
                NodeImplementationFactory nodeImplementationFactory =
                    modelFactories.getFactory(NodeImplementationFactory.class);
                configuration = nodeImplementationFactory.createConfiguredNodeImplementation();

                Composite composite = createComposite(compositeURI);
                configuration.setComposite(composite);

                // Create contribution models
                ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
                for (SCAContribution c : contributions) {
                    Contribution contribution = createContribution(contributionFactory, c);
                    configuration.getContributions().add(contribution);
                }
            }

            // Configure the node
            configureNode(configuration);
View Full Code Here

        try {
            // Initialize the runtime
            initRuntime();

            ConfiguredNodeImplementation configuration = null;
            if (contributions == null || contributions.length == 0) {
                configuration = findNodeConfiguration(compositeURI, null);
            } else {
                // Create a node configuration
                NodeImplementationFactory nodeImplementationFactory =
                    modelFactories.getFactory(NodeImplementationFactory.class);
                configuration = nodeImplementationFactory.createConfiguredNodeImplementation();

                // Read the composite model
                StAXArtifactProcessor<Composite> compositeProcessor = artifactProcessors.getProcessor(Composite.class);
                URL compositeURL = new URL(compositeURI);
                logger.log(Level.INFO, "Loading composite: " + compositeURL);
                XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(compositeContent));
                Composite composite = compositeProcessor.read(reader);
                reader.close();
                configuration.setComposite(composite);

                // Create contribution models
                ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
                for (SCAContribution c : contributions) {
                    Contribution contribution = createContribution(contributionFactory, c);
                    configuration.getContributions().add(contribution);
                }
            }

            // Configure the node
            configureNode(configuration);
View Full Code Here

        return ConfiguredNodeImplementation.class;
    }

    public ConfiguredNodeImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
       
        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;

                case XMLStreamConstants.CHARACTERS:
                   
                    // Read characters inside an <id> element
                    if (id) {
                        if (contribution != null) {
                            contribution.setURI(reader.getText());
                        }
                    }
                    break;

                case END_ELEMENT:
                    name = reader.getName();

                    // Clear current state when reading reaching end element
                    if (ENTRY_QNAME.equals(name)) {
                        if (composite != null) {
                            implementation.setComposite(composite);
                        } else if (contribution != null) {
                            implementation.getContributions().add(contribution);
                        }

                        composite = null;
                        contribution = null;
                       
View Full Code Here

            StAXArtifactProcessor<ConfiguredNodeImplementation> configurationProcessor = artifactProcessors.getProcessor(ConfiguredNodeImplementation.class);
            URL configurationURL = new URL(configurationURI);
            InputStream is = configurationURL.openStream();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
            reader.nextTag();
            ConfiguredNodeImplementation configuration = configurationProcessor.read(reader);
            is.close();
           
            // Resolve contribution URLs
            for (Contribution contribution: configuration.getContributions()) {
                URL contributionURL = new URL(configurationURL, contribution.getLocation());
                contribution.setLocation(contributionURL.toString());
            }
           
            // Resolve composite URL
            URL compositeURL = new URL(configurationURL, configuration.getComposite().getURI());
            configuration.getComposite().setURI(compositeURL.toString());

            // Configure the node
            configureNode(configuration);

        } catch (Exception e) {
View Full Code Here

            // Initialize the runtime
            initRuntime();
           
            // Create a node configuration
            NodeImplementationFactory nodeImplementationFactory = modelFactories.getFactory(NodeImplementationFactory.class);
            ConfiguredNodeImplementation configuration = nodeImplementationFactory.createConfiguredNodeImplementation();
           
            // Create composite model
            AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
            Composite composite = assemblyFactory.createComposite();
            composite.setURI(compositeURI);
            composite.setUnresolved(true);
            configuration.setComposite(composite);
           
            // Create contribution models
            ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
            for (SCAContribution c: contributions) {
                Contribution contribution = contributionFactory.createContribution();
                contribution.setURI(c.getURI());
                contribution.setLocation(c.getLocation());
                contribution.setUnresolved(true);
                configuration.getContributions().add(contribution);
            }

            // Configure the node
            configureNode(configuration);
View Full Code Here

        return ConfiguredNodeImplementation.class;
    }

    public ConfiguredNodeImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
       
        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;

                case XMLStreamConstants.CHARACTERS:
                   
                    // Read characters inside an <id> element
                    if (id) {
                        if (contribution != null) {
                            contribution.setURI(reader.getText());
                        }
                    }
                    break;

                case END_ELEMENT:
                    name = reader.getName();

                    // Clear current state when reading reaching end element
                    if (ENTRY_QNAME.equals(name)) {
                        if (composite != null) {
                            implementation.setComposite(composite);
                        } else if (contribution != null) {
                            implementation.getContributions().add(contribution);
                        }

                        composite = null;
                        contribution = null;
                       
View Full Code Here

            // Initialize the runtime
            init();

            // Create a node configuration
            NodeImplementationFactory nodeImplementationFactory = modelFactories.getFactory(NodeImplementationFactory.class);
            ConfiguredNodeImplementation configuration = nodeImplementationFactory.createConfiguredNodeImplementation();

            if (compositeURI != null) {
                Composite composite = assemblyFactory.createComposite();
                composite.setURI(compositeURI);
                composite.setUnresolved(true);
                configuration.setComposite(composite);
            }
 
                // Create contribution models
            for (org.apache.tuscany.sca.node.Contribution c : contributions) {
                Contribution contribution = contribution(contributionFactory, c);
                configuration.getContributions().add(contribution);
            }

            // Configure the node
            configureNode(configuration);
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation

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.