From c51886cd56d681230b8b1914b2b369d47619c65d Mon Sep 17 00:00:00 2001 From: antelder Date: Wed, 21 Apr 2010 08:02:38 +0000 Subject: Fix up properties parsing git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@936187 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/node/NodeFactory.java | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'sca-java-2.x/trunk/modules/node-api/src') 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>()); } 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:?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 params = new HashMap(); + 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; } -- cgit v1.2.3