summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r--sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java18
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();
+ }
}