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

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


    public void execute() throws MojoExecutionException, MojoFailureException {
        // getLog().info(String.valueOf(runtimeClasspathElements));
        try {
            NodeFactory factory = NodeFactory.getInstance();
            NodeConfiguration configuration = null;
            if (nodeConfiguration != null) {
                getLog().info("Loading node configuration: " + nodeConfiguration);
                configuration =
                    factory
                        .loadConfiguration(new FileInputStream(nodeConfiguration), nodeConfiguration.toURI().toURL());
View Full Code Here


        });
        return host;
    }

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

        }
    }

    private static NodeConfiguration getNodeConfiguration(WebContextConfigurator configurator) throws IOException,
        URISyntaxException {
        NodeConfiguration configuration = null;
        String nodeConfigURI = configurator.getInitParameter(NODE_CONFIGURATION);
        ServletContext servletContext = configurator.getServletContext();
        if (nodeConfigURI != null) {
            URL url = getResource(servletContext, nodeConfigURI);
            configuration = factory.loadConfiguration(url.openStream(), url);
        } else {
            configuration = factory.createNodeConfiguration();

            boolean explicitContributions = false;
            Enumeration<String> names = configurator.getInitParameterNames();
            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 = configurator.getInitParameter(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)configurator.getInitParameter(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());
                            }
                        }
                    }
                }
            }

            String compositeURI = configurator.getInitParameter(COMPOSITE_URI);
            if (compositeURI == null) {
                compositeURI = getDefaultComposite(configurator);
            }
            URL composite = getResource(servletContext, compositeURI);
            if (configuration.getContributions().isEmpty() || (!explicitContributions && composite != null)) {
                if ("".equals(configurator.getName())) {
                    // Add the root of the web application
                    configuration.addContribution(getResource(servletContext, ROOT));
                } else {
                    // Add a dummy contribution
                    configuration.addContribution(URI.create("sca:contributions/" + configurator.getName()), null);
                }
            }
            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 = configurator.getInitParameter(NODE_URI);
            if (nodeURI == null) {
                nodeURI = getResource(servletContext, ROOT).getPath() + configurator.getName();
            }
            configuration.setURI(nodeURI);
            String domainURI = configurator.getInitParameter(DOMAIN_URI);
            if (domainURI != null) {
                configuration.setDomainURI(domainURI);
            } else {
                domainURI = configurator.getInitParameter("org.apache.tuscany.sca.defaultDomainURI");
                if (domainURI == null) {
                    domainURI = System.getProperty(DOMAIN_URI_PROP);
                }
                if (domainURI != null) {
                    configuration.setDomainURI(getDomainName(domainURI));
                    configuration.setDomainRegistryURI(domainURI);
                }
            }
            String domainRegistryURI = configurator.getInitParameter(DOMAIN_REGISTRY_URI);
            if (domainRegistryURI != null) {
                configuration.setDomainRegistryURI(domainRegistryURI);
            }
        }
        configuration.setAttribute(ServletContext.class.getName(), servletContext);
        if(configurator instanceof ServletConfigurator) {
            configuration.setAttribute(Servlet.class.getName(), ((ServletConfigurator) configurator).servlet);
        }
        return configuration;
    }
View Full Code Here

        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 {
                        Object ext = processor.read(reader, context);
                        if (ext instanceof Endpoint) {
                            node.getEndpointDescriptions().add((Endpoint)ext);
                        } else {
                            node.getExtensions().add(ext);
                        }
                    }
                    break;

                case END_ELEMENT:
View Full Code Here

        }
    }

    @Test
    public final void testNode() throws Exception {
        NodeConfiguration config = NodeFactory.getInstance().createNodeConfiguration();
        config.addContribution(new File("target/test-classes/contribution").toURI().toURL());

        String svg = Main.generateDiagram(config, HelloWorld.class.getClassLoader(), null);
       
        System.out.println(svg);
        FileWriter fw = new FileWriter("target/node.svg");
View Full Code Here

    public void testRead() throws Exception {
        InputStream is = getClass().getResourceAsStream("/org/apache/tuscany/sca/node/configuration/node1.xml");
        XMLInputFactory xmlInputFactory = factories.getFactory(XMLInputFactory.class);
        XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is);
        reader.nextTag();
        NodeConfiguration config = (NodeConfiguration) processor.read(reader, context);
        is.close();       
        StringWriter sw = new StringWriter();
        XMLOutputFactory xmlOutputFactory = factories.getFactory(XMLOutputFactory.class);
        xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
        XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(sw);
View Full Code Here

    @Before
    public void setUp() throws Exception {
        try {        
            NodeFactory factory = NodeFactory.getInstance();
           
            NodeConfiguration configuration = factory.createNodeConfiguration();
            configuration.setDomainURI("tuscany:default");
            configuration.setURI("node1");
            configuration.addContribution("c1", "./target/classes");
            configuration.addDeploymentComposite("c1","CallBackService.composite");

            //node1 = factory.createNode("CallBackService.composite", new Contribution("c1", "./target/classes"));
            node1 = factory.createNode(configuration);
            node1.start();
           
            configuration = factory.createNodeConfiguration();
            configuration.setDomainURI("tuscany:default");
            configuration.setURI("node2");
            configuration.addContribution("c1", "./target/classes");
            configuration.addDeploymentComposite("c1","CallBackReference.composite");
           
            //node2 = factory.newInstance().createNode("CallBackReference.composite", new Contribution("c1", "./target/classes"));
            node2 = factory.createNode(configuration);
            node2.start();
   
View Full Code Here

            } // end for

            node = launcher.createNode(compositeName, contributions);
           
            // Set the domain URI for the node as JCA_9016 tests for this domain name
            NodeConfiguration nodeConfiguration = ((NodeImpl)node).getConfiguration();
            nodeConfiguration.setDomainURI("http://Domain1");
           
            // Start the node
            node.start();
           
            // For debugging
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

    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

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.