diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-21 08:02:38 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-21 08:02:38 +0000 |
commit | c51886cd56d681230b8b1914b2b369d47619c65d (patch) | |
tree | b8d88357767bbca172f323d871066a7046c312c5 /sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java | |
parent | f1efea501cd83340c2131c3b66224baafe1a3039 (diff) |
Fix up properties parsing
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@936187 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java')
-rw-r--r-- | sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java | 46 |
1 files changed, 31 insertions, 15 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 4588941f47..082b6e612f 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 @@ -197,14 +197,19 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { return nodeFactory; } - protected Properties properties = new Properties(); + protected Properties properties; - public static NodeFactory newInstance(Properties properties) { + protected NodeFactory() { + this.properties = new Properties(); + properties.setProperty("defaultScheme", "vm"); + } + + public static NodeFactory newInstance(Properties configProperties) { NodeFactory nodeFactory = null; try { Class<?> factoryClass = getFactoryImplClass(); nodeFactory = (NodeFactory)factoryClass.newInstance(); - nodeFactory.properties = properties; + nodeFactory.properties = configProperties; nodeFactory.configure(new HashMap<String, Map<String,String>>()); } catch (Exception e) { throw new ServiceRuntimeException(e); @@ -223,22 +228,40 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { throw new ServiceRuntimeException(e); } } else if (configURI.startsWith("uri:")) { - properties = parseConfigURI(configURI); + properties = parseConfigURI(configURI.substring("uri:".length())); } else { - properties = new Properties(); - properties.setProperty("configURI", configURI); + throw new IllegalArgumentException("config should start with 'uri:' or 'properties:'"); } return newInstance(properties); } /** - * Parse the config URI into a Properties object. + * Parse the config string into a Properties object. * The config URI has the following format: * uri:<domainName>?name=value&... */ private static Properties parseConfigURI(String configURI) { Properties properties = new Properties(); - // TODO: + int qm = configURI.indexOf('?'); + if (qm < 0) { + properties.setProperty("defaultDomainName", configURI); + } else { + properties.setProperty("defaultDomainName", configURI.substring(0, qm)); + if (configURI.length() > qm+1) { + Map<String, String> params = new HashMap<String, String>(); + for (String param : configURI.substring(qm+1).split("&")) { + String[] px = param.split("="); + if (px.length == 2) { + params.put(px[0], px[1]); + } else { + params.put(px[0], ""); + } + } + for (String name : params.keySet()) { + properties.setProperty(name, params.get(name)); + } + } + } return properties; } @@ -273,13 +296,6 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { inputStream.close(); } - // append any system properties? - try { - Properties systemProperties = System.getProperties(); - properties.putAll(systemProperties); - } catch (Exception e) { - // ignore security exception - } return properties; } |