diff options
author | Thomas Watson | 2015-09-29 21:33:17 +0000 |
---|---|---|
committer | Thomas Watson | 2015-09-29 21:34:47 +0000 |
commit | 62e50f08890d7a52a95f0a18bcb227baea8434d3 (patch) | |
tree | 7a043920d17f30fc5a4bbebae7f112403e683c51 /bundles/org.eclipse.equinox.region | |
parent | 582504f8895753d81ddcc79fbd758b1a48a8fd31 (diff) | |
download | rt.equinox.bundles-62e50f08890d7a52a95f0a18bcb227baea8434d3.tar.gz rt.equinox.bundles-62e50f08890d7a52a95f0a18bcb227baea8434d3.tar.xz rt.equinox.bundles-62e50f08890d7a52a95f0a18bcb227baea8434d3.zip |
Bug 478674 - Deprecate RegionFilter.VISIBLE_SERVICE_NAMESPACEI20151013-0800I20151006-0800
Diffstat (limited to 'bundles/org.eclipse.equinox.region')
3 files changed, 43 insertions, 9 deletions
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java index 7554c4eab..9b99faf6f 100644 --- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java +++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java @@ -89,9 +89,9 @@ public final class StandardRegionFilter implements RegionFilter { } public boolean isAllowed(ServiceReference<?> service) { - if (match(filters.get(VISIBLE_SERVICE_NAMESPACE), service)) + if (match(filters.get(VISIBLE_OSGI_SERVICE_NAMESPACE), service)) return true; - return matchAll(VISIBLE_SERVICE_NAMESPACE, service); + return matchAll(VISIBLE_OSGI_SERVICE_NAMESPACE, service); } public boolean isAllowed(BundleCapability capability) { @@ -108,15 +108,22 @@ public final class StandardRegionFilter implements RegionFilter { return matchAll(namespace, attributes); } + @SuppressWarnings("deprecation") + static final String[] serviceNamespaces = new String[] {VISIBLE_OSGI_SERVICE_NAMESPACE, VISIBLE_SERVICE_NAMESPACE}; + private boolean matchAll(final String namespace, final Map<String, ?> attributes) { Collection<Filter> allMatching = filters.get(VISIBLE_ALL_NAMESPACE); if (allMatching == null) { return false; } return match(allMatching, new AbstractMap<String, Object>() { + @SuppressWarnings("deprecation") @Override public Object get(Object key) { if (RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE.equals(key)) { + if (VISIBLE_SERVICE_NAMESPACE.equals(namespace) || VISIBLE_OSGI_SERVICE_NAMESPACE.equals(namespace)) { + return serviceNamespaces; + } return namespace; } return attributes.get(key); @@ -135,9 +142,13 @@ public final class StandardRegionFilter implements RegionFilter { return false; } return match(allMatching, new AbstractMap<String, Object>() { + @SuppressWarnings("deprecation") @Override public Object get(Object key) { if (RegionFilter.VISIBLE_ALL_NAMESPACE_ATTRIBUTE.equals(key)) { + if (VISIBLE_SERVICE_NAMESPACE.equals(namespace) || VISIBLE_OSGI_SERVICE_NAMESPACE.equals(namespace)) { + return serviceNamespaces; + } return namespace; } return service.getProperty((String) key); diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java index aa6ff4889..d0315406e 100644 --- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java +++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java @@ -11,6 +11,9 @@ package org.eclipse.equinox.internal.region; +import static org.eclipse.equinox.region.RegionFilter.VISIBLE_OSGI_SERVICE_NAMESPACE; +import static org.eclipse.equinox.region.RegionFilter.VISIBLE_SERVICE_NAMESPACE; + import java.util.*; import org.eclipse.equinox.region.RegionFilter; import org.eclipse.equinox.region.RegionFilterBuilder; @@ -21,6 +24,7 @@ public final class StandardRegionFilterBuilder implements RegionFilterBuilder { private final static String ALL_SPEC = "(|(!(all=*))(all=*))"; //$NON-NLS-1$ private final static Filter ALL; + static { try { ALL = FrameworkUtil.createFilter(ALL_SPEC); @@ -35,6 +39,7 @@ public final class StandardRegionFilterBuilder implements RegionFilterBuilder { private final Map<String, Collection<Filter>> policy = new HashMap<String, Collection<Filter>>(); + @SuppressWarnings("deprecation") public RegionFilterBuilder allow(String namespace, String filter) throws InvalidSyntaxException { if (namespace == null) throw new IllegalArgumentException("The namespace must not be null."); //$NON-NLS-1$ @@ -43,28 +48,39 @@ public final class StandardRegionFilterBuilder implements RegionFilterBuilder { synchronized (this.monitor) { Collection<Filter> namespaceFilters = policy.get(namespace); if (namespaceFilters == null) { - namespaceFilters = new ArrayList<Filter>(); + // use set to avoid duplicates + namespaceFilters = new LinkedHashSet<Filter>(); policy.put(namespace, namespaceFilters); } // TODO need to use BundleContext.createFilter here namespaceFilters.add(FrameworkUtil.createFilter(filter)); } + if (VISIBLE_SERVICE_NAMESPACE.equals(namespace)) { + // alias the deprecated namespace to osgi.service + allow(VISIBLE_OSGI_SERVICE_NAMESPACE, filter); + } return this; } + @SuppressWarnings("deprecation") public RegionFilterBuilder allowAll(String namespace) { if (namespace == null) throw new IllegalArgumentException("The namespace must not be null."); //$NON-NLS-1$ synchronized (this.monitor) { Collection<Filter> namespaceFilters = policy.get(namespace); if (namespaceFilters == null) { - namespaceFilters = new ArrayList<Filter>(); + // use set to avoid duplicates + namespaceFilters = new LinkedHashSet<Filter>(); policy.put(namespace, namespaceFilters); } // remove any other filters since this will override them all. namespaceFilters.clear(); namespaceFilters.add(ALL); } + if (VISIBLE_SERVICE_NAMESPACE.equals(namespace)) { + // alias the deprecated namespace to osgi.service + allowAll(VISIBLE_OSGI_SERVICE_NAMESPACE); + } return this; } diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionFilter.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionFilter.java index 7b514de5e..21370791e 100644 --- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionFilter.java +++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionFilter.java @@ -55,10 +55,17 @@ public interface RegionFilter { /** * Name space for sharing services. The filters specified in this name space will be used to match * {@link ServiceReference services}. + * @deprecated use the {@link RegionFilter#VISIBLE_OSGI_SERVICE_NAMESPACE osgi.service} namespace instead. */ public static final String VISIBLE_SERVICE_NAMESPACE = "org.eclipse.equinox.allow.service"; //$NON-NLS-1$ /** + * Name space for sharing services. The filters specified in this name space will be used to match + * {@link ServiceReference services} as well as {@code osgi.service} capabilities. + */ + public static final String VISIBLE_OSGI_SERVICE_NAMESPACE = "osgi.service"; //$NON-NLS-1$ + + /** * Name space for sharing bundles. The filters specified in this name space will be use to match against a bundle's * symbolic name and version. The attributes {@link Constants#BUNDLE_SYMBOLICNAME_ATTRIBUTE bundle-symbolic-name} * and org.eclipse.equinox.allow.bundle are used for the symbolic name and the attribute @@ -87,7 +94,7 @@ public interface RegionFilter { /** * An attribute used to hold the namespace for which the attributes belong to when using the - * {@link #VISIBLE_ALL_NAMESPACE} namespace to mach all capabilities. This can be useful + * {@link #VISIBLE_ALL_NAMESPACE} namespace to match all capabilities. This can be useful * for excluding some namespaces from the all namespace. For example, * <q>(!(org.eclipse.equinox.allow.all.namespace=osgi.wiring.package))</q> will allow everything * except package capabilities. @@ -120,7 +127,7 @@ public interface RegionFilter { * Determines whether this filter allows the given service reference. A * service is allowed if its service properties successfully matches one * or more filters specified using the - * {@link RegionFilter#VISIBLE_SERVICE_NAMESPACE} name space. + * {@link RegionFilter#VISIBLE_OSGI_SERVICE_NAMESPACE} name space. * * @param service the service reference of the service * @return <code>true</code> if the service is allowed and <code>false</code>otherwise @@ -149,9 +156,9 @@ public interface RegionFilter { * The name space can be any generic name space including but not limited to the following: * {@link #VISIBLE_BUNDLE_NAMESPACE}, {@link #VISIBLE_PACKAGE_NAMESPACE}, * {@link #VISIBLE_HOST_NAMESPACE}, {@link #VISIBLE_REQUIRE_NAMESPACE} and - * {@link #VISIBLE_SERVICE_NAMESPACE}. Any other generic capability - * {@link RegionFilterBuilder#allow(String, String) name spaces} can also - * be allowed by the region filter. + * {@link #VISIBLE_OSGI_SERVICE_NAMESPACE}. + * Any other generic capability {@link RegionFilterBuilder#allow(String, String) name spaces} + * can also be allowed by the region filter. * * @param namespace the name space * @param attributes the attributes to check if they are allowed |