You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2009/08/28 15:05:34 UTC

svn commit: r808875 - in /tuscany/java/sca/modules/domain-node: ./ src/main/java/org/apache/tuscany/sca/node/ src/test/java/org/apache/tuscany/sca/node/

Author: antelder
Date: Fri Aug 28 13:05:34 2009
New Revision: 808875

URL: http://svn.apache.org/viewvc?rev=808875&view=rev
Log:
Update domain-node to use the new endpoint wrapper and runtime configuration so that the inVm/tribes endpoint registry can be choosen and configured via the domain node URI

Added:
    tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java
    tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
Modified:
    tuscany/java/sca/modules/domain-node/pom.xml
    tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java

Modified: tuscany/java/sca/modules/domain-node/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/pom.xml?rev=808875&r1=808874&r2=808875&view=diff
==============================================================================
--- tuscany/java/sca/modules/domain-node/pom.xml (original)
+++ tuscany/java/sca/modules/domain-node/pom.xml Fri Aug 28 13:05:34 2009
@@ -50,6 +50,12 @@
             <version>2.0-SNAPSHOT</version>
         </dependency>  
                       
+         <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-endpoint-wrapper</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>  
+
     </dependencies>
 
 </project>

Added: tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java?rev=808875&view=auto
==============================================================================
--- tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java (added)
+++ tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java Fri Aug 28 13:05:34 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.node;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.management.ConfigAttributes;
+
+public class ConfigAttributesImpl implements ConfigAttributes {
+
+    private Map<String, String> attributes = new HashMap<String, String>();
+    
+    public Map<String, String> getAttributes() {
+        return attributes;
+    }
+
+}

Modified: tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java?rev=808875&r1=808874&r2=808875&view=diff
==============================================================================
--- tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java (original)
+++ tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java Fri Aug 28 13:05:34 2009
@@ -23,19 +23,23 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.tuscany.sca.node.Contribution;
-import org.apache.tuscany.sca.node.Node;
-import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.management.ConfigAttributes;
+import org.apache.tuscany.sca.node.impl.NodeFactoryImpl;
 
 public class DomainNode {
 
-    private String domainName;
+    public static final String DOMAIN_NAME_ATTR = "domainName";
+    public static final String DOMAIN_SCHEME_ATTR = "domainScheme";
+    public static final String DEFAULT_DOMAIN_SCHEME = "vm";
+    public static final String DEFAULT_DOMAIN_NAME = "defaultDomain";
+
+    private ConfigAttributes configAttributes = new ConfigAttributesImpl();
     
-    private NodeFactory nodeFactory;
+    private NodeFactoryImpl nodeFactory;
     private Map<String, Node> nodes = new HashMap<String, Node>();
     
     public DomainNode() {
-       this("vm://defaultDomain");   
+       this(DEFAULT_DOMAIN_SCHEME + "://" + DEFAULT_DOMAIN_NAME);   
     }
     
     public DomainNode(String configURI) {
@@ -56,7 +60,9 @@
             throw new IllegalStateException("Already started");
         }
         
-        nodeFactory = NodeFactory.getInstance(domainName);
+        //TODO shouldn't really be working with the impl
+        nodeFactory = (NodeFactoryImpl)NodeFactory.getInstance(configAttributes.getAttributes().get(DOMAIN_NAME_ATTR));
+        nodeFactory.setConfigAttributes(configAttributes);
     }
     
     public boolean isStarted() {
@@ -100,14 +106,34 @@
         node.stop();
     }
 
+    public ConfigAttributes getConfigAttributes() {
+        return configAttributes;
+    }
+    
     public String getDomainName() {
-        return domainName;
+        return configAttributes.getAttributes().get(DOMAIN_NAME_ATTR);
     }
     
     protected void parseConfigURI(String configURI) {
         URI uri = URI.create(configURI);
-
-        this.domainName = uri.getHost();
+        String dn = uri.getHost();
+        if (dn == null || dn.length() < 1) {
+            dn = DEFAULT_DOMAIN_NAME;
+        }
+        configAttributes.getAttributes().put(DOMAIN_NAME_ATTR, dn);  
+        String scheme = uri.getScheme();
+        if (scheme != null && scheme.length() > 0) {
+            configAttributes.getAttributes().put(DOMAIN_SCHEME_ATTR, scheme);  
+        }
+
+        String query = uri.getQuery();
+        if (query != null && query.length() > 0) {
+            String[] params = query.split("&");
+            for (String param : params){
+                String name = param.split("=")[0];  
+                String value = param.split("=")[1];  
+                configAttributes.getAttributes().put(name, value);  
+            }
+        }
     }
-
 }

Added: tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java?rev=808875&view=auto
==============================================================================
--- tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java (added)
+++ tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java Fri Aug 28 13:05:34 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.node;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class ConfigTestCase{
+
+    @Test
+    public void testConfig() throws Exception {
+        DomainNode domain = new DomainNode("foo://someDomain:1234?p1=x&p2=y");
+        assertEquals(4,  domain.getConfigAttributes().getAttributes().size());
+        assertEquals("someDomain", domain.getDomainName());
+        assertEquals("foo", domain.getConfigAttributes().getAttributes().get("domainScheme"));
+        assertEquals("someDomain", domain.getConfigAttributes().getAttributes().get("domainName"));
+        assertEquals("x", domain.getConfigAttributes().getAttributes().get("p1"));
+        assertEquals("y", domain.getConfigAttributes().getAttributes().get("p2"));
+    }
+
+}