diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-30 16:59:41 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-30 16:59:41 +0000 |
commit | 6ae91307f506b8050293f37402bf936358fe338e (patch) | |
tree | a1b57e5ef5af12e3ad1dbc847ac39021e491e76a /sca-java-2.x/trunk | |
parent | 71b01b40ed17143ae45b85ec67b42e665f99cd29 (diff) |
Add a method remove duplicate service declsrations
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1053940 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java index f99f682e07..973664f382 100644 --- a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java +++ b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -285,4 +286,21 @@ public final class ServiceDiscovery implements ServiceDiscoverer { public Map<String, String> getAttributes(String serviceType) { return serviceAttributes.get(serviceType); } + + /** + * Remove the duplicate service declarations. The duplication happens when we have the same jar from more than one entries on the classpath + * @param declarations + * @return + */ + public static Collection<ServiceDeclaration> removeDuplicateDeclarations(Collection<ServiceDeclaration> declarations) { + // Use LinkedHashMap to maintain the insertion order + Map<String, ServiceDeclaration> map = new LinkedHashMap<String, ServiceDeclaration>(); + for (ServiceDeclaration sd : declarations) { + ServiceDeclaration existed = map.put(sd.getClassName(), sd); + if (existed != null) { + logger.warning("Duplicate service declaration is ignored: " + existed + " <-> " + sd); + } + } + return map.values(); + } } |