You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/10/24 06:31:01 UTC

svn commit: r587778 [11/13] - in /incubator/tuscany/branches/sca-java-1.0.1: ./ distribution/ distribution/bundle/ distribution/manifest/ distribution/webapp/src/main/java/org/apache/tuscany/sca/webapp/ distribution/webapp/src/main/resources/_node/ dis...

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/java2wsdl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/java2wsdl/pom.xml?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/java2wsdl/pom.xml (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/java2wsdl/pom.xml Tue Oct 23 21:30:02 2007
@@ -111,6 +111,12 @@
             <groupId>org.apache.axis2</groupId>
             <artifactId>axis2-java2wsdl</artifactId>
             <version>1.3</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.ant</groupId>
+                    <artifactId>ant</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>

Propchange: incubator/tuscany/branches/sca-java-1.0.1/modules/maven-ant-generator/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 23 21:30:02 2007
@@ -0,0 +1,16 @@
+target
+work
+dojo
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+

Copied: incubator/tuscany/branches/sca-java-1.0.1/modules/maven-ant-generator/pom.xml (from r587600, incubator/tuscany/java/sca/modules/maven-ant-generator/pom.xml)
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/maven-ant-generator/pom.xml?p2=incubator/tuscany/branches/sca-java-1.0.1/modules/maven-ant-generator/pom.xml&p1=incubator/tuscany/java/sca/modules/maven-ant-generator/pom.xml&r1=587600&r2=587778&rev=587778&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/maven-ant-generator/pom.xml (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/maven-ant-generator/pom.xml Tue Oct 23 21:30:02 2007
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.apache.tuscany.sca</groupId>
         <artifactId>tuscany-modules</artifactId>
-        <version>1.1-incubating-SNAPSHOT</version>
+        <version>1.0.1-incubating-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
     <artifactId>tuscany-maven-ant-generator</artifactId>

Propchange: incubator/tuscany/branches/sca-java-1.0.1/modules/node-api/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 23 21:30:02 2007
@@ -0,0 +1,4 @@
+.settings
+target
+.classpath
+.project

Copied: incubator/tuscany/branches/sca-java-1.0.1/modules/node-api/pom.xml (from r587600, incubator/tuscany/java/sca/modules/node-api/pom.xml)
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-api/pom.xml?p2=incubator/tuscany/branches/sca-java-1.0.1/modules/node-api/pom.xml&p1=incubator/tuscany/java/sca/modules/node-api/pom.xml&r1=587600&r2=587778&rev=587778&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/node-api/pom.xml (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-api/pom.xml Tue Oct 23 21:30:02 2007
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.tuscany.sca</groupId>
         <artifactId>tuscany-modules</artifactId>
-        <version>1.1-incubating-SNAPSHOT</version>
+        <version>1.0.1-incubating-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
@@ -34,13 +34,13 @@
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-sca-api</artifactId>
-            <version>1.1-incubating-SNAPSHOT</version>
+            <version>1.0.1-incubating-SNAPSHOT</version>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-domain-api</artifactId>
-            <version>1.1-incubating-SNAPSHOT</version>
+            <version>1.0.1-incubating-SNAPSHOT</version>
         </dependency>
  
     </dependencies>

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/pom.xml?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/pom.xml (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/pom.xml Tue Oct 23 21:30:02 2007
@@ -58,6 +58,12 @@
         
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-node-api</artifactId>
+            <version>1.0.1-incubating-SNAPSHOT</version>
+        </dependency>          
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-domain-api</artifactId>
             <version>1.0.1-incubating-SNAPSHOT</version>
         </dependency>        
@@ -88,20 +94,6 @@
             <scope>test</scope>
         </dependency>         
         
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-binding-ws-axis2</artifactId>
-            <version>1.0.1-incubating-SNAPSHOT</version>
-            <scope>test</scope>
-        </dependency>         
-        
-        <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-binding-sca-axis2</artifactId>
-            <version>1.0.1-incubating-SNAPSHOT</version>
-            <scope>test</scope>
-        </dependency>
-        
        <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-binding-jsonrpc</artifactId>
@@ -120,7 +112,21 @@
             <artifactId>tuscany-implementation-resource</artifactId>
             <version>1.0.1-incubating-SNAPSHOT</version>
             <scope>runtime</scope>
-        </dependency>           
+        </dependency>   
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-ws-axis2</artifactId>
+            <version>1.0.1-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>         
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-sca-axis2</artifactId>
+            <version>1.0.1-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
         
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java Tue Oct 23 21:30:02 2007
@@ -27,9 +27,9 @@
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.core.assembly.ActivationException;
 import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl;
+import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime;
 import org.apache.tuscany.sca.node.ComponentListener;
 import org.apache.tuscany.sca.node.ComponentManager;
-import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime;
 
 public class ComponentManagerServiceImpl implements ComponentManager {
 

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java Tue Oct 23 21:30:02 2007
@@ -24,8 +24,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.apache.tuscany.sca.domain.DomainManagerService;
-import org.apache.tuscany.sca.domain.NodeInfo;
+import org.apache.tuscany.sca.domain.DomainManagerNodeEventService;
 import org.osoa.sca.annotations.Property;
 import org.osoa.sca.annotations.Reference;
 import org.osoa.sca.annotations.Scope;
@@ -37,7 +36,7 @@
  * @version $Rev: 552343 $ $Date: 2007-09-07 12:41:52 +0100 (Fri, 07 Sep 2007) $
  */
 @Scope("COMPOSITE")
-public class DomainManagerServiceImpl implements DomainManagerService{
+public class DomainManagerServiceImpl implements DomainManagerNodeEventService{
     
     private final static Logger logger = Logger.getLogger(DomainManagerServiceImpl.class.getName());    
     
@@ -48,21 +47,21 @@
     protected int retryInterval = 5000; //ms    
     
     @Reference
-    protected DomainManagerService domainManager;
+    protected DomainManagerNodeEventService domainManager;
 
-    public String registerNode(String domainUri, String nodeUri) {
+    public String registerNode(String nodeURI, String nodeURL) {
         
         String returnValue = null;
         
         for (int i =0; i < retryCount; i++){
             try {        
-                returnValue =  domainManager.registerNode(domainUri, nodeUri);
+                returnValue =  domainManager.registerNode(nodeURI, nodeURL);
                 break;
             } catch(UndeclaredThrowableException ex) {
                 logger.log(Level.INFO, "Trying to regsiter node " + 
-                                       nodeUri + 
-                                       " with domain " +
-                                       domainUri);
+                                       nodeURI + 
+                                       " at endpoint " +
+                                       nodeURL);
           
             }
             
@@ -75,11 +74,93 @@
         return returnValue;
     }
 
-    public String removeNode(String domainUri, String nodeUri) {
-        return domainManager.removeNode(domainUri, nodeUri);
+    public String removeNode(String nodeURI) {
+        return domainManager.removeNode(nodeURI);
     }
     
-    public List<NodeInfo> getNodeInfo(){
-        return domainManager.getNodeInfo();
+    public void registerContribution(String nodeURI, String contributionURI, String contributionURL){
+        domainManager.registerContribution(nodeURI, contributionURI, contributionURL);
     }
+    
+    public void unregisterContribution(String contributionURI){
+        domainManager.unregisterContribution(contributionURI);
+    }
+
+
+    public String registerServiceEndpoint(String domainUri, String nodeUri, String serviceName, String bindingName, String URL){
+     
+        String dummy = null; 
+        
+        for (int i =0; i < retryCount; i++){
+            try {
+                dummy = domainManager.registerServiceEndpoint(domainUri, nodeUri, serviceName, bindingName, URL);
+                break;
+            } catch(UndeclaredThrowableException ex) {
+                logger.log(Level.INFO, "Trying to connect to domain " + 
+                                       domainUri + 
+                                       " to register service " +
+                                       serviceName);
+          
+            }
+            
+            try {
+                Thread.sleep(retryInterval);
+            } catch(InterruptedException ex) {
+            }
+         }
+        
+        return dummy;
+    }
+    
+    public String removeServiceEndpoint(String domainUri, String nodeUri, String serviceName, String bindingName){
+     
+        String dummy = null; 
+        
+        for (int i =0; i < retryCount; i++){
+            try {
+                dummy = domainManager.removeServiceEndpoint(domainUri, nodeUri, serviceName, bindingName);
+                break;
+            } catch(UndeclaredThrowableException ex) {
+                logger.log(Level.INFO, "Trying to connect to domain " + 
+                                       domainUri + 
+                                       " to remove service " +
+                                       serviceName);
+          
+            }
+            
+            try {
+                Thread.sleep(retryInterval);
+            } catch(InterruptedException ex) {
+            }
+         }
+        
+        return dummy;
+    }    
+   
+    public String findServiceEndpoint(String domainUri, String serviceName, String bindingName){
+
+        
+        String url = null;
+        
+        for (int i =0; i < retryCount; i++){
+            try {
+                url =  domainManager.findServiceEndpoint(domainUri, serviceName, bindingName);
+                break;
+            } catch(UndeclaredThrowableException ex) {
+                logger.log(Level.INFO, "Trying to connect to domain " + 
+                                       domainUri + 
+                                       " to find service " +
+                                       serviceName);
+          
+            }
+            
+            try {
+                Thread.sleep(retryInterval);
+            } catch(InterruptedException ex) {
+            }
+         }
+        
+        return url;
+    }
+ 
 }

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java Tue Oct 23 21:30:02 2007
@@ -19,66 +19,130 @@
 
 package org.apache.tuscany.sca.node.impl;
 
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
 
 import org.apache.tuscany.sca.assembly.Component;
 import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl;
+import org.apache.tuscany.sca.domain.SCADomain;
 import org.apache.tuscany.sca.node.ComponentInfo;
 import org.apache.tuscany.sca.node.ComponentManagerService;
-import org.apache.tuscany.sca.node.SCANode;
 import org.apache.tuscany.sca.node.NodeManagerInitService;
 import org.apache.tuscany.sca.node.NodeManagerService;
+import org.apache.tuscany.sca.node.SCANode;
 import org.osoa.sca.annotations.Scope;
 import org.osoa.sca.annotations.Service;
 
 /**
- * Stores details of services exposed and retrieves details of remote services
+ * Manages a node implementation
  * 
  * @version $Rev: 552343 $ $Date: 2007-09-11 18:45:36 +0100 (Tue, 11 Sep 2007) $
  */
 @Scope("COMPOSITE")
 @Service(interfaces = {NodeManagerService.class, NodeManagerInitService.class, ComponentManagerService.class})
 public class NodeManagerServiceImpl implements NodeManagerService, NodeManagerInitService, ComponentManagerService {
+    
+    private final static Logger logger = Logger.getLogger(NodeManagerServiceImpl.class.getName());
 
-    private SCANode node;
+    private SCANodeImpl node;
 
-    public String getNodeUri() {
-        return node.getNodeURI();
-    }
 
     // NodeManagerInitService
+    
     public void setNode(SCANode node) {
-        this.node = node;
+        this.node = (SCANodeImpl)node;
+    }
+    
+    // NodeManagerSerivice
+    
+    /**
+     * Returns the URI of the SCA node. That URI is the endpoint of the
+     * SCA node administration service.
+     * 
+     * @return the URI of the SCA node
+     */
+    public String getURI(){
+        return node.getURI();
+    }
+        
+    /**
+     * Add an SCA contribution into the node.
+     *  
+     * @param uri the URI of the contribution
+     * @param url the URL of the contribution
+     */
+    public void addContribution(String contributionURI, String contributionURL){
+        try {
+            node.addContribution(contributionURI, new URL(contributionURL));
+        } catch (Exception ex){
+            // TODO - sort out exceptions passing across binding.sca
+            logger.log(Level.SEVERE, ex.toString());
+        }
+    }
+   
+    /**
+     * deploy deployable composite on the node.
+     * 
+     * @param composite
+     */
+    public void deployComposite(String compositeName) {
+        try {
+            node.deployComposite(QName.valueOf(compositeName));
+        } catch (Exception ex){
+            // TODO - sort out exceptions passing across binding.sca
+            logger.log(Level.SEVERE, ex.toString());
+        }
+    }
+    
+    /**
+     * Start the SCA node service.
+     */
+    public void start(){
+        try {
+            node.start();
+        } catch (Exception ex){
+            // TODO - sort out exceptions passing across binding.sca
+            logger.log(Level.SEVERE, ex.toString());
+        }
+    }
+    
+    /**
+     * Stop the SCA node service.
+     */
+    public void stop(){
+        try {
+            node.stop();
+        } catch (Exception ex){
+            // TODO - sort out exceptions passing across binding.sca
+            logger.log(Level.SEVERE, ex.toString());
+        }
     }
 
     // ComponentManagerService
+    
     public List<ComponentInfo> getComponentInfos() {
         List<ComponentInfo> componentInfos = new ArrayList<ComponentInfo>();
-        for (Component component : node.getComponentManager().getComponents()) {
+        for (Component component : node.getComponents()) {
             ComponentInfo componentInfo = new ComponentInfoImpl();
             componentInfo.setName(component.getName());
-            componentInfo.setStarted(node.getComponentManager().isComponentStarted(component));
+            componentInfo.setStarted(((RuntimeComponentImpl)component).isStarted());
             componentInfos.add(componentInfo);
         }
         return componentInfos;
     }
 
     public ComponentInfo getComponentInfo(String componentName) {
-        Component component = node.getComponentManager().getComponent(componentName);
+        Component component = node.getComponent(componentName);
         ComponentInfo componentInfo = new ComponentInfoImpl();
         componentInfo.setName(component.getName());
-        componentInfo.setStarted(node.getComponentManager().isComponentStarted(component));
+        componentInfo.setStarted(((RuntimeComponentImpl)component).isStarted());
         return componentInfo;
     }
 
-    public void startComponent(String componentName) throws ActivationException {
-        node.getComponentManager().startComponent(node.getComponentManager().getComponent(componentName));
-    }
-
-    public void stopComponent(String componentName) throws ActivationException {
-        node.getComponentManager().stopComponent(node.getComponentManager().getComponent(componentName));
-    }
-
-    // TODO - ContributionManagerService
 }

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java Tue Oct 23 21:30:02 2007
@@ -19,107 +19,70 @@
 
 package org.apache.tuscany.sca.node.impl;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetAddress;
-import java.net.ServerSocket;
 import java.net.URI;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
 
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.Component;
-import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.CompositeService;
-import org.apache.tuscany.sca.assembly.SCABinding;
-import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.xml.Constants;
 import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.DeployedArtifact;
 import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl;
 import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.assembly.ActivationException;
-import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
-import org.apache.tuscany.sca.node.ComponentManager;
-import org.apache.tuscany.sca.node.ContributionManager;
-import org.apache.tuscany.sca.node.SCANode;
-import org.apache.tuscany.sca.node.NodeManagerInitService;
 import org.apache.tuscany.sca.domain.SCADomain;
-import org.apache.tuscany.sca.domain.DomainManagerService;
-import org.apache.tuscany.sca.domain.SCADomainService;
-import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain;
 import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime;
-import org.apache.tuscany.sca.interfacedef.InterfaceContract;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.osoa.sca.CallableReference;
-import org.osoa.sca.ServiceReference;
-import org.osoa.sca.ServiceRuntimeException;
+import org.apache.tuscany.sca.node.NodeException;
+import org.apache.tuscany.sca.node.NodeFactoryImpl;
+import org.apache.tuscany.sca.node.SCADomainFinder;
+import org.apache.tuscany.sca.node.SCANode;
 
 /**
  * A local representation of the sca domain running on a single node
  * 
  * @version $Rev: 552343 $ $Date: 2007-09-09 23:54:46 +0100 (Sun, 09 Sep 2007) $
  */
-public class SCANodeImpl extends SCADomain implements SCANode {
+public class SCANodeImpl implements SCANode {
 	
     private final static Logger logger = Logger.getLogger(SCANodeImpl.class.getName());
-	
-    public final static String LOCAL_DOMAIN_URI = "standalonedomain";
-    public final static String LOCAL_NODE_URI = "standalonenode";
-    
-    private boolean isStandalone = false;
-    
-    // the domain used by the node to talk to the rest of the domain
-    private EmbeddedSCADomain managementRuntime;
-    
-    // class loader used to get the runtime going
-    private ClassLoader domainClassLoader;
-    
+	     
     // class loader used to get application resources
-    private ClassLoader applicationClassLoader;    
+    private ClassLoader nodeClassLoader;    
     
-    // representation of the private state of the node that the domain is running on
-    private String domainUri; 
-    private URL domainUrl;
-    private String nodeUri;
-    private URL nodeUrl;
+    // identity and endpoints for the node and the domain it belongs to
+    private String nodeURI;
+    private URL nodeURL;
+    private String domainURI; 
+    private URL domainURL;
+    private String nodeGroupURI;
+
+    // The tuscany runtime that does the hard work
     private ReallySmallRuntime nodeRuntime;
+    
+    // the top level components in this node. A subset of the the domain level composite
     private Composite nodeComposite; 
     
-    // the managers used to control the domain node
-    private ComponentManagerServiceImpl componentManager;
-    private ContributionManagerImpl contributionManager;
-    
-    // the proxies to the domain
-    private SCADomainService scaDomain;
-    private DomainManagerService domainManager;
-    private NodeManagerInitService nodeManagerInit;
+    // the domain that the node belongs to. This object acts as a proxy to the domain
+    private SCADomain scaDomain;
+    
+    // collection for managing contributions that have been added to the node 
+    private Map<String, Contribution> contributions = new HashMap<String, Contribution>();    
+    private Map<QName, Composite> composites = new HashMap<QName, Composite>();
+    private List<QName> compositesToStart = new ArrayList<QName>();
        
     // methods defined on the implementation only
-    
-    /**
-     * Default constructor creates a standalone node with no connectivity to a wider
-     * domain and no local web page. 
-     */
-    public SCANodeImpl()
-      throws ActivationException {
-        this.domainUri = LOCAL_DOMAIN_URI ; 
-        this.nodeUri = LOCAL_NODE_URI;
-        this.domainClassLoader = SCANodeImpl.class.getClassLoader(); 
-        this.applicationClassLoader = Thread.currentThread().getContextClassLoader();                
-        this.isStandalone = true;
-        init();
-    }
        
     /** 
      * Creates a node connected to a wider domain.  To find its place in the domain 
@@ -127,15 +90,15 @@
      * 
      * @param domainUri - identifies what host and port the domain service is running on, e.g. http://localhost:8081
      * @param nodeUri - if this is a url it is assumed that this will be used as root url for management components, e.g. http://localhost:8082
+     * @param nodeGroupURI the uri of the node group. This is the enpoint URI of the head of the
+     * group of nodes. For example, in load balancing scenarios this will be the loaded balancer itself 
      * @throws ActivationException
      */
-    public SCANodeImpl(String domainUri, String nodeUri)
-    throws ActivationException {
-        this.domainUri = domainUri;
-        this.nodeUri = nodeUri;
-        this.domainClassLoader = SCANodeImpl.class.getClassLoader(); 
-        this.applicationClassLoader = Thread.currentThread().getContextClassLoader();        
-        this.isStandalone = LOCAL_DOMAIN_URI.equals(domainUri);
+    public SCANodeImpl(String nodeURI, String domainURI, String nodeGroupURI) throws NodeException {
+        this.domainURI = domainURI;
+        this.nodeURI = nodeURI;
+        this.nodeGroupURI = nodeGroupURI;
+        this.nodeClassLoader = Thread.currentThread().getContextClassLoader();        
         init();
     }    
     
@@ -145,58 +108,17 @@
      * 
      * @param domainUri - identifies what host and port the domain service is running on, e.g. http://localhost:8081
      * @param nodeUri - if this is a url it is assumed that this will be used as root url for management components, e.g. http://localhost:8082
+     * @param nodeGroupURI the uri of the node group. This is the enpoint URI of the head of the
+     * group of nodes. For example, in load balancing scenarios this will be the loaded balancer itself 
      * @param cl - the ClassLoader to use for loading system resources for the node
      * @throws ActivationException
      */
-    public SCANodeImpl(String domainUri, String nodeUri, ClassLoader cl)
-    throws ActivationException {
-        this.domainUri = domainUri;
-        this.nodeUri = nodeUri;
-        this.domainClassLoader = cl;
-        this.applicationClassLoader = Thread.currentThread().getContextClassLoader();
-        this.isStandalone = LOCAL_DOMAIN_URI.equals(domainUri);
+    public SCANodeImpl(String nodeURI, String domainURI, String nodeGroupURI, ClassLoader cl) throws NodeException {
+        this.domainURI = domainURI;
+        this.nodeURI = nodeURI;
+        this.nodeGroupURI = nodeGroupURI;
+        this.nodeClassLoader = cl;
         init();
-    } 
-    
-    /** 
-     * Creates a node connected to a wider domain and allows a classpath to be specified.  
-     * To find its place in the domain node and domain identifiers must be provided. 
-     * 
-     * @param domainUri - identifies what host and port the domain service is running on, e.g. http://localhost:8081
-     * @param nodeUri - if this is a url it is assumed that this will be used as root url for management components, e.g. http://localhost:8082
-     * @param cl - the ClassLoader to use for loading system resources for the node
-     * @param applicationCl - the ClassLoader to use for loading application resources for the node
-     * @throws ActivationException
-     */
-    public SCANodeImpl(String domainUri, String nodeUri, ClassLoader cl, ClassLoader applicationCl, String contributionPath, String[] composites)
-    throws ActivationException {
-        this.domainUri = domainUri;
-        this.nodeUri = nodeUri;
-        this.domainClassLoader = cl;
-        this.applicationClassLoader = applicationCl;        
-        this.isStandalone = LOCAL_DOMAIN_URI.equals(domainUri);
-        init();
-        start();        
-        
-        try {
-            URL contributionURL = SCANodeUtil.findContributionURLFromCompositeNameOrPath(applicationClassLoader, contributionPath, composites);
-            
-            contributionManager.addContribution(contributionURL);
-            
-            if (composites.length > 0 ){
-                for(int i = 0; i < composites.length; i++) {
-                    contributionManager.addComposite(composites[i]);
-                    contributionManager.startComposite(composites[i]);
-                }
-            } else {
-                contributionManager.addAllComposites(contributionURL);
-                contributionManager.startAllComposites(contributionURL);
-            }
-             
-        } catch(Exception ex) {
-            throw new ActivationException(ex);
-        }
-        
     }    
     
     /**
@@ -204,348 +126,253 @@
      * get domain information. This all depends on whether there is a management
      * composite on the classpath
      */
-    private void init()
-      throws ActivationException {
+    private void init() throws NodeException {
         try {
             
             // create a node runtime for the domain contributions to run on
-            nodeRuntime = new ReallySmallRuntime(domainClassLoader);
+            nodeRuntime = new ReallySmallRuntime(nodeClassLoader);
+            
+            // Start the runtime
+            nodeRuntime.start();
+            
+            // Create an in-memory domain level composite
+            AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
+            nodeComposite = assemblyFactory.createComposite();
+            nodeComposite.setName(new QName(Constants.SCA10_NS, "node"));
+            nodeComposite.setURI(nodeURI);
+            
+            // add the top level composite into the composite activator
+            nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite);             
           
-            // Check if node has been given a domain name to connect to
-            if (isStandalone) {
-            	logger.log(Level.INFO, "Domain node will be started stand-alone as node and domain URIs are not provided");
-            	managementRuntime = null;
-            	scaDomain = null;
-            } else {
-                // check where domain and node uris are urls, they will be used to configure various
-                // endpoints if they are
-                URI tmpURI;
-                try {
-                    tmpURI = new URI(domainUri); 
-                    if (tmpURI.isAbsolute()){
-                        domainUrl = tmpURI.toURL();
-                    }
-                } catch(Exception ex) {
-                    throw new ActivationException("domain uri " + 
-                                                  domainUri + 
-                                                  "must be a valid url");
-                }
-                
-                try {
-                    tmpURI = new URI(nodeUri); 
-                    if (tmpURI.isAbsolute()){
-                        nodeUrl = tmpURI.toURL();
-                    }
-                } catch(Exception ex) {
-                    nodeUrl = null;
+            // check whether node uri is an absolute url,            
+            try {
+                URI tmpURI = new URI(nodeURI); 
+                if (tmpURI.isAbsolute()){
+                    nodeURL = tmpURI.toURL();
                 }
-
-                createManagementNode();
+            } catch(Exception ex) {
+                nodeURL = null;
+            }
+            
+            // create a link to the domain 
+            scaDomain = SCADomainFinder.newInstance().getSCADomain(domainURI);
+            
+            // add the node to the domain
+            ((SCADomainImpl)scaDomain).addNode(this);  
+            
+            // If a non-null domain name is provided make the node available to the model
+            // this causes the runtime to start registering binding-sca service endpoints
+            // with the domain so only makes sense if we know we have a domain to talk to
+            if (domainURI != null) {
+                ModelFactoryExtensionPoint factories = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
+                NodeFactoryImpl nodeFactory = new NodeFactoryImpl(this);
+                factories.addFactory(nodeFactory);    
             }
-        } catch(ActivationException ex) {
-            throw ex;                        
+ 
         } catch(Exception ex) {
-            throw new ActivationException(ex);
+            throw new NodeException(ex);
         }
     }
     
-    private void createManagementNode()
-      throws ActivationException {
-        try {
-            // create a runtime for components to run on that will be used for talking to the 
-            // rest of the domain. The components are defined in the node.composite file
-            String nodeCompositeName = "node.composite";
-            URL contributionURL = SCANodeUtil.findContributionURLFromCompositeNameOrPath(domainClassLoader, null, new String[]{nodeCompositeName} );
-            
-            if ( contributionURL != null ){ 
-                logger.log(Level.INFO, "Node management configured from " + contributionURL);
-                
-                // start a local domain in order to talk to the logical domain
-                managementRuntime = new EmbeddedSCADomain(domainClassLoader, "node");   
-                managementRuntime.start();
-            
-                // add node composite to the management domain
-                ContributionService contributionService = managementRuntime.getContributionService();
-                Contribution contribution = null;
-
-	            contribution = contributionService.contribute(nodeUri, 
-	                                                          contributionURL, 
-	                                                          false);
-                
-                if (contribution.getDeployables().size() != 0) {
-                    Composite composite = contribution.getDeployables().get(0);
-                
-                    managementRuntime.getDomainComposite().getIncludes().add(composite);
-                    managementRuntime.getCompositeBuilder().build(composite);
-                    
-                    // deal with the special case of registering the node manager service 
-                    // in service discovery. It's not on an SCA binding. 
-                    // TODO - really want to be able to hand out service references but they
-                    //        don't serialize out over web services yet. 
-                    SCANodeUtil.fixUpNodeServiceUrls(managementRuntime.getDomainComposite().getIncludes().get(0).getComponents(), nodeUrl); 
-                    SCANodeUtil.fixUpNodeReferenceUrls(managementRuntime.getDomainComposite().getIncludes().get(0).getComponents(), domainUrl);  
-                  
-                    managementRuntime.getCompositeActivator().activate(composite); 
-                    managementRuntime.getCompositeActivator().start(composite);
-                
-                    // get the management components out of the domain so that they 
-                    // can be configured/used. 
-                    scaDomain =  managementRuntime.getService(SCADomainService.class, "SCADomainComponent");
-                    domainManager = managementRuntime.getService(DomainManagerService.class, "DomainManagerComponent");
-                    nodeManagerInit = managementRuntime.getService(NodeManagerInitService.class, "NodeManagerComponent/NodeManagerInitService");
-                    
-                    // Now get the uri back out of the component now it has been built and started
-                    // TODO - this doesn't pick up the url from external hosting environments
-                    String nodeManagerUrl = SCANodeUtil.getNodeManagerServiceUrl(managementRuntime.getDomainComposite().getIncludes().get(0).getComponents());
-                    
-                    if (nodeManagerUrl != null) {
-                        if (isStandalone == false){
-                            try {
-                                
-                                scaDomain.registerServiceEndpoint(domainUri, 
-                                                                  nodeUri, 
-                                                                  nodeUri + "NodeManagerService",
-                                                                  "",
-                                                                  nodeManagerUrl);
-                                
-                            } catch(Exception ex) {
-                                logger.log(Level.SEVERE,  
-                                           "Can't connect to domain manager at: " + 
-                                           domainUrl);
-                                throw new ActivationException(ex);
-                            }
-                        }                        
-                    }
-                        
-                } else {
-                    throw new ActivationException("Node management contribution " + 
-                                                  contributionURL + 
-                                                  " found but could not be loaded");
+    // temp methods to help integrate with existing code
+    
+    public ReallySmallRuntime getNodeRuntime() {
+        return nodeRuntime;
+    }
+    
+    public Component getComponent(String componentName) {
+        for (Composite composite: nodeComposite.getIncludes()) {
+            for (Component component: composite.getComponents()) {
+                if (component.getName().equals(componentName)) {
+                    return component;
                 }
-            } else {
-                throw new ActivationException("Node management contribution " + 
-                                              nodeCompositeName + 
-                                              " not found on the classpath");
             }
-        } catch(ActivationException ex) {
-            throw ex;                        
-        } catch(Exception ex) {
-            throw new ActivationException(ex);
         }
-    }   
+        return null;
+    }    
     
-        
-    // methods that implement interfaces 
+    public List<Component> getComponents() {
+        List<Component> components = new ArrayList<Component>();
+        for (Composite composite: nodeComposite.getIncludes()) {
+            components.addAll(composite.getComponents());
+        }
+        return components;
+    }    
     
-    public void start() throws ActivationException {
-        // Start the runtime
-        nodeRuntime.start();
-        
-        // Create an in-memory domain level composite
-        AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
-        nodeComposite = assemblyFactory.createComposite();
-        nodeComposite.setName(new QName(Constants.SCA10_NS, "domain"));
-        nodeComposite.setURI(domainUri);
-        
-        // add the top level composite into the composite activator
-        nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite);  
+    /**
+     * Stating to think about how a node advertises what it can do. 
+     * Maybe need to turn this round and ask the node to decide whether it
+     * can process a list of artifacts
+     * @return
+     */
+    public List<String> getFeatures() {
+        List<String> featureList = new ArrayList<String>();
         
-        // make the domain available to the model. 
-        // TODO - No sure how this should be done properly. As a nod to this though
-        //        I have a domain factory which always returns the same domain
-        //        object. I.e. this node
-        ModelFactoryExtensionPoint factories = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
-        NodeFactoryImpl domainFactory = new NodeFactoryImpl(this);
-        factories.addFactory(domainFactory);
+        ExtensionPointRegistry registry = nodeRuntime.getExtensionPointRegistry();
         
-        // create the domain node managers
-        componentManager = new ComponentManagerServiceImpl(domainUri, nodeUri, nodeComposite, nodeRuntime);
-        contributionManager = new ContributionManagerImpl(domainUri, nodeUri, nodeComposite, nodeRuntime, applicationClassLoader, null);
+        // TODO - how to get registered features?
+        ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
         
-        if (isStandalone == false){
-            // pass this object into the node manager
-            nodeManagerInit.setNode((SCANode)this);
-            
-            try {
-                // go out and add this node to the wider domain
-                domainManager.registerNode(domainUri, nodeUri);
-            } catch(Exception ex) {
-                logger.log(Level.SEVERE,  
-                           "Can't connect to domain manager at: " + 
-                           domainUrl);
-                throw new ActivationException(ex);
-            }
-        }
+        return null;
     }
     
-    @Override
-    public void close() {
+    
+    // API methods 
+    
+    public void start() throws NodeException {
+        startComposites();
+    }
+    
+    public void stop() throws NodeException {
         try {
-            stop();
+            // remove contributions
+            removeAllContributions();           
         } catch (Exception ex) {
-            throw new ServiceRuntimeException(ex);
-        }
-    }
-
-    public void stop() throws ActivationException {
-        // stop the components
-        
-        // remove contributions
-        
-        // Stop the node
-    	nodeRuntime.stop();
-        
-        // Cleanup the top level composite
-        nodeComposite = null;
-        
-        // remove the manager objects
-        
-        // go out and remove this node from the wider domain
-        if (isStandalone == false){
-            try {
-                domainManager.removeNode(domainUri, nodeUri);
-            } catch(Exception ex) {
-                logger.log(Level.SEVERE,  
-                        "Can't connect to domain manager at: " + 
-                        domainUrl);
-                throw new ActivationException(ex);
-            }
+            throw new NodeException(ex);
         }
     }    
  
     public String getURI(){
-        return domainUri;
+        return nodeURI;
     }
     
-    public String getDomainURI(){
-        return domainUri;
-    }
-    
-    public String getNodeURI(){
-        return nodeUri;
-    }  
+    public SCADomain getDomain(){
+        return scaDomain;
+    }   
     
-    public URL getDomainURL(){
-        return domainUrl;
+    public void addContribution(String contributionURI, URL contributionURL) throws NodeException {
+        addContribution(contributionURI, contributionURL, null);
     }
     
-    public URL getNodeURL(){
-        return nodeUrl;
-    }     
-    
-    public ComponentManager getComponentManager() {
-        return componentManager;
-    } 
-    
-    public ContributionManager getContributionManager() {    	
-        return contributionManager;
-    }     
-      
-    
-    /**
-     * Return an interface for registering local services and for
-     * finding remote services
-     * 
-     * @return The service discovery interface
-     */    
-    public SCADomainService getDomainService(){
-        return scaDomain;
-    }
-       
-    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
-        return (R)nodeRuntime.getProxyFactory().cast(target);
+    public void addContribution(String contributionURI, URL contributionURL, ClassLoader contributionClassLoader ) throws NodeException {
+       try {            
+            if (contributionURL != null) {
+                ModelResolver modelResolver = null;
+                
+                // if the contribution is to be resolved using a separate class loader
+                // then create a new model resolver
+                if (contributionClassLoader != null)  {
+                    modelResolver = new ModelResolverImpl(contributionClassLoader);
+                }
+                
+                // Add the contribution to the node
+                ContributionService contributionService = nodeRuntime.getContributionService();
+                Contribution contribution = contributionService.contribute(contributionURI, 
+                                                                           contributionURL, 
+                                                                           modelResolver, 
+                                                                           false);
+                
+                // remember the contribution
+                contributions.put(contributionURI, contribution);
+                    
+                // remember all the composites that have been found
+                for (DeployedArtifact artifact : contribution.getArtifacts()) {
+                    if (artifact.getModel() instanceof Composite) {
+                        Composite composite = (Composite)artifact.getModel();
+                        composites.put(composite.getName(), composite);
+                    }
+                }
+                
+                // remember all the deployable composites ready to be started
+                for (Composite composite : contribution.getDeployables()) {
+                    compositesToStart.add(composite.getName());
+                }  
+                
+                
+                // add the contribution to the domain. It will generally already be there
+                // unless the contribution has been added to the node itself. 
+                ((SCADomainImpl)scaDomain).registerContribution(nodeURI, contributionURI, contributionURL.toExternalForm());                  
+                
+            } else {
+                    throw new ActivationException("Contribution " + contributionURL + " not found");
+            }  
+        } catch (Exception ex) {
+            throw new NodeException(ex);
+        }        
     }
 
-    public <B> B getService(Class<B> businessInterface, String serviceName) {
-        ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);
-        if (serviceReference == null) {
-            throw new ServiceRuntimeException("Service not found: " + serviceName);
-        }
-        return serviceReference.getService();
+    private void removeAllContributions() throws NodeException {
+        try {     
+            // stop any running composites
+            stopComposites();
+            
+            // Remove all contributions
+            for (String contributionURI : contributions.keySet()){
+                nodeRuntime.getContributionService().remove(contributionURI);
+                contributions.remove(contributionURI);
+            }
+        } catch (Exception ex) {
+            throw new NodeException(ex);
+        }   
     }
-
-    private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
-        try {
-            AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
-            Composite composite = assemblyFactory.createComposite();
-            composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
-            RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
-            component.setName("default");
-            component.setURI("default");
-            nodeRuntime.getCompositeActivator().configureComponentContext(component);
-            composite.getComponents().add(component);
-            RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
-            reference.setName("default");
-            ModelFactoryExtensionPoint factories =
-            	nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
-            JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
-            InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
-            interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
-            reference.setInterfaceContract(interfaceContract);
-            component.getReferences().add(reference);
-            reference.setComponent(component);
-            SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
-            SCABinding binding = scaBindingFactory.createSCABinding();
-            binding.setURI(targetURI);
-            reference.getBindings().add(binding);       
-            return new ServiceReferenceImpl<B>(businessInterface, component, reference, binding, nodeRuntime
-                .getProxyFactory(), nodeRuntime.getCompositeActivator());
-        } catch (Exception e) {
-            throw new ServiceRuntimeException(e);
+    
+    public void deployComposite(QName compositeName) throws NodeException {
+        // if the named composite is not already in the list then 
+        // add it
+        if (compositesToStart.indexOf(compositeName) == -1 ){
+            compositesToStart.add(compositeName);  
         }
     }
-
-    public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
-
-        // Extract the component name
-        String componentName;
-        String serviceName;
-        int i = name.indexOf('/');
-        if (i != -1) {
-            componentName = name.substring(0, i);
-            serviceName = name.substring(i + 1);
-
-        } else {
-            componentName = name;
-            serviceName = null;
-        }
-
-        // Lookup the component in the domain
-        Component component = componentManager.getComponent(componentName);
-        if (component == null) {
-            // The component is not local in the partition, try to create a remote service ref
-            return createServiceReference(businessInterface, name);
-        }
-        RuntimeComponentContext componentContext = null;
-
-        // If the component is a composite, then we need to find the
-        // non-composite component that provides the requested service
-        if (component.getImplementation() instanceof Composite) {
-            for (ComponentService componentService : component.getServices()) {
-                if (serviceName == null || serviceName.equals(componentService.getName())) {
-                    CompositeService compositeService = (CompositeService)componentService.getService();
-                    if (compositeService != null) {
-                        if (serviceName != null) {
-                            serviceName = "$promoted$." + serviceName;
-                        }
-                        componentContext =
-                            ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
-                        return componentContext.createSelfReference(businessInterface, compositeService
-                            .getPromotedService());
+    
+    private void startComposites() throws NodeException {
+        try {
+            if (compositesToStart.size() == 0 ){
+                logger.log(Level.INFO, nodeURI + 
+                                       " has no composites to start" );
+            } else {  
+                for (QName compositeName : compositesToStart) {
+                    Composite composite = composites.get(compositeName);
+                    
+                    if (composite == null) {
+                        logger.log(Level.INFO, "Composite not found during start: " + compositeName);
+                    } else {
+                        logger.log(Level.INFO, "Starting composite: " + compositeName);
+                        
+                        // Add the composite to the top level domain
+                        nodeComposite.getIncludes().add(composite);
+                        nodeRuntime.getCompositeBuilder().build(composite); 
+                        
+                        // activate the composite
+                        nodeRuntime.getCompositeActivator().activate(composite);              
+                        
+                        //start the composite
+                        nodeRuntime.getCompositeActivator().start(composite);
                     }
-                    break;
                 }
             }
-            // No matching service is found
-            throw new ServiceRuntimeException("Composite service not found: " + name);
-        } else {
-            componentContext = ((RuntimeComponent)component).getComponentContext();
-            if (serviceName != null) {
-                return componentContext.createSelfReference(businessInterface, serviceName);
-            } else {
-                return componentContext.createSelfReference(businessInterface);
+
+        } catch (Exception ex) {
+            throw new NodeException(ex);
+        }  
+    }    
+
+    private void stopComposites() throws NodeException {
+        
+        try {
+            if (compositesToStart.size() == 0 ){
+                throw new NodeException("Stopping node " + 
+                                        nodeURI + 
+                                        " with no composite started");
             }
-        }
-    }
+            for (QName compositeName : compositesToStart) {
+                logger.log(Level.INFO, "Stopping composite: " + compositeName);
+                
+                Composite composite = composites.get(compositeName);   
+
+                nodeRuntime.getCompositeActivator().stop(composite);
+                nodeRuntime.getCompositeActivator().deactivate(composite);
+                
+                composites.remove(compositeName);               
+            }
+            
+            compositesToStart.clear(); 
+        } catch (NodeException ex) {
+        throw ex;            
+            
+        } catch (Exception ex) {
+            throw new NodeException(ex);
+        }              
 
+    }
+      
 }

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java Tue Oct 23 21:30:02 2007
@@ -27,7 +27,6 @@
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.List;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.tuscany.sca.assembly.Binding;
@@ -38,11 +37,6 @@
 import org.apache.tuscany.sca.contribution.Contribution;
 import org.apache.tuscany.sca.contribution.service.util.FileHelper;
 import org.apache.tuscany.sca.core.assembly.ActivationException;
-import org.apache.tuscany.sca.domain.SCADomainService;
-import org.apache.tuscany.sca.node.NodeFactory;
-import org.apache.tuscany.sca.domain.SCADomain;
-import org.osoa.sca.CallableReference;
-import org.osoa.sca.ServiceReference;
 
 
 /**
@@ -63,80 +57,7 @@
      * @return the contribution URL
      * @throws MalformedURLException
      */
-/* original version
-    public static URL findContributionURLFromCompositeNameOrPath(ClassLoader classLoader, String contributionPath, String[] composites)
-    throws MalformedURLException {
-      if (contributionPath != null && contributionPath.length() > 0) {
-          //encode spaces as they would cause URISyntaxException
-          contributionPath = contributionPath.replace(" ", "%20");
-          URI contributionURI = URI.create(contributionPath);
-          if (contributionURI.isAbsolute() || composites.length == 0) {
-              return new URL(contributionPath);
-          }
-      }
-  
-      String contributionArtifactPath = null;
-      URL contributionArtifactURL = null;
-      if (composites != null && composites.length > 0 && composites[0].length() > 0) {
-  
-          // Here the SCADomain was started with a reference to a composite file
-          contributionArtifactPath = composites[0];
-          contributionArtifactURL = classLoader.getResource(contributionArtifactPath);
-          if (contributionArtifactURL == null) {
-              throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath);
-          }
-      } else {
-  
-          // Here the SCANode 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 = classLoader.getResource(contributionArtifactPath);
-  
-          // Look for META-INF/sca-contribution-generated.xml
-          if (contributionArtifactURL == null) {
-              contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META;
-              contributionArtifactURL = classLoader.getResource(contributionArtifactPath);
-          }
-  
-          // Look for META-INF/sca-deployables directory
-          if (contributionArtifactURL == null) {
-              contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
-              contributionArtifactURL = classLoader.getResource(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.");
-      }
-  
-      URL contributionURL = null;
-      // "jar:file://....../something.jar!/a/b/c/app.composite"
-      try {
-          String url = contributionArtifactURL.toExternalForm();
-          String protocol = contributionArtifactURL.getProtocol();
-          if ("file".equals(protocol)) {
-              // directory contribution
-              if (url.endsWith(contributionArtifactPath)) {
-                  String location = url.substring(0, url.lastIndexOf(contributionArtifactPath));
-                  // workaround from evil url/uri form maven
-                  contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL();
-              }
-  
-          } else if ("jar".equals(protocol)) {
-              // jar contribution
-              String location = url.substring(4, url.lastIndexOf("!/"));
-              // workaround for evil url/uri from maven
-              contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL();
-          }
-      } catch (MalformedURLException mfe) {
-          throw new IllegalArgumentException(mfe);
-      }
-  
-      return contributionURL;
-  }   
- */
+
     public static URL findContributionURLFromCompositeNameOrPath(ClassLoader classLoader, String contributionPath, String[] composites)
       throws MalformedURLException {
         
@@ -221,56 +142,11 @@
         return contributionURL;
     }	
     
-	/**
-	 * Given the name of a composite this method finds the contribution that it belongs to
-	 * this could be either a local directory of a jar file.
-	 * 
-	 * @param classLoader
-	 * @param compositeString
-	 * @return the contribution URL
-	 * @throws MalformedURLException
-	 */
-/*    
-    public static URL findContributionFromComposite(ClassLoader classLoader, String compositeString)
-      throws MalformedURLException {
-    	   	
-        URL contributionURL = classLoader.getResource(compositeString);
-        
-        if ( contributionURL != null ){ 
-            String contributionString = contributionURL.toExternalForm();
-            int jarPosition = contributionString.indexOf(".jar");
-    	
-            if (jarPosition> -1){
-                // if the node dir is in a jar just contribute the name of the jar file
-                // rather the name of the directory in the jar file.
-                // changing
-                //   jar:file:/myjarfile.jar!/contributiondir
-                // to
-                //   file:/myjarfile.jar
-                contributionString = contributionString.substring(0, jarPosition + 4);
-                contributionString = contributionString.substring(4);
-                contributionURL = new URL(contributionString);  
-            } else {
-                // Assume the node.composite file is in a directory so find the directory name
-                // changing
-                //   file:/mydir/node.composite
-                // to 
-                //   file:/mydir
-                int compositePosition = contributionString.indexOf(compositeString);
-                contributionString = contributionString.substring(0, compositePosition);
-                contributionURL = new URL(contributionString);
-            } 
-        } 
-        
-    	return contributionURL;
-    } 
-*/  
-    
     /** 
      * A rather ugly method to find and fix the url of the service, assuming that there
      * is one. 
      *  
-     * we can't get is out of a service reference
+     * we can't get this out of a service reference
      * the component itself doesn't know how to get it  
      * the binding can't to do it automatically as it's not the sca binding
      * 

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/resources/node.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/resources/node.composite?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/resources/node.composite (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/main/resources/node.composite Tue Oct 23 21:30:02 2007
@@ -29,6 +29,14 @@
            xmlns:sample="http://management"
            xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
            name="Management">
+          
+    <component name="DomainManagerComponent">
+        <implementation.java class="org.apache.tuscany.sca.node.impl.DomainManagerServiceImpl"/>
+        <reference name="domainManager">
+            <interface.java interface="org.apache.tuscany.sca.domain.DomainManagerNodeEventService"/>
+            <binding.ws uri="http://localhost:8878/DomainManagerComponent/DomainManagerNodeEventService"/>
+        </reference>
+    </component>           
            
     <component name="NodeManagerComponent">
         <implementation.java class="org.apache.tuscany.sca.node.impl.NodeManagerServiceImpl"/>
@@ -38,28 +46,13 @@
         </service>
         <service name="NodeManagerService">
             <interface.java interface="org.apache.tuscany.sca.node.NodeManagerService"/>
-            <tuscany:binding.jsonrpc uri="http://localhost:8878/NodeManagerComponent/NodeManagerJson"/>
+            <binding.ws uri="http://localhost:8878/NodeManagerComponent/NodeManagerService"/>
         </service>
         <service name="ComponentManagerService">
             <interface.java interface="org.apache.tuscany.sca.node.ComponentManagerService"/>
             <tuscany:binding.jsonrpc uri="http://localhost:8878/NodeManagerComponent/ComponentManagerJson"/>
         </service>
     </component>           
-    
-    <component name="DomainManagerComponent">
-        <implementation.java class="org.apache.tuscany.sca.node.impl.DomainManagerServiceImpl"/>
-        <reference name="domainManager">
-            <interface.java interface="org.apache.tuscany.sca.domain.DomainManagerService"/>
-            <binding.ws uri="http://localhost:8878/DomainManagerComponent/DomainManager"/>
-        </reference>
-    </component>
-    
-    <component name="SCADomainComponent">
-        <implementation.java class="org.apache.tuscany.sca.node.impl.SCADomainServiceImpl" />
-        <reference name="scaDomainService">
-            <binding.ws uri="http://localhost:8878/SCADomainComponent/SCADomainService"/>
-        </reference>
-    </component>
 
     <component name="node">
        <tuscany:implementation.resource location="webroot"/>
@@ -67,6 +60,5 @@
             <tuscany:binding.http uri="http://localhost:8878/node"/>
         </service>
     </component>    
-    
 
 </composite>

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/java/calculator/CalculatorService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/java/calculator/CalculatorService.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/java/calculator/CalculatorService.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/java/calculator/CalculatorService.java Tue Oct 23 21:30:02 2007
@@ -18,10 +18,13 @@
  */
 package calculator;
 
+import org.osoa.sca.annotations.Remotable;
+
 
 /**
  * The Calculator service interface.
  */
+@Remotable
 public interface CalculatorService {
 
     double add(double n1, double n2);

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeA/Calculator.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeA/Calculator.composite?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeA/Calculator.composite (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeA/Calculator.composite Tue Oct 23 21:30:02 2007
@@ -22,19 +22,22 @@
            xmlns:sample="http://sample"
            name="Calculator">
 
-    <component name="CalculatorServiceComponent">
+    <component name="CalculatorServiceComponentA">
 		<implementation.java class="calculator.CalculatorServiceImpl"/>
-        <reference name="addService" target="AddServiceComponent" />     
-        <reference name="subtractService" target="SubtractServiceComponent" />
-        <reference name="multiplyService" target="MultiplyServiceComponent"/>     
-        <reference name="divideService" target="DivideServiceComponent" />
+        <service name="CalculatorService">
+            <binding.sca uri="http://localhost:8087/CalculatorServiceComponentA"/>
+        </service>		
+        <reference name="addService" target="AddServiceComponentB" />     
+        <reference name="subtractService" target="SubtractServiceComponentC" />
+        <reference name="multiplyService" target="MultiplyServiceComponentA"/>     
+        <reference name="divideService" target="DivideServiceComponentA" />
     </component>  
 
-    <component name="MultiplyServiceComponent">
+    <component name="MultiplyServiceComponentA">
         <implementation.java class="calculator.MultiplyServiceImpl" />
     </component>    
     
-    <component name="DivideServiceComponent">
+    <component name="DivideServiceComponentA">
         <implementation.java class="calculator.DivideServiceImpl" />
     </component>
 

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeC/Calculator.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeC/Calculator.composite?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeC/Calculator.composite (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node-impl/src/test/resources/nodeC/Calculator.composite Tue Oct 23 21:30:02 2007
@@ -22,10 +22,10 @@
            xmlns:sample="http://sample"
            name="Calculator">
 
-    <component name="SubtractServiceComponent">
+    <component name="SubtractServiceComponentC">
         <implementation.java class="calculator.SubtractServiceImpl" />
         <service name="SubtractService">
-            <binding.sca uri="http://localhost:8086/SubtractServiceComponent"/>
+            <binding.sca uri="http://localhost:8086/SubtractServiceComponentC"/>
         </service>
     </component>
 

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node/pom.xml?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node/pom.xml (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node/pom.xml Tue Oct 23 21:30:02 2007
@@ -65,7 +65,13 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-domain-api</artifactId>
             <version>1.0.1-incubating-SNAPSHOT</version>
-        </dependency>                     
+        </dependency>     
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-node-api</artifactId>
+            <version>1.0.1-incubating-SNAPSHOT</version>
+        </dependency>  
 
     </dependencies>
 

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentManagerService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentManagerService.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentManagerService.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentManagerService.java Tue Oct 23 21:30:02 2007
@@ -47,20 +47,6 @@
      */
     ComponentInfo getComponentInfo(String componentName);
 
-    /**
-     * Start a component, making it ready to receive messages
-     * 
-     * @param componentName
-     * @throws ActivationException
-     */
-    void startComponent(String componentName) throws ActivationException;
 
-    /** 
-     * Stop a component
-     * 
-     * @param componentName
-     * @throws ActivationException
-     */
-    void stopComponent(String componentName) throws ActivationException;
 
 }

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java Tue Oct 23 21:30:02 2007
@@ -19,7 +19,6 @@
 
 package org.apache.tuscany.sca.node;
 
-import org.apache.tuscany.sca.node.SCANode;
 
 /**
  * A factory that always returns the same domain object

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeManagerService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeManagerService.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeManagerService.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeManagerService.java Tue Oct 23 21:30:02 2007
@@ -19,6 +19,11 @@
 
 package org.apache.tuscany.sca.node;
 
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.domain.SCADomain;
 import org.osoa.sca.annotations.Remotable;
 
 
@@ -30,20 +35,37 @@
 @Remotable
 public interface NodeManagerService {
      
-    /** 
-     * Return the Uri that identifies the node
+    /**
+     * Returns the URI of the SCA node. That URI is the endpoint of the
+     * SCA node administration service.
      * 
-     * @return
+     * @return the URI of the SCA node
      */
-    public String getNodeUri();
+    public String getURI();
     
     /**
-     * The configuration of a domain running on this node has changed.
-     * It is the responsibility of the node to respond to this and retrieve
-     * any relevent configuration changes 
+     * Add an SCA contribution into the node.
      *  
-     * @param domainUri the string uri for the distributed domain
+     * @param uri the URI of the contribution
+     * @param url the URL of the contribution
+     */
+    public void addContribution(String contributionURI, String contributionURL);
+   
+    /**
+     * Start the specified deployable composite on the node.
+     * 
+     * @param composite
+     */
+    public void deployComposite(String compositeName);
+    
+    /**
+     * Start the SCA node service.
+     */
+    public void start();    
+    
+    /**
+     * Stop the SCA node service.
      */
-   // public void addContribution(String domainUri);   
+    public void stop();    
  
 }

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java Tue Oct 23 21:30:02 2007
@@ -93,6 +93,7 @@
                 // Ignore errors.
             }
         }
+        super.shutdown();
     }
 
 

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java Tue Oct 23 21:30:02 2007
@@ -62,7 +62,7 @@
         
     }
     
-    private BundleContext startRuntime() throws Exception {
+    protected BundleContext startRuntime() throws Exception {
         
         if (bundleContext != null)
             return bundleContext;
@@ -183,6 +183,7 @@
             }            
             felix = null;
         }
+        super.shutdown();
     }
     
     @Override

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java Tue Oct 23 21:30:02 2007
@@ -58,7 +58,7 @@
     //        the classpath which contains framework.jar. The entries in init.xargs starting with
     //        -install are assumed to be single-line entries with full bundle location.
     //
-    private BundleContext startRuntime() throws Exception {
+    protected BundleContext startRuntime() throws Exception {
         
         if (bundleContext != null)
             return bundleContext;
@@ -146,6 +146,7 @@
             }
             framework = null;
         }
+        super.shutdown();
         
     }
     

Modified: incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java?rev=587778&r1=587777&r2=587778&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java Tue Oct 23 21:30:02 2007
@@ -30,18 +30,19 @@
 
 public abstract class OSGiRuntime {
     private static final Logger logger = Logger.getLogger(OSGiRuntime.class.getName());
-    private BundleContext bundleContext;
 
     public abstract BundleContext getBundleContext();
 
-    protected abstract void shutdown() throws Exception;
-
     public abstract boolean supportsBundleFragments();
-
-    private PackageAdmin packageAdmin;
-
+    
+    protected abstract BundleContext startRuntime() throws Exception;
+       
     private static OSGiRuntime instance;
-
+    
+    private BundleContext bundleContext;
+    
+    private PackageAdmin packageAdmin;
+    
     /**
      * System property org.apache.tuscany.implementation.osgi.runtime.OSGiRuntime can be set to the
      * name of the OSGiRuntime class (eg. EquinoxRuntime). If set, start this runtime and return the
@@ -52,26 +53,37 @@
      */
     public synchronized static OSGiRuntime getRuntime() throws Exception {
         if (instance != null) {
+        	
+        	if (instance.bundleContext == null) {
+        		instance.startRuntime();
+        		instance.initialize();
+        	}
             return instance;
         }
         String runtimeClassName = System.getProperty(OSGiRuntime.class.getName());
+        
+        if (instance != null)
+        	return instance;
 
         if (runtimeClassName != null) {
             try {
                 Class<?> runtimeClass = OSGiRuntime.class.getClassLoader().loadClass(runtimeClassName);
                 Method method = runtimeClass.getMethod("getInstance");
-                instance = (OSGiRuntime)method.invoke(null);
+                instance = (OSGiRuntime) method.invoke(null);
+                instance.initialize();
                 return instance;
-
+                
             } catch (Exception e) {
                 throw new BundleException("Could not start OSGi runtime " + runtimeClassName, e);
             }
         }
 
         try {
+            
             instance = EquinoxRuntime.getInstance();
+            instance.initialize();
             return instance;
-
+            
         } catch (ClassNotFoundException e) {
             // Ignore
         } catch (Throwable e) {
@@ -79,8 +91,11 @@
         }
 
         try {
+
             instance = FelixRuntime.getInstance();
+            instance.initialize();
             return instance;
+ 
         } catch (ClassNotFoundException e) {
             // Ignore
         } catch (Throwable e) {
@@ -88,8 +103,11 @@
         }
 
         try {
+       
             instance = KnopflerfishRuntime.getInstance();
+            instance.initialize();
             return instance;
+            
         } catch (ClassNotFoundException e) {
             // Ignore
         } catch (Throwable e) {
@@ -99,9 +117,16 @@
         throw new BundleException("Could not start OSGi runtime from the classpath");
     }
 
+
+    public void shutdown() throws Exception {
+    	
+    	bundleContext = null;
+    	packageAdmin = null;
+    }
+    
     private void initialize() {
-        if (bundleContext == null)
-            bundleContext = getBundleContext();
+    	
+        bundleContext = getBundleContext();
 
         if (bundleContext != null) {
 
@@ -117,8 +142,6 @@
 
     public Bundle findBundle(String bundleSymbolicName, String bundleVersion) {
 
-        initialize();
-
         if (bundleContext != null) {
             Bundle[] installedBundles = bundleContext.getBundles();
             for (Bundle bundle : installedBundles) {
@@ -130,11 +153,16 @@
         }
         return null;
     }
+    
+    public synchronized static Bundle findInstalledBundle(String bundleLocation) {
+    	if (instance != null) {
+    		return instance.findBundle(bundleLocation);
+    	}
+    	return null;
+    }
 
     public Bundle findBundle(String bundleLocation) {
 
-        initialize();
-
         if (bundleContext != null) {
             Bundle[] installedBundles = bundleContext.getBundles();
             for (Bundle bundle : installedBundles) {
@@ -147,8 +175,6 @@
     }
 
     public Bundle installBundle(String bundleLocation, InputStream inputStream) {
-
-        initialize();
 
         try {
             if (bundleContext != null) {

Propchange: incubator/tuscany/branches/sca-java-1.0.1/modules/policy-logging/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 23 21:30:02 2007
@@ -0,0 +1,16 @@
+target
+work
+dojo
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+.externalToolBuilders

Copied: incubator/tuscany/branches/sca-java-1.0.1/modules/policy-logging/pom.xml (from r587600, incubator/tuscany/java/sca/modules/policy-logging/pom.xml)
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0.1/modules/policy-logging/pom.xml?p2=incubator/tuscany/branches/sca-java-1.0.1/modules/policy-logging/pom.xml&p1=incubator/tuscany/java/sca/modules/policy-logging/pom.xml&r1=587600&r2=587778&rev=587778&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-logging/pom.xml (original)
+++ incubator/tuscany/branches/sca-java-1.0.1/modules/policy-logging/pom.xml Tue Oct 23 21:30:02 2007
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.apache.tuscany.sca</groupId>
         <artifactId>tuscany-modules</artifactId>
-        <version>1.1-incubating-SNAPSHOT</version>
+        <version>1.0.1-incubating-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
     <artifactId>tuscany-policy-logging</artifactId>
@@ -33,25 +33,25 @@
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-contribution</artifactId>
-            <version>1.1-incubating-SNAPSHOT</version>
+            <version>1.0.1-incubating-SNAPSHOT</version>
         </dependency>
         
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-assembly-xml</artifactId>
-            <version>1.1-incubating-SNAPSHOT</version>
+            <version>1.0.1-incubating-SNAPSHOT</version>
         </dependency>
         
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-policy</artifactId>
-            <version>1.1-incubating-SNAPSHOT</version>
+            <version>1.0.1-incubating-SNAPSHOT</version>
         </dependency>
         
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-contribution-impl</artifactId>
-            <version>1.1-incubating-SNAPSHOT</version>
+            <version>1.0.1-incubating-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
     </dependencies>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org