Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   * 
  *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.    
  */
 
 package org.apache.tuscany.sca.node2;
 
 import java.net.URL;
 
 
 public class NodeFactory {
 
     private Deployer deployer;
 
     public static NodeFactory newInstance() {
         return new NodeFactory(null);
     }
     public static NodeFactory newInstance(Properties config) {
         return new NodeFactory(config);
     }

    
A helper method to simplify creating a standalone Node

Parameters:
compositeURI URI within the contribution of a composite to run if compositeURI is null then all deployable composites in the contribution will be run
contributionURL URL of the contribution
dependentContributionURLs optional URLs of dependent contributions
Returns:
a Node with installed contributions
 
     public static Node newStandaloneNode(String compositeURIString contributionURLString... dependentContributionURLs) {
         try {
             NodeFactory nodeFactory = newInstance();
             EndpointRegistry endpointRegistry = new EndpointRegistryImpl(nodeFactory.extensionPointRegistrynullnull);
             NodeImpl node = new NodeImpl("default"nodeFactory.deployernodeFactory.compositeActivatorendpointRegistrynodeFactory.extensionPointRegistrynodeFactory);
 
             if (dependentContributionURLs != null) {
                 for (int i=dependentContributionURLs.length-1; i>-1; i--) {
                     node.installContribution(nulldependentContributionURLs[i], nullnullfalse);
                 }
             }
 
             String curi = node.installContribution(nullcontributionURLnullnullcompositeURI == null);
             if (compositeURI != null) {
                 node.addToDomainLevelComposite(curicompositeURI);
             }
             return node;
             
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
     protected NodeFactory(Properties config) {
         init(config);
    }
    
    public Node createNode() {
        return createNode(null);
    }
    public Node createNode(String domainURI) {
        String domainName = "default";
        if (domainURI != null){
            domainName = getDomainName(domainURI);
        }
        EndpointRegistry endpointRegistry = .getEndpointRegistry(domainURIdomainName);
        return new NodeImpl(domainNameendpointRegistrynull);
    }
        NodeConfiguration configuration = loadConfiguration(configURL);
        Node node = createNode(configuration.getDomainURI());
        for ( ContributionConfiguration c : configuration.getContributions()) {
        }
        return node;
    }
    public void stop() {
        .stop();
        .stop();
    }
    protected void init(Properties config) {
        if (config == null) {
            config = new Properties();
            config.setProperty("defaultScheme""vm");
            config.setProperty("defaultDomainName""default");
        }
        .start();
        modelFactories.addFactory();
        this. = utilities.getUtility(CompositeActivator.class);
        this. = utilities.getUtility(Deployer.class);
        utilities.getUtility(RuntimeProperties.class).setProperties(config);
        utilities.getUtility(WorkScheduler.class);
        // Initialize the Tuscany module activators
        // The module activators will be started
        this. = ExtensibleDomainRegistryFactory.getInstance();
    }
    
Get the Deployer. The Deployer can be used to create contribution artifacts when configuring a Node programatically.

Returns:
the Deployer
    public Deployer getDeployer() {
        return ;
    }
    
    
Get the AssemblyFactory. The AssemblyFactory can be used to create contribution artifact contents when configuring a Node programatically.

Returns:
the AssemblyFactory
        return ;
    }
    private String getDomainName(String domainURI) {
        int scheme = domainURI.indexOf(':');
        int qm = domainURI.indexOf('?');
        if (qm == -1) {
            return domainURI.substring(scheme+1);
        } else {
            return domainURI.substring(scheme+1, qm);
        }
    }
    protected NodeConfiguration loadConfiguration(String configURL) {
        InputStream xml =null;
        try {
            URL base = IOHelper.getLocationAsURL(configURL);
            xml = IOHelper.openStream(base);
            InputStreamReader reader = new InputStreamReader(xml"UTF-8");
            ProcessorContext context = .createProcessorContext();
            NodeConfiguration config = .loadXMLDocument(readercontext.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(baselocation);
                        url = IOHelper.normalize(url);
                        c.setLocation(url.toString());
                    }
                }
            }
            return config;
        } catch (Throwable e) {
            throw new ServiceRuntimeException(e);
        } finally {
            try {
                if (xml != nullxml.close();
            } catch (IOException e) {
                throw new ServiceRuntimeException(e);
            }
        }
    }
New to GrepCode? Check out our FAQ X