You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/01/15 13:32:53 UTC

svn commit: r612098 - /incubator/sling/whiteboard/fmeschbe/resource/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java

Author: fmeschbe
Date: Tue Jan 15 04:32:53 2008
New Revision: 612098

URL: http://svn.apache.org/viewvc?rev=612098&view=rev
Log:
Register ResourceProvider services

Modified:
    incubator/sling/whiteboard/fmeschbe/resource/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java

Modified: incubator/sling/whiteboard/fmeschbe/resource/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=612098&r1=612097&r2=612098&view=diff
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java (original)
+++ incubator/sling/whiteboard/fmeschbe/resource/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java Tue Jan 15 04:32:53 2008
@@ -32,6 +32,7 @@
 
 import org.apache.commons.collections.BidiMap;
 import org.apache.commons.collections.bidimap.TreeBidiMap;
+import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.jcr.api.SlingRepository;
@@ -39,8 +40,9 @@
 import org.apache.sling.jcr.resource.internal.helper.Mapping;
 import org.apache.sling.jcr.resource.internal.helper.ResourceProviderEntry;
 import org.apache.sling.jcr.resource.internal.helper.bundle.BundleResourceProvider;
-import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvderEntry;
+import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderEntry;
 import org.apache.sling.jcr.resource.internal.loader.Loader;
+import org.apache.sling.osgi.commons.OsgiUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleListener;
@@ -62,13 +64,16 @@
  * descriptors provided by bundles.
  * <li>Fires OSGi EventAdmin events on behalf of internal helper objects
  * </ul>
- *
+ * 
  * @scr.component immediate="true" label="%resource.resolver.name"
  *                description="%resource.resolver.description"
  * @scr.property name="service.description" value="Sling
  *               JcrResourceResolverFactory Implementation"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
  * @scr.service interface="org.apache.sling.jcr.resource.JcrResourceResolverFactory"
+ * @scr.reference name="ResourceProvider"
+ *                interface="org.apache.sling.api.resource.ResourceProvider"
+ *                cardinality="0..n" policy="dynamic"
  */
 public class JcrResourceResolverFactoryImpl implements
         JcrResourceResolverFactory, BundleListener {
@@ -83,7 +88,7 @@
      * maven plugin and the sling management console cannot handle empty
      * multivalue properties at the moment. So we just add a dummy direct
      * mapping.
-     *
+     * 
      * @scr.property values.1="/-/"
      */
     private static final String PROP_VIRTUAL = "resource.resolver.virtual";
@@ -101,14 +106,14 @@
 
     /**
      * The JCR Repository we access to resolve resources
-     *
+     * 
      * @scr.reference
      */
     private SlingRepository repository;
 
     /**
      * The OSGi EventAdmin service used to dispatch events
-     *
+     * 
      * @scr.reference cardinality="0..1" policy="dynamic"
      */
     private EventAdmin eventAdmin;
@@ -116,11 +121,13 @@
     /**
      * The MimeTypeService used by the initial content initialContentLoader to
      * resolve MIME types for files to be installed.
-     *
+     * 
      * @scr.reference cardinality="0..1" policy="dynamic"
      */
     private MimeTypeService mimeTypeService;
 
+    private ComponentContext componentContext;
+    
     /**
      * This services ServiceReference for use in
      * {@link #fireEvent(Bundle, String, Map)}
@@ -140,7 +147,7 @@
      * Map of administrative sessions used to check item existence. Indexed by
      * workspace name. The map is filled on-demand. The sessions are closed when
      * the factory is deactivated.
-     *
+     * 
      * @see #itemReallyExists(Session, String)
      */
     private Map<String, Session> adminSessions = new HashMap<String, Session>();
@@ -169,7 +176,7 @@
      * may be cast.
      */
     public ResourceResolver getResourceResolver(Session session) {
-        JcrResourceProvderEntry sessionRoot = new JcrResourceProvderEntry(this,
+        JcrResourceProviderEntry sessionRoot = new JcrResourceProviderEntry(this,
             session, rootProviderEntry.getEntries());
         return new JcrResourceResolver(sessionRoot, this);
     }
@@ -180,7 +187,7 @@
      * Loads and unloads any components provided by the bundle whose state
      * changed. If the bundle has been started, the components are loaded. If
      * the bundle is about to stop, the components are unloaded.
-     *
+     * 
      * @param event The <code>BundleEvent</code> representing the bundle state
      *            change.
      */
@@ -226,7 +233,7 @@
 
     /**
      * Fires an OSGi event through the EventAdmin service.
-     *
+     * 
      * @param sourceBundle The Bundle from which the event originates. This may
      *            be <code>null</code> if there is no originating bundle.
      * @param eventName The name of the event
@@ -325,8 +332,8 @@
             BundleResourceProvider brp = new BundleResourceProvider(bundle,
                 prefixes);
             String[] rootPaths = brp.getRoots();
-            for (int i=0; i < rootPaths.length; i++) {
-                rootProviderEntry.addResourceProvider(rootPaths[i], brp);
+            for (String rootPath : rootPaths) {
+                rootProviderEntry.addResourceProvider(rootPath, brp);
             }
             bundleResourceProviderMap.put(bundle.getBundleId(), brp);
         }
@@ -336,8 +343,8 @@
         BundleResourceProvider brp = bundleResourceProviderMap.get(bundle.getBundleId());
         if (brp != null) {
             String[] rootPaths = brp.getRoots();
-            for (int i=0; i < rootPaths.length; i++) {
-                rootProviderEntry.removeResourceProvider(rootPaths[i]);
+            for (String rootPath : rootPaths) {
+                rootProviderEntry.removeResourceProvider(rootPath);
             }
         }
     }
@@ -346,6 +353,7 @@
 
     /** Activates this component, called by SCR before registering as a service */
     protected void activate(ComponentContext componentContext) {
+        this.componentContext = componentContext;
         this.serviceReference = componentContext.getServiceReference();
 
         this.initialContentLoader = new Loader(this);
@@ -364,7 +372,7 @@
                 }
 
                 if (bundle.getState() == Bundle.ACTIVE) {
-                    // add bundle resource provider for active bundles 
+                    // add bundle resource provider for active bundles
                     addBundleResourceProvider(bundle);
                 }
             }
@@ -416,8 +424,32 @@
         for (int i = 0; i < sessions.length; i++) {
             sessions[i].logout();
         }
+        
+        this.componentContext = null;
     }
 
+    protected void bindResourceProvider(ServiceReference reference) {
+        String[] roots = OsgiUtil.toStringArray(reference.getProperty(ResourceProvider.ROOTS));
+        if (roots != null && roots.length > 0) {
+            
+            ResourceProvider provider = (ResourceProvider) componentContext.locateService(
+                "ResourceProvider", reference);
+            
+            for (String root : roots) {
+                rootProviderEntry.addResourceProvider(root, provider);
+            }
+        }
+    }
+    
+    protected void unbindResourceProvider(ServiceReference reference) {
+        String[] roots = OsgiUtil.toStringArray(reference.getProperty(ResourceProvider.ROOTS));
+        if (roots != null && roots.length > 0) {
+            for (String root : roots) {
+                rootProviderEntry.removeResourceProvider(root);
+            }
+        }
+    }
+    
     // ---------- internal helper ----------------------------------------------
 
     /** Returns the JCR repository used by this factory */