diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-13 10:12:18 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-13 10:12:18 +0000 |
commit | 54fdb68ef9f00e6744a1685f208b7c860ef4cd33 (patch) | |
tree | 030c13354daa2d89b31c435ea541978e638be07e | |
parent | 90a42e7b7f8e7f91596c24975a4dd641f5ef1d8e (diff) |
Add a NodeFactory newInstance method that takes a Properties object instead of a map or maps to configure the runtime, which makes it easier to use
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@933537 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java index b8bfbee356..e4df78ffde 100644 --- a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java @@ -31,8 +31,10 @@ import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import org.apache.tuscany.sca.node.configuration.DefaultNodeConfigurationFactory; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; @@ -192,6 +194,28 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { return nodeFactory; } + public static NodeFactory newInstance(Properties properties) { + Map<String, Map<String, String>> attributes = new HashMap<String, Map<String,String>>(); + for (String key : properties.stringPropertyNames()) { + int i = key.lastIndexOf('.'); + String mk, m2k; + if (i > -1) { + mk = key.substring(0, i); + m2k = key.substring(i+1); + } else { + mk = "system"; + m2k = key; + } + Map<String,String> m2 = attributes.get(mk); + if (m2 == null) { + m2 = new HashMap<String, String>(); + attributes.put(mk, m2); + } + m2.put(m2k, properties.getProperty(key)); + } + return newInstance(attributes); + } + /** * Configure the NodeFactory instance * @param attributes |