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

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


        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

                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 (ServiceRuntimeException e) {
View Full Code Here

        logger.log(Level.INFO, "Creating node: " + configurationName);

        try {
            initRuntime();

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

        }
        try {
            // Initialize the runtime
            initRuntime();

            ConfiguredNodeImplementation config = findNodeConfiguration(compositeURI, classLoader);
            configureNode(config);
        } catch (ServiceRuntimeException e) {
            throw e;
        } 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();

        // Default to thread context classloader
        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);
            }
            // Set to relative URI to avoid duplicate loading
            Composite composite = createComposite(compositeURI);
            config.setComposite(composite);
        } else {
            // No composite is specified, tring to search the SCA metadata files
            contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
            contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_META);

            if (contributionArtifactURL == null) {
                contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META;
                contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_GENERATED_META);
            }
            if (contributionArtifactURL == null) {
                contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
                contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_DEPLOYABLES);
            }
           
            // No contribution can be discovered
            if (contributionArtifactURL == null) {
                throw new IllegalArgumentException("No default contribution can be discovered on the classpath");
            }
           
            // No composite will be created, all deployable composites will be used later
        }

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

        return config;
    }
View Full Code Here

        try {
            // Initialize the runtime
            initRuntime();

            URI uri = compositeURI == null ? null : URI.create(compositeURI);
            ConfiguredNodeImplementation configuration = null;
            if (contributions == null || contributions.length == 0) {
                if (uri != null && uri.getScheme() != null) {
                    throw new IllegalArgumentException("No SCA contributions are provided");
                }
                configuration = findNodeConfiguration(compositeURI, null);
            } else {

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

                Composite composite = compositeURI == null ? null : 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: " + compositeURI);

                CompositeDocumentProcessor compositeDocProcessor =
                    (CompositeDocumentProcessor)documentProcessors.getProcessor(Composite.class);
                composite =
                    compositeDocProcessor.read(URI.create(compositeURI), new ByteArrayInputStream(compositeContent
                        .getBytes("UTF-8")));

                analyzeProblems();

                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

            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

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.