This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.serviceusermapper-1.2.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit 6bc2582d7c5cd2cc1180dcb98920a9b5df12186a Author: Marius Petria <[email protected]> AuthorDate: Thu Mar 12 14:02:20 2015 +0000 SLING-4312: changed name from ServiceUserMapping to ServiceUserMapped and removed all metohds git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/serviceusermapper@1666196 13f79535-47bb-0310-9956-ffa450edef68 --- ...viceUserMapping.java => ServiceUserMapped.java} | 15 +++-------- .../sling/serviceusermapping/impl/Mapping.java | 6 ++--- ...ter.java => ServiceUserMappedBundleFilter.java} | 15 +++++------ .../impl/ServiceUserMappedImpl.java | 31 ++++++++++++++++++++++ .../impl/ServiceUserMapperImpl.java | 13 ++++++--- ...java => ServiceUserMappedBundleFilterTest.java} | 13 +++++---- .../impl/ServiceUserMapperImplTest.java | 9 +++---- 7 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapped.java similarity index 52% rename from src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java rename to src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapped.java index 93fe6eb..1e116b1 100644 --- a/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapping.java +++ b/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapped.java @@ -3,15 +3,15 @@ package org.apache.sling.serviceusermapping; import aQute.bnd.annotation.ProviderType; /** - * The <code>ServiceUserMapping</code> service can be used to retrieve an already registered service user mapping. - * A service reference targeting a service user mapping will be satisfied only when <code>ServiceUserMapper.getServiceUserID</code> - * will return the registered user ID in that bundle. + * The <code>ServiceUserMapped</code> is a marker service that can be used to ensure that there is an already registered mapping for a certain service/subService. + * A service reference targeting a <code>ServiceUserMapped</code> will be satisfied only if <code>ServiceUserMapper.getServiceUserID</code> + * will resolve the subService to an userID. * For example setting the reference target to "(subServiceName=mySubService)" ensures that your component only starts when the subService is available. * The subServiceName will not be set for mappings that do not have one, and those can be referenced with a negating target "(!(subServiceName=*))". * Trying to reference a sub service from a bundle for which it was not registered for will not work. */ @ProviderType -public interface ServiceUserMapping { +public interface ServiceUserMapped { /** @@ -19,11 +19,4 @@ public interface ServiceUserMapping { */ static String SUBSERVICENAME = "subServiceName"; - - /** - * Returns the sub service name for this mapping. - * - * @return The sub service name for this mapping. This can be {@code null} if no sub service name is configured for this mapping. - */ - String getSubServiceName(); } diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java b/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java index cdbe4dc..7a4f042 100644 --- a/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java +++ b/src/main/java/org/apache/sling/serviceusermapping/impl/Mapping.java @@ -18,19 +18,17 @@ */ package org.apache.sling.serviceusermapping.impl; -import org.apache.sling.serviceusermapping.ServiceUserMapping; - /** * The <code>Mapping</code> class defines the mapping of a service's name and * optional service information to a user name. */ -class Mapping implements ServiceUserMapping, Comparable<Mapping> { +class Mapping implements Comparable<Mapping> { /** * The name of the osgi property holding the service name. */ - static String SERVICENAME = "serviceName"; + static String SERVICENAME = ".serviceName"; private final String serviceName; diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilter.java similarity index 86% rename from src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java rename to src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilter.java index 81bf8e6..80a625e 100644 --- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilter.java +++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilter.java @@ -21,8 +21,7 @@ package org.apache.sling.serviceusermapping.impl; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; -import org.apache.sling.serviceusermapping.ServiceUserMapping; -import org.osgi.framework.Bundle; +import org.apache.sling.serviceusermapping.ServiceUserMapped; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.ServiceEvent; @@ -40,7 +39,7 @@ import java.util.Map; /** * The <code>ServiceUserMappingBundleFilter</code> only allows the bundle for which the service mapping is available to see it. */ -public class ServiceUserMappingBundleFilter implements EventListenerHook, FindHook { +public class ServiceUserMappedBundleFilter implements EventListenerHook, FindHook { public void event(ServiceEvent serviceEvent, Map map) { @@ -53,8 +52,8 @@ public class ServiceUserMappingBundleFilter implements EventListenerHook, FindHo while (it.hasNext()) { BundleContext ctx = it.next().getKey(); - String bundleName = ctx.getBundle().getSymbolicName(); - if (!serviceName.equals(bundleName)) { + String bundleServiceName = ServiceUserMapperImpl.getServiceName(ctx.getBundle()); + if (!serviceName.equals(bundleServiceName)) { it.remove(); } } @@ -64,7 +63,7 @@ public class ServiceUserMappingBundleFilter implements EventListenerHook, FindHo public void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection references) { - String bundleName = bundleContext.getBundle().getSymbolicName(); + String bundleServiceName = ServiceUserMapperImpl.getServiceName(bundleContext.getBundle()); Iterator<ServiceReference> it = references.iterator(); while (it.hasNext()) { @@ -72,7 +71,7 @@ public class ServiceUserMappingBundleFilter implements EventListenerHook, FindHo if (isServiceMappingReference(serviceReference)) { Object serviceName = serviceReference.getProperty(Mapping.SERVICENAME); - if (serviceName != null && !serviceName.equals(bundleName)) { + if (serviceName != null && !serviceName.equals(bundleServiceName)) { it.remove(); } } @@ -82,7 +81,7 @@ public class ServiceUserMappingBundleFilter implements EventListenerHook, FindHo private static boolean isServiceMappingReference(ServiceReference serviceReference) { Object objectClass = serviceReference.getProperty(Constants.OBJECTCLASS); for (Object o : (Object[]) objectClass) { - if (ServiceUserMapping.class.getName().equals(o)) { + if (ServiceUserMappedImpl.SERVICEUSERMAPPED.equals(o)) { return true; } } diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedImpl.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedImpl.java new file mode 100644 index 0000000..3a7d2d7 --- /dev/null +++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedImpl.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sling.serviceusermapping.impl; + +import org.apache.sling.serviceusermapping.ServiceUserMapped; + +/** + * This is a trivial implementation of the marker interface <code>ServiceUserMapped</code> + */ +public class ServiceUserMappedImpl implements ServiceUserMapped { + + static String SERVICEUSERMAPPED = ServiceUserMapped.class.getName(); + +} diff --git a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java index 9cbe000..a7e9929 100644 --- a/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java +++ b/src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java @@ -45,9 +45,9 @@ import org.apache.felix.scr.annotations.ReferencePolicy; import org.apache.felix.scr.annotations.References; import org.apache.felix.scr.annotations.Service; import org.apache.sling.commons.osgi.PropertiesUtil; +import org.apache.sling.serviceusermapping.ServiceUserMapped; import org.apache.sling.serviceusermapping.ServiceUserMapper; import org.apache.sling.serviceusermapping.ServiceUserValidator; -import org.apache.sling.serviceusermapping.ServiceUserMapping; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; @@ -167,7 +167,7 @@ public class ServiceUserMapperImpl implements ServiceUserMapper { * @see org.apache.sling.serviceusermapping.ServiceUserMapper#getServiceUserID(org.osgi.framework.Bundle, java.lang.String) */ public String getServiceUserID(final Bundle bundle, final String subServiceName) { - final String serviceName = bundle.getSymbolicName(); + final String serviceName = getServiceName(bundle); final String userId = internalGetUserId(serviceName, subServiceName); return isValidUser(userId, serviceName, subServiceName) ? userId : null; } @@ -244,11 +244,12 @@ public class ServiceUserMapperImpl implements ServiceUserMapper { if (!activeMappingRegistrations.containsKey(mapping)) { Dictionary<String, Object> properties = new Hashtable<String, Object>(); if (mapping.getSubServiceName() != null) { - properties.put(ServiceUserMapping.SUBSERVICENAME, mapping.getSubServiceName()); + properties.put(ServiceUserMapped.SUBSERVICENAME, mapping.getSubServiceName()); } properties.put(Mapping.SERVICENAME, mapping.getServiceName()); - ServiceRegistration registration = bundleContext.registerService(ServiceUserMapping.class.getName(), mapping, properties); + ServiceRegistration registration = bundleContext.registerService(ServiceUserMappedImpl.SERVICEUSERMAPPED, + new ServiceUserMappedImpl(), properties); activeMappingRegistrations.put(mapping, registration); } } @@ -289,5 +290,9 @@ public class ServiceUserMapperImpl implements ServiceUserMapper { } return true; } + + static String getServiceName(Bundle bundle) { + return bundle.getSymbolicName(); + } } diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilterTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilterTest.java similarity index 91% rename from src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilterTest.java rename to src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilterTest.java index 5e3d6ae..9f12426 100644 --- a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappingBundleFilterTest.java +++ b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMappedBundleFilterTest.java @@ -21,7 +21,6 @@ package org.apache.sling.serviceusermapping.impl; import junit.framework.TestCase; -import org.apache.sling.serviceusermapping.ServiceUserMapping; import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -44,7 +43,7 @@ import static org.mockito.Mockito.when; /** * Test reference and bundle filtering based on <code>Mapping.SERVICENAME</code> */ -public class ServiceUserMappingBundleFilterTest { +public class ServiceUserMappedBundleFilterTest { final static String BUNDLE1 = "bundle1"; final static String BUNDLE2 = "bundle2"; @@ -80,11 +79,11 @@ public class ServiceUserMappingBundleFilterTest { ServiceEvent serviceEvent = mock(ServiceEvent.class); ServiceReference serviceReference = mock(ServiceReference.class); when(serviceEvent.getServiceReference()).thenReturn(serviceReference); - when(serviceReference.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[]{ServiceUserMapping.class.getName()}); + when(serviceReference.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[]{ServiceUserMappedImpl.SERVICEUSERMAPPED}); when(serviceReference.getProperty(Mapping.SERVICENAME)).thenReturn(BUNDLE1); - EventListenerHook eventListenerHook = new ServiceUserMappingBundleFilter(); + EventListenerHook eventListenerHook = new ServiceUserMappedBundleFilter(); eventListenerHook.event(serviceEvent, map); TestCase.assertEquals(1, map.size()); @@ -102,12 +101,12 @@ public class ServiceUserMappingBundleFilterTest { collection.add(serviceReference2); when(serviceReference1.getProperty(Mapping.SERVICENAME)).thenReturn(BUNDLE1); - when(serviceReference1.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[]{ServiceUserMapping.class.getName()}); + when(serviceReference1.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[]{ServiceUserMappedImpl.SERVICEUSERMAPPED}); when(serviceReference2.getProperty(Mapping.SERVICENAME)).thenReturn(BUNDLE2); - when(serviceReference2.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[]{ServiceUserMapping.class.getName()}); + when(serviceReference2.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[]{ServiceUserMappedImpl.SERVICEUSERMAPPED}); - FindHook findHook = new ServiceUserMappingBundleFilter(); + FindHook findHook = new ServiceUserMappedBundleFilter(); findHook.find(bundleContext1, null, null, false, collection); TestCase.assertEquals(1, collection.size()); diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java index fcae724..e7c86af 100644 --- a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java +++ b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java @@ -24,7 +24,6 @@ import java.util.Map; import junit.framework.TestCase; -import org.apache.sling.serviceusermapping.ServiceUserMapping; import org.apache.sling.serviceusermapping.ServiceUserValidator; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; @@ -237,7 +236,7 @@ public class ServiceUserMapperImplTest { final ServiceRegistrationContextHelper context = new ServiceRegistrationContextHelper(); sum.configure(context.getBundleContext(), config); - TestCase.assertEquals(2, context.getRegistrations(ServiceUserMapping.class.getName()).size()); + TestCase.assertEquals(2, context.getRegistrations(ServiceUserMappedImpl.SERVICEUSERMAPPED).size()); final MappingConfigAmendment mca1 = new MappingConfigAmendment(); @SuppressWarnings("serial") @@ -251,7 +250,7 @@ public class ServiceUserMapperImplTest { mca1.configure(mca1Config); sum.bindAmendment(mca1, mca1Config); - TestCase.assertEquals(3, context.getRegistrations(ServiceUserMapping.class.getName()).size()); + TestCase.assertEquals(3, context.getRegistrations(ServiceUserMappedImpl.SERVICEUSERMAPPED).size()); final MappingConfigAmendment mca2 = new MappingConfigAmendment(); @SuppressWarnings("serial") @@ -265,11 +264,11 @@ public class ServiceUserMapperImplTest { mca2.configure(mca2Config); sum.bindAmendment(mca2, mca2Config); - TestCase.assertEquals(4, context.getRegistrations(ServiceUserMapping.class.getName()).size()); + TestCase.assertEquals(4, context.getRegistrations(ServiceUserMappedImpl.SERVICEUSERMAPPED).size()); sum.unbindAmendment(mca1, mca1Config); - TestCase.assertEquals(3, context.getRegistrations(ServiceUserMapping.class.getName()).size()); + TestCase.assertEquals(3, context.getRegistrations(ServiceUserMappedImpl.SERVICEUSERMAPPED).size()); } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
