Package org.apache.tuscany.sca.node.configuration

Examples of org.apache.tuscany.sca.node.configuration.NodeConfiguration


        return NodeConfiguration.class;
    }

    public NodeConfiguration read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {

        NodeConfiguration node = null;
        ContributionConfiguration contribution = null;
        DeploymentComposite composite = null;
        BindingConfiguration binding = null;

        // Skip to end element
        while (true) {
            int event = reader.getEventType();
            switch (event) {
                case XMLStreamConstants.START_ELEMENT:
                    QName name = reader.getName();
                    if (NODE.equals(name)) {
                        node = nodeConfigurationFactory.createNodeConfiguration();
                        node.setURI(reader.getAttributeValue(null, "uri"));
                        node.setDomainURI(reader.getAttributeValue(null, "domain"));
                        node.setDomainRegistryURI(reader.getAttributeValue(null, "domainRegistry"));
                    } else if (CONTRIBUTION.equals(name)) {
                        contribution = nodeConfigurationFactory.createContributionConfiguration();
                        contribution.setURI(reader.getAttributeValue(null, "uri"));
                        contribution.setLocation(reader.getAttributeValue(null, "location"));
                        contribution.setMetaDataURL(reader.getAttributeValue(null, "metaDataURL"));
                        String startDeployables = reader.getAttributeValue(null, "startDeployables");
                        if (startDeployables != null) {
                            contribution.setStartDeployables(Boolean.parseBoolean(startDeployables));
                        }
                        String dependentURIs = reader.getAttributeValue(null, "dependentURIs");
                        if (dependentURIs != null) {
                            contribution.setDependentContributionURIs(Arrays.asList(dependentURIs.split(",")));
                        }
                        node.getContributions().add(contribution);
                    } else if (BINDING.equals(name)) {
                        binding = nodeConfigurationFactory.createBindingConfiguration();
                        binding.setBindingType(getQName(reader, "name"));
                        String baseURIs = reader.getAttributeValue(null, "baseURIs");
                        if (baseURIs != null) {
                            StringTokenizer tokenizer = new StringTokenizer(baseURIs);
                            while (tokenizer.hasMoreTokens()) {
                                binding.getBaseURIs().add(tokenizer.nextToken());
                            }
                        }
                        node.getBindings().add(binding);
                    } else if (DEPLOYMENT_COMPOSITE.equals(name)) {
                        composite = nodeConfigurationFactory.createDeploymentComposite();
                        composite.setLocation(reader.getAttributeValue(null, "location"));
                        if (contribution != null) {
                            contribution.getDeploymentComposites().add(composite);
                        }
                    } else if(BASE_URI.equals(name)) {
                        // We also support <baseURI> element
                        String baseURI = reader.getElementText();
                        if (baseURI != null && binding != null) {
                            baseURI = baseURI.trim();
                            binding.addBaseURI(baseURI);
                        }
                        // getElementText() moves the event to END_ELEMENT
                        continue;
                    } else if (COMPOSITE.equals(name)) {
                        /*
                        Object model = processor.read(reader);
                        if (model instanceof Composite) {
                            // FIXME: We need to capture the text here
                            // composite.setComposite((Composite)model);
                        }
                        */
                        StringWriter sw = new StringWriter();
                        XMLStreamWriter writer = helper.createXMLStreamWriter(sw);
                        helper.save(reader, writer);
                        composite.setContent(sw.toString());
                    } else {
                        node.getExtensions().add(processor.read(reader, context));
                    }
                    break;

                case END_ELEMENT:
                    name = reader.getName();
View Full Code Here


    public NodeConfiguration loadConfiguration(InputStream xml, URL base) {
        try {
            init();
            InputStreamReader reader = new InputStreamReader(xml, "UTF-8");
            ProcessorContext context = deployer.createProcessorContext();
            NodeConfiguration config = deployer.loadXMLDocument(reader, context.getMonitor());
            if (base != null && config != null) {
                // Resolve the contribution location against the node.xml
                for (ContributionConfiguration c : config.getContributions()) {
                    String location = c.getLocation();
                    if (location != null) {
                        URL url = new URL(base, location);
                        url = IOHelper.normalize(url);
                        c.setLocation(url.toString());
View Full Code Here

        return NodeConfiguration.class;
    }

    public NodeConfiguration read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {

        NodeConfiguration config = factory.createNodeConfiguration();

        // Read a feed containing links to the composite and the contributions assigned to
        // the node
        ContributionConfiguration 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>
                        contribution = factory.createContributionConfiguration();
                    } 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 (contribution != null) {
                            contribution.setLocation(href);
                        }
                    } else if (CONTENT_QNAME.equals(name)) {
                        // Read a <content>
                    } else if (FEED_QNAME.equals(name)) {
                        // Read a <feed>
                    }
                    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 (contribution != null) {
                            config.getContributions().add(contribution);
                        }

                        contribution = null;

                    } else if (ID_QNAME.equals(name)) {
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private static NodeConfiguration getNodeConfiguration(ServletContext servletContext) throws IOException,
        URISyntaxException {
        NodeConfiguration configuration = null;
        String nodeConfigURI = (String)servletContext.getAttribute(NODE_CONFIGURATION);
        if (nodeConfigURI != null) {
            URL url = getResource(servletContext, nodeConfigURI);
            configuration = factory.loadConfiguration(url.openStream(), url);
        } else {
            configuration = factory.createNodeConfiguration();
           
           
            boolean explicitContributions = false;
            Enumeration<String> names = servletContext.getAttributeNames();
            while (names.hasMoreElements()) {
                String name = names.nextElement();
                if (name.equals(CONTRIBUTION) || name.startsWith(CONTRIBUTION + ".")) {
                    explicitContributions = true;
                    // We need to have a way to select one or more folders within the webapp as the contributions
                    String listOfValues = (String)servletContext.getAttribute(name);
                    if (listOfValues != null) {
                        for (String path : parse(listOfValues)) {
                            if ("".equals(path)) {
                                continue;
                            }
                            File f = new File(getResource(servletContext, path).toURI());
                            configuration.addContribution(f.toURI().toURL());
                        }
                    }
                } else if (name.equals(CONTRIBUTIONS) || name.startsWith(CONTRIBUTIONS + ".")) {
                    explicitContributions = true;
                    String listOfValues = (String)servletContext.getAttribute(name);
                    if (listOfValues != null) {
                        for (String path : parse(listOfValues)) {
                            if ("".equals(path)) {
                                continue;
                            }
                            File f = new File(getResource(servletContext, path).toURI());
                            if (f.isDirectory()) {
                                for (File n : f.listFiles()) {
                                    configuration.addContribution(n.toURI().toURL());
                                }
                            } else {
                                configuration.addContribution(f.toURI().toURL());
                            }
                        }
                    }
                }
            }

            URL composite = getResource(servletContext, WEB_COMPOSITE);
            if (configuration.getContributions().isEmpty() || (!explicitContributions && composite != null)) {
                // TODO: Which path should be the default root
                configuration.addContribution(getResource(servletContext, ROOT));
            }
            if (composite != null) {
                configuration.getContributions().get(0).addDeploymentComposite(composite);
            }
            if (!explicitContributions) {
                URL url = getResource(servletContext, DEFAULT_CONTRIBUTIONS);
                if (url != null) {
                    File f = new File(url.toURI());
                    if (f.isDirectory()) {
                        for (File n : f.listFiles()) {
                            configuration.addContribution(n.toURI().toURL());
                        }
                    }
                }
            }
            String nodeURI = (String)servletContext.getAttribute(NODE_URI);
            if (nodeURI == null) {
                nodeURI = new File(servletContext.getRealPath(ROOT)).getName();
            }
            configuration.setURI(nodeURI);
            String domainURI = (String)servletContext.getAttribute(DOMAIN_URI);
            if (domainURI != null) {
                configuration.setDomainURI(domainURI);
            } else {
                domainURI = servletContext.getInitParameter("org.apache.tuscany.sca.defaultDomainURI");
                if (domainURI != null) {
                    configuration.setDomainURI(getDomainName(domainURI));
                    configuration.setDomainRegistryURI(domainURI);
                }
            }
        }
        return configuration;
    }
View Full Code Here

        ExtensionPointRegistry registry = factory.getExtensionPointRegistry();
        return (WebAppServletHost)org.apache.tuscany.sca.host.http.ServletHostHelper.getServletHost(registry);
    }

    private static Node createAndStartNode(final ServletContext servletContext) throws ServletException {
        NodeConfiguration configuration;
        try {
            configuration = getNodeConfiguration(servletContext);
        } catch (IOException e) {
            throw new ServletException(e);
        } catch (URISyntaxException e) {
View Full Code Here

        EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry(domainURI, domainName);
        return new NodeImpl(domainName, deployer, compositeActivator, endpointRegistry, extensionPointRegistry, null);
    }

    public Node createNodeFromXML(String configURL) throws ContributionReadException, ActivationException, ValidationException {
        NodeConfiguration configuration = loadConfiguration(configURL);
        Node node = createNode(configuration.getDomainURI());
        for ( ContributionConfiguration c : configuration.getContributions()) {
            node.installContribution(c.getURI(), c.getLocation(), c.getMetaDataURL(), c.getDependentContributionURIs(), c.isStartDeployables());
        }
        return node;
    }
View Full Code Here

        try {
            URL base = IOHelper.getLocationAsURL(configURL);
            xml = IOHelper.openStream(base);
            InputStreamReader reader = new InputStreamReader(xml, "UTF-8");
            ProcessorContext context = deployer.createProcessorContext();
            NodeConfiguration config = deployer.loadXMLDocument(reader, context.getMonitor());
            if (base != null && config != null) {
                // Resolve the contribution location against the node.xml
                // TODO: absolute locations?
                for (ContributionConfiguration c : config.getContributions()) {
                    String location = c.getLocation();
                    if (location != null) {
                        URL url = new URL(base, location);
                        url = IOHelper.normalize(url);
                        c.setLocation(url.toString());
View Full Code Here

     * @return a new SCA node.
     */
    public Node createNode(URL configurationURL) {
        try {
            InputStream is = openStream(configurationURL);
            NodeConfiguration configuration = loadConfiguration(is, configurationURL);
            return createNode(configuration);
        } catch (IOException e) {
            throw new ServiceRuntimeException(e);
        }
    }
View Full Code Here

     * @param is The input stream that the XML configuration can be read. The stream will be closed
     * after this call.
     * @return a new SCA node
     */
    public Node createNode(InputStream is) {
        NodeConfiguration configuration = loadConfiguration(is, null);
        return createNode(configuration);
    }
View Full Code Here

            if (locations.isEmpty()) {
                throw new ServiceRuntimeException("No SCA contributions are found on the classpath");
            }
            contributions = getContributions(locations);
        }
        NodeConfiguration configuration = createConfiguration(contributions);
        if (deploymentCompositeURI != null && configuration.getContributions().size() > 0) {
            configuration.getContributions().get(0).addDeploymentComposite(createURI(deploymentCompositeURI));
        }
        return createNode(configuration);
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.node.configuration.NodeConfiguration

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.