sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1622419 - /sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourcePickerWhiteboard.java
Date Thu, 04 Sep 2014 08:43:49 GMT
Author: cziegeler
Date: Thu Sep  4 08:43:48 2014
New Revision: 1622419

URL: http://svn.apache.org/r1622419
Log:
SLING-3423 - ResourceMergerService API must allow custom merge paths

Modified:
    sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourcePickerWhiteboard.java

Modified: sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourcePickerWhiteboard.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourcePickerWhiteboard.java?rev=1622419&r1=1622418&r2=1622419&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourcePickerWhiteboard.java
(original)
+++ sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourcePickerWhiteboard.java
Thu Sep  4 08:43:48 2014
@@ -20,6 +20,8 @@ package org.apache.sling.resourcemerger.
 
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -29,6 +31,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.resourcemerger.spi.MergedResourcePicker;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.util.tracker.ServiceTracker;
@@ -41,8 +44,10 @@ public class MergedResourcePickerWhitebo
 
     private BundleContext bundleContext;
 
+    private final Map<Long, ServiceRegistration> serviceRegistrations = new ConcurrentHashMap<Long,
ServiceRegistration>();
+
     @Activate
-    protected void activate(BundleContext bundleContext) {
+    protected void activate(final BundleContext bundleContext) {
         this.bundleContext = bundleContext;
         tracker = new ServiceTracker(bundleContext, MergedResourcePicker.class.getName(),
this);
         tracker.open();
@@ -53,28 +58,38 @@ public class MergedResourcePickerWhitebo
         tracker.close();
     }
 
-    public Object addingService(ServiceReference reference) {
-        MergedResourcePicker picker = (MergedResourcePicker) bundleContext.getService(reference);
-        String mergeRoot = PropertiesUtil.toString(reference.getProperty(MergedResourcePicker.MERGE_ROOT),
null);
-        if (mergeRoot != null) {
-            ResourceProviderFactory providerFactory = new MergingResourceProviderFactory(mergeRoot,
picker);
-            Dictionary<Object, Object> props = new Hashtable<Object, Object>();
-            props.put(ResourceProvider.ROOTS, mergeRoot);
-            props.put(ResourceProvider.OWNS_ROOTS, true);
-            return bundleContext.registerService(ResourceProviderFactory.class.getName(),
providerFactory, props);
-        } else {
-            return null;
+    public Object addingService(final ServiceReference reference) {
+        final MergedResourcePicker picker = (MergedResourcePicker) bundleContext.getService(reference);
+        if ( picker != null ) {
+            final String mergeRoot = PropertiesUtil.toString(reference.getProperty(MergedResourcePicker.MERGE_ROOT),
null);
+            if (mergeRoot != null) {
+                final ResourceProviderFactory providerFactory = new MergingResourceProviderFactory(mergeRoot,
picker);
+                final Dictionary<Object, Object> props = new Hashtable<Object, Object>();
+                props.put(ResourceProvider.ROOTS, mergeRoot);
+                props.put(ResourceProvider.OWNS_ROOTS, true);
+
+                final Long key = (Long) reference.getProperty(Constants.SERVICE_ID);
+                final ServiceRegistration reg = bundleContext.registerService(ResourceProviderFactory.class.getName(),
providerFactory, props);
+
+                serviceRegistrations.put(key, reg);
+
+            }
+            return picker;
         }
+        return null;
     }
 
-    public void modifiedService(ServiceReference reference, Object service) {
-        // TODO Auto-generated method stub
-
+    public void modifiedService(final ServiceReference reference, final Object service) {
+        removedService(reference, service);
+        addingService(reference);
     }
 
-    public void removedService(ServiceReference reference, Object service) {
-        if (service instanceof ServiceRegistration) {
-            ((ServiceRegistration) service).unregister();
+    public void removedService(final ServiceReference reference, final Object service) {
+        final Long key = (Long) reference.getProperty(Constants.SERVICE_ID);
+        final ServiceRegistration reg = serviceRegistrations.get(key);
+        if ( reg != null ) {
+            reg.unregister();
+            this.bundleContext.ungetService(reference);
         }
     }
 



Mime
View raw message