summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/extensibility-equinox/src/main
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-02-19 03:27:50 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-02-19 03:27:50 +0000
commiteab31f88e10a97c863c14eb9c18e9fe7e0ed096c (patch)
tree182f006b80d2aded574f367a0a0b65db41250c78 /sca-java-2.x/trunk/modules/extensibility-equinox/src/main
parent5cf2cf2306522c7bd3b420e7ce6e362ce3b743f1 (diff)
Start to add the support to load node factory configuration from external files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@911689 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/extensibility-equinox/src/main')
-rw-r--r--sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java85
1 files changed, 5 insertions, 80 deletions
diff --git a/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java b/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
index 34e08d5ef6..fa9fb03a1d 100644
--- a/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
+++ b/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
@@ -19,28 +19,20 @@
package org.apache.tuscany.sca.extensibility.equinox;
-import static org.apache.tuscany.sca.extensibility.ServiceDeclarationParser.parseDeclaration;
-
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.Collection;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser;
import org.apache.tuscany.sca.extensibility.ServiceDiscoverer;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -302,77 +294,10 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
logger.fine("Reading service provider file: " + url.toExternalForm());
}
try {
- // Allow privileged access to open URL stream. Add FilePermission to added to security
- // policy file.
- InputStream is;
- try {
- is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
- public InputStream run() throws IOException {
- return url.openStream();
- }
- });
- } catch (PrivilegedActionException e) {
- throw (IOException)e.getException();
- }
- if (isPropertyFile) {
- // Load as a property file
- Properties props = new Properties();
- props.load(is);
- is.close();
- for (Map.Entry<Object, Object> e : props.entrySet()) {
- Map<String, String> attributes = new HashMap<String, String>();
- String key = (String)e.getKey();
- String value = (String)e.getValue();
- // Unfortunately, the xalan file only has the classname
- if ("".equals(value)) {
- value = key;
- key = "";
- }
- if (!"".equals(key)) {
- attributes.put(key, value);
- attributes.put("uri", key);
- }
- attributes.putAll(parseDeclaration(value));
- ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(bundle, url, value, attributes);
- descriptors.add(descriptor);
- }
- continue;
- }
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(is));
- int count = 0;
- while (true) {
- String line = reader.readLine();
- if (line == null)
- break;
- line = line.trim();
- if (!line.startsWith("#") && !"".equals(line)) {
- String reg = line.trim();
- if (debug) {
- logger.fine("Registering service provider: " + reg);
- }
-
- Map<String, String> attributes = parseDeclaration(reg);
- String className = attributes.get("class");
- if (className == null) {
- // Add a unique class name to prevent equals() from returning true
- className = "_class_" + count;
- count++;
- }
- ServiceDeclarationImpl descriptor =
- new ServiceDeclarationImpl(bundle, url, className, attributes);
- descriptors.add(descriptor);
- }
- }
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- // Ignore
- }
- }
+ for (Map<String, String> attributes : ServiceDeclarationParser.load(url, isPropertyFile)) {
+ String className = attributes.get("class");
+ ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(bundle, url, className, attributes);
+ descriptors.add(descriptor);
}
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);