diff options
author | slewis | 2016-02-25 06:26:11 +0000 |
---|---|---|
committer | slewis | 2016-02-25 06:26:11 +0000 |
commit | 12c2659eae6d37f7748e92186eca19828b4e8d75 (patch) | |
tree | e5806bbc5525d3f98d5187ee79a2bcb47dee47e9 | |
parent | 09f2fe21b6c0fc16d665229ce502cf732564f458 (diff) | |
download | org.eclipse.ecf-12c2659eae6d37f7748e92186eca19828b4e8d75.tar.gz org.eclipse.ecf-12c2659eae6d37f7748e92186eca19828b4e8d75.tar.xz org.eclipse.ecf-12c2659eae6d37f7748e92186eca19828b4e8d75.zip |
New RSA API for simplifying distribution provider implementations
Change-Id: I0000000000000000000000000000000000000000
5 files changed, 30 insertions, 123 deletions
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF index 0d350f5e5..ab4c1ea10 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/META-INF/MANIFEST.MF @@ -22,6 +22,7 @@ Import-Package: javax.xml.parsers, org.eclipse.ecf.discovery.identity, org.eclipse.ecf.remoteservice;version="7.2.0", org.eclipse.ecf.remoteservice.events;version="6.0.0", + org.eclipse.ecf.remoteservice.util;version="8.2.0", org.eclipse.equinox.concurrent.future;version="1.0.0", org.eclipse.osgi.framework.eventmgr, org.osgi.framework;version="1.3.0", diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java index 78bd303b9..7b983ea0a 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/IDUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This + * Copyright (c) 2016 Composent, Inc. and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -9,72 +9,41 @@ ******************************************************************************/ package org.eclipse.ecf.internal.osgi.services.remoteserviceadmin; -import java.util.Iterator; -import java.util.List; - import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDCreateException; -import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.core.identity.IIDFactory; import org.eclipse.ecf.core.identity.Namespace; -import org.eclipse.ecf.core.identity.StringID; public class IDUtil { public static IIDFactory getIDFactory() { - return IDFactory.getDefault(); + return org.eclipse.ecf.remoteservice.util.IDUtil.getIDFactory(); } public static Namespace getNamespaceByName(String namespaceName) { - if (namespaceName == null) - return null; - return getIDFactory().getNamespaceByName(namespaceName); + return org.eclipse.ecf.remoteservice.util.IDUtil.getNamespaceByName(namespaceName); } public static Namespace findNamespaceByIdName(String idName) { - if (idName == null) - return null; - int colonIndex = idName.indexOf(Namespace.SCHEME_SEPARATOR); - if (colonIndex <= 0) - return null; - String scheme = idName.substring(0, colonIndex); - // First try to find the Namespace using the protocol directly - Namespace ns = getNamespaceByName(scheme); - return (ns == null) ? findNamespaceByScheme(scheme) : ns; + return org.eclipse.ecf.remoteservice.util.IDUtil.findNamespaceByIdName(idName); } public static Namespace findNamespaceByScheme(String scheme) { - if (scheme == null) - return null; - if (scheme.equals("ecftcp")) //$NON-NLS-1$ - return getIDFactory().getNamespaceByName(StringID.class.getName()); - List namespaces = getIDFactory().getNamespaces(); - for (Iterator i = namespaces.iterator(); i.hasNext();) { - Namespace ns = (Namespace) i.next(); - if (scheme.equals(ns.getScheme())) - return ns; - } - return null; + return org.eclipse.ecf.remoteservice.util.IDUtil.findNamespaceByScheme(scheme); } public static ID createID(String namespaceName, String idName) throws IDCreateException { - Namespace ns = (namespaceName != null) ? getNamespaceByName(namespaceName) - : findNamespaceByIdName(idName); - if (ns == null) - throw new IDCreateException( - "Cannot find Namespace for namespaceName=" + namespaceName //$NON-NLS-1$ - + " and idName=" + idName); //$NON-NLS-1$ - return createID(ns, idName); + return org.eclipse.ecf.remoteservice.util.IDUtil.createID(namespaceName, idName); } public static ID createID(Namespace namespace, String idName) throws IDCreateException { - return getIDFactory().createID(namespace, idName); + return org.eclipse.ecf.remoteservice.util.IDUtil.createID(namespace, idName); } public static ID createID(Namespace namespace, Object[] args) throws IDCreateException { - return getIDFactory().createID(namespace, args); + return org.eclipse.ecf.remoteservice.util.IDUtil.createID(namespace, args); } } diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java index adca1ffa4..889ed1c5b 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/PropertiesUtil.java @@ -14,7 +14,6 @@ import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; @@ -185,39 +184,7 @@ public class PropertiesUtil { } public static List getStringPlusProperty(Map properties, String key) { - Object value = properties.get(key); - if (value == null) { - return Collections.EMPTY_LIST; - } - - if (value instanceof String) { - return Collections.singletonList((String) value); - } - - if (value instanceof String[]) { - String[] values = (String[]) value; - List result = new ArrayList(values.length); - for (int i = 0; i < values.length; i++) { - if (values[i] != null) { - result.add(values[i]); - } - } - return Collections.unmodifiableList(result); - } - - if (value instanceof Collection) { - Collection values = (Collection) value; - List result = new ArrayList(values.size()); - for (Iterator iter = values.iterator(); iter.hasNext();) { - Object v = iter.next(); - if (v instanceof String) { - result.add((String) v); - } - } - return Collections.unmodifiableList(result); - } - - return Collections.EMPTY_LIST; + return org.eclipse.ecf.remoteservice.util.EndpointDescriptionPropertiesUtil.getStringPlusProperty(properties, key); } public static Object getPropertyValue(ServiceReference serviceReference, String key) { diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java index 9e0420494..a348fecc7 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/EndpointDescription.java @@ -16,10 +16,7 @@ import java.util.List; import java.util.Map; import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.identity.IDCreateException; -import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions; -import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.IDUtil; import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility; import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.PropertiesUtil; import org.eclipse.ecf.remoteservice.Constants; @@ -159,62 +156,28 @@ public class EndpointDescription extends } private Long verifyLongProperty(String propName) { - Object r = getProperties().get(propName); - try { - return (Long) r; - } catch (ClassCastException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "property value is not a Long: " + propName); //$NON-NLS-1$ - iae.initCause(e); - throw iae; - } + return org.eclipse.ecf.remoteservice.util.EndpointDescriptionPropertiesUtil.verifyLongProperty(getProperties(), + propName); } private String verifyStringProperty(String propName) { - Object r = getProperties().get(propName); - try { - return (String) r; - } catch (ClassCastException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "property value is not a String: " + propName); //$NON-NLS-1$ - iae.initCause(e); - throw iae; - } + return org.eclipse.ecf.remoteservice.util.EndpointDescriptionPropertiesUtil + .verifyStringProperty(getProperties(), propName); } private ID verifyIDProperty(String idNamespace, String idName) { - if (idName == null) - return null; - try { - return IDUtil.createID(idNamespace, idName); - } catch (IDCreateException e) { - return IDFactory.getDefault().createStringID(idName); - } + return org.eclipse.ecf.remoteservice.util.EndpointDescriptionPropertiesUtil.verifyIDProperty(idNamespace, + idName); } private ID verifyIDProperty(String namePropName) { - return verifyIDProperty(idNamespace, verifyStringProperty(namePropName)); + return org.eclipse.ecf.remoteservice.util.EndpointDescriptionPropertiesUtil + .verifyIDProperty(idNamespace, verifyStringProperty(namePropName)); } private ID[] verifyIDFilter() { - List<String> idNames = PropertiesUtil.getStringPlusProperty( - getProperties(), RemoteConstants.ENDPOINT_IDFILTER_IDS); - if (idNames.size() == 0) - return null; - List<ID> results = new ArrayList(); - String idNamespace = getIdNamespace(); - for (String idName : idNames) { - try { - results.add(IDUtil.createID(idNamespace, idName)); - } catch (IDCreateException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "cannot create ID[]: idNamespace=" + idNamespace //$NON-NLS-1$ - + " idName=" + idName); //$NON-NLS-1$ - iae.initCause(e); - throw iae; - } - } - return (ID[]) results.toArray(new ID[results.size()]); + return org.eclipse.ecf.remoteservice.util.EndpointDescriptionPropertiesUtil + .verifyIDArray(getProperties(), RemoteConstants.ENDPOINT_IDFILTER_IDS, getIdNamespace()); } private void addInterfaceVersions(List<String> interfaces, Map<String,Version> result) { diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java index 1bb8371c5..1483a0313 100644 --- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java +++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java @@ -43,6 +43,7 @@ import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.Activator; import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions; import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility; import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.PropertiesUtil; +import org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter; import org.eclipse.ecf.remoteservice.IExtendedRemoteServiceRegistration; import org.eclipse.ecf.remoteservice.IOSGiRemoteServiceContainerAdapter; import org.eclipse.ecf.remoteservice.IRemoteService; @@ -2346,7 +2347,7 @@ public class RemoteServiceAdmin implements } private ImportRegistration importService( - EndpointDescription endpointDescription, + final EndpointDescription endpointDescription, IRemoteServiceContainer rsContainer) { // Get interfaces from endpoint description Collection<String> interfaces = endpointDescription.getInterfaces(); @@ -2366,7 +2367,7 @@ public class RemoteServiceAdmin implements final ID targetID = tID; // Get idFilter...also may be null final ID[] idFilter = getIDFilter(endpointDescription, - endpointContainerID); + targetID); // Get remote service filter final String rsFilter = getRemoteServiceFilter(endpointDescription); // IRemoteServiceReferences from query @@ -2377,6 +2378,7 @@ public class RemoteServiceAdmin implements // rsContainerID ID rsContainerID = rsContainer.getContainer().getID(); try { + final IRSAConsumerContainerAdapter cca = (IRSAConsumerContainerAdapter) containerAdapter.getAdapter(IRSAConsumerContainerAdapter.class); // Get first interface name for service reference // lookup final String intf = interfaces.iterator().next(); @@ -2386,7 +2388,12 @@ public class RemoteServiceAdmin implements public IRemoteServiceReference[] run() throws ContainerConnectException, InvalidSyntaxException { - return containerAdapter.getRemoteServiceReferences( + // If the RSAConsumerContainerAdapter is present, use it + if (cca != null) + // Call importEndpoint if the IRSAConsumerContainerAdapter is present + return cca.importEndpoint(endpointDescription.getProperties()); + // Otherwise use the 'old' container adapter + else return containerAdapter.getRemoteServiceReferences( targetID, idFilter, intf, rsFilter); } }); |