Author: antelder
Date: Tue Jun 14 07:00:09 2011
New Revision: 1135391

URL: http://svn.apache.org/viewvc?rev=1135391&view=rev
Log:
Have a look at creating a domain node from a file system dirctory to see if its 
possible to do it in a way thats simpler than requiring a node.xml config file

Added:
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jar
   (with props)
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jar
   (with props)
Modified:
    
tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java

Modified: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java?rev=1135391&r1=1135390&r2=1135391&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java
 Tue Jun 14 07:00:09 2011
@@ -19,13 +19,21 @@
 
 package org.apache.tuscany.sca;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URI;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Properties;
 
+import javax.xml.stream.XMLStreamException;
+
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
 import org.apache.tuscany.sca.common.java.io.IOHelper;
 import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
@@ -136,7 +144,7 @@ public class TuscanyRuntime {
      * @return a Node
      */
     public Node createNode() {
-        return createNode(null);
+        return createNode((String)null);
     }
 
     /**
@@ -152,6 +160,66 @@ public class TuscanyRuntime {
         DomainRegistry domainRegistry = 
domainRegistryFactory.getEndpointRegistry(domainURI, domainName);
         return new NodeImpl(deployer, compositeActivator, domainRegistry, 
extensionPointRegistry, null);
     }
+    
+    /*
+     * Create a node from a file system directory. 
+     * The directory can contain:
+     *  domain.properties 
+     *  contributions - jar, zip, or exploded directories
+     *  sca-contribution.xml metaData files to override whats in a contribution
+     *  .composite files to add to contributions as additional deployables
+     * 
+     * TODO: Review if this is useful?
+     */
+    public Node createNode(File directory) throws ContributionReadException, 
ValidationException, ActivationException, XMLStreamException, IOException {
+        
+        Properties domainProps = new Properties();
+        File propsFile = new File(directory, "domain.properties");
+        if (propsFile.exists()) {
+            domainProps.load(new FileInputStream(propsFile));
+        }
+        String domainName = domainProps.getProperty("domainName", 
directory.getName());
+        String domainURI = domainProps.getProperty("domainURI", domainName);
+
+        DomainRegistry domainRegistry = 
domainRegistryFactory.getEndpointRegistry(domainURI, domainName);
+        Node node = new NodeImpl(deployer, compositeActivator, domainRegistry, 
extensionPointRegistry, null);
+ 
+        
+        List<String> installed = new ArrayList<String>();
+        for (File f : directory.listFiles()) {
+            if (!f.getName().endsWith(".xml") && 
!f.getName().endsWith(".composite")) {
+                String fn = f.getName().lastIndexOf('.') == -1 ? f.getName() : 
f.getName().substring(0, f.getName().lastIndexOf('.'));
+                String metaData = null;
+                for (File f2 : directory.listFiles()) {
+                    if (f2.getName().startsWith(fn) && 
f2.getName().endsWith(".xml")) {
+                        metaData = f2.getPath();
+                        break;
+                    }
+                }
+                
+                List<String> dependencyURIs = new ArrayList();
+                String dependencyURIprop = domainProps.getProperty(fn + 
".dependencies");
+                if (dependencyURIprop != null && dependencyURIprop.length() > 
0) {
+                    dependencyURIs = 
Arrays.asList(dependencyURIprop.split(","));
+                }
+
+                String curi = node.installContribution(null, f.getPath(), 
metaData, dependencyURIs);
+                installed.add(curi);
+
+                for (File f2 : directory.listFiles()) {
+                    if (f2.getName().startsWith(fn) && 
f2.getName().endsWith(".composite")) {
+                        node.addDeploymentComposite(curi, new FileReader(f2));
+                    }
+                }
+            }
+        }
+
+        for (String curi : installed) {
+            node.startDeployables(curi);
+        }
+
+        return node;
+    }
 
     /**
      * Creates a Node from an XML configuration file

Added: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java?rev=1135391&view=auto
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
 (added)
+++ 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java
 Tue Jun 14 07:00:09 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.monitor.ValidationException;
+import org.apache.tuscany.sca.runtime.ActivationException;
+import org.apache.tuscany.sca.runtime.ContributionDescription;
+import org.junit.Test;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public class DirectoryDomainTestCase {
+
+    @Test
+    public void testDefaultDomain() throws NoSuchServiceException, 
NoSuchDomainException, ContributionReadException, ActivationException, 
ValidationException, XMLStreamException, IOException {
+        Node node = TuscanyRuntime.newInstance().createNode(new 
File("src/test/resources/test-domains/default"));
+
+        Assert.assertEquals("default", node.getDomainName());
+        Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+        Assert.assertEquals("sample-helloworld", 
node.getInstalledContributionURIs().get(0));
+        Assert.assertEquals("helloworld.composite", 
node.getStartedCompositeURIs().get("sample-helloworld").get(0));
+    }
+    
+    @Test
+    public void testMyDomain() throws NoSuchServiceException, 
NoSuchDomainException, ContributionReadException, ActivationException, 
ValidationException, XMLStreamException, IOException {
+        Node node = TuscanyRuntime.newInstance().createNode(new 
File("src/test/resources/test-domains/MyDomain"));
+
+        Assert.assertEquals("MyDomain", node.getDomainName());
+        Assert.assertEquals(1, node.getInstalledContributionURIs().size());
+        Assert.assertEquals("helloworld-contribution", 
node.getInstalledContributionURIs().get(0));
+
+        // validate additional deployable composite
+        Map<String, List<String>> scs = node.getStartedCompositeURIs();
+        Assert.assertEquals(2, scs.get("helloworld-contribution").size());
+        
Assert.assertTrue(scs.get("helloworld-contribution").contains("helloworld.composite"));
+        
Assert.assertTrue(scs.get("helloworld-contribution").contains("helloworld2.composite"));
+        
+        // validate metadata side file
+        ContributionDescription ic = 
node.getInstalledContribution("helloworld-contribution");
+        Assert.assertEquals(1, ic.getJavaExports().size());
+        Assert.assertEquals("sample", ic.getJavaExports().get(0));
+    }
+
+}

Added: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite?rev=1135391&view=auto
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite
 (added)
+++ 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.deployable.composite
 Tue Jun 14 07:00:09 2011
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912";
+           xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1";
+           targetNamespace="http://sample";
+           name="helloworld2">
+
+    <component name="Helloworld2Component">
+        <implementation.java class="sample.HelloworldImpl"/>
+    </component>
+
+</composite>

Added: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jar
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jar?rev=1135391&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml?rev=1135391&view=auto
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml
 (added)
+++ 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/MyDomain/helloworld-contribution.xml
 Tue Jun 14 07:00:09 2011
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912";
+              xmlns:sample="http://sample";>
+   <export.java package="sample" />
+</contribution>

Added: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jar
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jar?rev=1135391&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
tuscany/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/default/sample-helloworld.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream


Reply via email to