summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/domain-node
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-08-28 13:05:34 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-08-28 13:05:34 +0000
commit4509ca848cddb29460467aff494e1d07d23f7248 (patch)
treed5decbab133750d465658abd55007fda64f017e5 /java/sca/modules/domain-node
parent135d6e4b837cc86c9b966bc6a966e66231c4cf61 (diff)
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
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@808875 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/domain-node')
-rw-r--r--java/sca/modules/domain-node/pom.xml6
-rw-r--r--java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java35
-rw-r--r--java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java46
-rw-r--r--java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java42
4 files changed, 119 insertions, 10 deletions
diff --git a/java/sca/modules/domain-node/pom.xml b/java/sca/modules/domain-node/pom.xml
index 4a1a7f5076..4cf6e4e279 100644
--- a/java/sca/modules/domain-node/pom.xml
+++ b/java/sca/modules/domain-node/pom.xml
@@ -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>
diff --git a/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java b/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java
new file mode 100644
index 0000000000..c38c59f0ba
--- /dev/null
+++ b/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/ConfigAttributesImpl.java
@@ -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;
+ }
+
+}
diff --git a/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java b/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
index f4c7d0f97c..91f4ff17d1 100644
--- a/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
+++ b/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
@@ -23,19 +23,23 @@ import java.net.URI;
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 @@ public class DomainNode {
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 @@ public class DomainNode {
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);
+ 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);
+ }
- this.domainName = uri.getHost();
+ 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);
+ }
+ }
}
-
}
diff --git a/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java b/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
new file mode 100644
index 0000000000..6327ae06b2
--- /dev/null
+++ b/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
@@ -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"));
+ }
+
+}