From d4743525775f0d49ab021887e7402967d12d32be Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 14 Apr 2010 04:15:42 +0000 Subject: Add duplication check for SCA configurations git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@933854 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/EndpointIntrospector.java | 6 ++- .../impl/RemoteServiceAdminImpl.java | 9 +++- .../discovery/impl/DomainDiscoveryService.java | 3 ++ .../discovery/impl/LocalDiscoveryService.java | 50 ++++++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) (limited to 'sca-java-2.x/trunk/modules/node-impl-osgi/src/main') diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java index ffd619a4c2..22bcb5af41 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java @@ -478,8 +478,10 @@ public class EndpointIntrospector { .getNamespaceURI())) { for (Binding binding : sc.getBindings()) { if (bindingName.getLocalPart().equals(binding.getName())) { - bindingMap.put(bindingName, binding); - break; + // We need to check duplications + if (bindingMap.put(bindingName, binding) != null) { + throw new ServiceRuntimeException("Duplicate binding found: " + bindingName); + } } } } diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java index 56e17a5642..00eb45f3c1 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java @@ -265,7 +265,14 @@ public class RemoteServiceAdminImpl implements RemoteServiceAdmin, ManagedServic if (bindings != null) { props.put("org.osgi.sca.bindings", bindings); } - } + Object config = ep.getProperties().get("org.osgi.sca.config.url"); + if (config != null) { + props.put("org.osgi.sca.config.url", config); + } + config = ep.getProperties().get("org.osgi.sca.config.xml"); + if (config != null) { + props.put("org.osgi.sca.config.xml", config); + } } props.put("timestamp", Long.valueOf(System.currentTimeMillis())); props.put("event", rsaEvent); return new Event(topic, props); diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java index 34c72933e9..0cbdda7b56 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java @@ -80,9 +80,12 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements public void endpointAdded(Endpoint endpoint) { Implementation impl = endpoint.getComponent().getImplementation(); + + /* if (!(impl instanceof OSGiImplementation)) { return; } + */ BundleContext bundleContext = null; // Remote endpoint doesn't have a bundle diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java index 320443c399..dc9ae096dd 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java @@ -34,12 +34,17 @@ import java.util.UUID; import java.util.Map.Entry; import java.util.logging.Level; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.implementation.osgi.SCAConfig; import org.apache.tuscany.sca.implementation.osgi.ServiceDescription; import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions; import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; import org.oasisopen.sca.ServiceRuntimeException; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -159,6 +164,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B } // Add to the extenders before notifying the listeners (the endpoints may references to the config) + ExtenderConfiguration.validate(extenders, extender); this.extenders.add(extender); // Notify @@ -200,6 +206,50 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B return scaConfigs; } + public static void validate(Collection configs, ExtenderConfiguration newConfig) { + Map bindings = new HashMap(); + Map intents = new HashMap(); + Map policySets = new HashMap(); + + for (ExtenderConfiguration config : configs) { + for (SCAConfig c : config.getSCAConfigs()) { + addBindings(bindings, c); + addIntents(intents, c); + addPolicySets(policySets, c); + } + } + for (SCAConfig c : newConfig.getSCAConfigs()) { + addBindings(bindings, c); + addIntents(intents, c); + addPolicySets(policySets, c); + } + } + + private static void addIntents(Map intents, SCAConfig c) { + for (Intent i: c.getIntents()) { + if (intents.put(i.getName(), i) != null) { + throw new ServiceRuntimeException("Duplicate intent: " + i.getName()); + } + } + } + + private static void addPolicySets(Map policySets, SCAConfig c) { + for (PolicySet ps: c.getPolicySets()) { + if (policySets.put(ps.getName(), ps) != null) { + throw new ServiceRuntimeException("Duplicate policySet: " + ps.getName()); + } + } + } + + private static void addBindings(Map bindings, SCAConfig c) { + for (Binding b : c.getBindings()) { + QName name = new QName(c.getTargetNamespace(), b.getName()); + if (bindings.put(name, b) != null) { + throw new ServiceRuntimeException("Duplicate binding: " + name); + } + } + } + } @Override -- cgit v1.2.3