incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r832781 - in /sling/trunk/contrib/jcr/resource2/src: main/java/org/apache/sling/jcr/resource/internal/ main/java/org/apache/sling/jcr/resource/internal/helper/ main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ test/java/org/apach...
Date Wed, 04 Nov 2009 16:06:17 GMT
Author: ieb
Date: Wed Nov  4 16:06:16 2009
New Revision: 832781

URL: http://svn.apache.org/viewvc?rev=832781&view=rev
Log:
Converted the Sorting of ResourceProviders at nodes in the ResourceProviderEntry2 tree to
use the comparable functionality
of the service reference, rather than relying on the implementation of ResourceProviders.

Added:
    sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
  (with props)
Modified:
    sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
    sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry2.java
    sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
    sling/trunk/contrib/jcr/resource2/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java

Modified: sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=832781&r1=832780&r2=832781&view=diff
==============================================================================
--- sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
Wed Nov  4 16:06:16 2009
@@ -32,7 +32,6 @@
 
 import org.apache.commons.collections.BidiMap;
 import org.apache.commons.collections.bidimap.TreeBidiMap;
-import org.apache.jackrabbit.name.Path.RootElement;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -483,7 +482,7 @@
                         }
 
                         rootProviderEntry.addResourceProvider(root,
-                            provider);
+                            provider, reference);
 
                         log.debug("bindResourceProvider: {}={} ({})",
                             new Object[] { root, provider, serviceName });
@@ -529,7 +528,7 @@
                     // TODO: Do not remove this path, if another resource
                     // owns it. This may be the case if adding the provider
                     // yielded an ResourceProviderEntryException
-                    rootProviderEntry.removeResourceProvider(root, provider);
+                    rootProviderEntry.removeResourceProvider(root, provider, reference);
 
                     log.debug("unbindResourceProvider: root={} ({})", root,
                         serviceName);

Modified: sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry2.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry2.java?rev=832781&r1=832780&r2=832781&view=diff
==============================================================================
--- sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry2.java
(original)
+++ sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry2.java
Wed Nov  4 16:06:16 2009
@@ -23,6 +23,7 @@
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.SyntheticResource;
+import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,7 +70,7 @@
 
     // the resource provider kept in this entry supporting resources at and
     // below the path of this entry.
-    private ResourceProvider[] providers = new ResourceProvider[0];
+    private WrappedResourceProvider[] providers = new WrappedResourceProvider[0];
 
     private long ttime = 0L;
 
@@ -91,7 +92,7 @@
      * @param provider
      *            The resource provider to encapsulate by this entry.
      */
-    public ResourceProviderEntry2(String path, ResourceProvider[] provider) {
+    public ResourceProviderEntry2(String path, ResourceProvider[] providerList) {
         if (path.endsWith("/")) {
             this.path = path.substring(0, path.length() - 1);
             this.prefix = path;
@@ -99,7 +100,16 @@
             this.path = path;
             this.prefix = path + "/";
         }
-        this.providers = provider;
+        if ( providerList != null ) {
+          providers = new WrappedResourceProvider[providerList.length];
+          for ( int i = 0; i < providerList.length; i++ ) {
+            if ( providerList[i] instanceof WrappedResourceProvider ) {
+              providers[i] = (WrappedResourceProvider) providerList[i];
+            } else {
+              providers[i] = new WrappedResourceProvider(providerList[i], null);
+            }
+          }
+        }
         
         // this will consume slightly more memory but ensures read is fast.
         storageMap.setFast(true);
@@ -244,7 +254,7 @@
      *         subtree below this entry. Otherwise <code>false</code> is
      *         returned.
      */
-    public boolean addResourceProvider(String prefix, ResourceProvider provider) {
+    public boolean addResourceProvider(String prefix, ResourceProvider provider, ServiceReference
serviceReference) {
         synchronized (this) {
             String[] elements = split(prefix, '/');
             List<ResourceProviderEntry2> entryPath = getResourceProviderPath(elements);
@@ -259,7 +269,7 @@
                 entryPath.get(i).put(elements[i], rpe2);
                 entryPath.add(rpe2);
             }
-            return entryPath.get(elements.length).addInternalProvider(provider);
+            return entryPath.get(elements.length).addInternalProvider(new WrappedResourceProvider(provider,
serviceReference));
 
         }
     }
@@ -300,13 +310,13 @@
     }
 
     public boolean removeResourceProvider(String prefix,
-            ResourceProvider provider) {
+            ResourceProvider resourceProvider, ServiceReference serviceReference) {
         synchronized (this) {
             String[] elements = split(prefix, '/');
             List<ResourceProviderEntry2> entryPath = getResourceProviderPath(elements);
             if (entryPath.size() == elements.length) {
                 // the first element is a perfect match;
-                return entryPath.get(0).removeInternalProvider(provider);
+                return entryPath.get(0).removeInternalProvider(new WrappedResourceProvider(resourceProvider,
serviceReference));
             }
             return false;
         }
@@ -325,10 +335,10 @@
      * 
      * @param provider
      */
-    private boolean addInternalProvider(ResourceProvider provider) {
+    private boolean addInternalProvider(WrappedResourceProvider provider) {
         synchronized (providers) {
             int before = providers.length;
-            Set<ResourceProvider> set = new HashSet<ResourceProvider>();
+            Set<WrappedResourceProvider> set = new HashSet<WrappedResourceProvider>();
             if (providers != null) {
                 set.addAll(Arrays.asList(providers));
             }
@@ -343,10 +353,10 @@
      * @param provider
      * @return
      */
-    private boolean removeInternalProvider(ResourceProvider provider) {
+    private boolean removeInternalProvider(WrappedResourceProvider provider) {
         synchronized (providers) {
             int before = providers.length;
-            Set<ResourceProvider> set = new HashSet<ResourceProvider>();
+            Set<WrappedResourceProvider> set = new HashSet<WrappedResourceProvider>();
             if (providers != null) {
                 set.addAll(Arrays.asList(providers));
             }
@@ -360,7 +370,7 @@
      * @param set
      * @return
      */
-    private ResourceProvider[] conditionalSort(Set<ResourceProvider> set) {
+    private WrappedResourceProvider[] conditionalSort(Set<WrappedResourceProvider>
set) {
         //
         // convert to a list so we can selectively sort. We can't guarantee that
         // all
@@ -398,7 +408,7 @@
             }
         });
 
-        return set.toArray(new ResourceProvider[set.size()]);
+        return set.toArray(new WrappedResourceProvider[set.size()]);
     }
 
     /**

Added: sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java?rev=832781&view=auto
==============================================================================
--- sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
(added)
+++ sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
Wed Nov  4 16:06:16 2009
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Sakai Foundation (SF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF 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.jcr.resource.internal.helper;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ */
+public class WrappedResourceProvider  implements ResourceProvider {
+
+  private ResourceProvider resourceProvider;
+  private ServiceReference serviceReference;
+
+  /**
+   * 
+   */
+  public WrappedResourceProvider(ResourceProvider resourceProvider, ServiceReference serviceReference)
{
+    this.resourceProvider = resourceProvider;
+    this.serviceReference = serviceReference;
+  }
+  /**
+   * {@inheritDoc}
+   * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver,
java.lang.String)
+   */
+  public Resource getResource(ResourceResolver arg0, String arg1) {
+    return resourceProvider.getResource(arg0, arg1);
+  }
+
+  /**
+   * {@inheritDoc}
+   * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver,
javax.servlet.http.HttpServletRequest, java.lang.String)
+   */
+  public Resource getResource(ResourceResolver arg0, HttpServletRequest arg1, String arg2)
{
+    return resourceProvider.getResource(arg0, arg1, arg2);
+  }
+
+  /**
+   * {@inheritDoc}
+   * @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
+   */
+  public Iterator<Resource> listChildren(Resource arg0) {
+    return resourceProvider.listChildren(arg0);
+  }
+  /**
+   * @return
+   */
+  public ServiceReference getServiceReference() {
+    return serviceReference;
+  }
+  
+  /**
+   * {@inheritDoc}
+   * @see java.lang.Object#hashCode()
+   */
+  @Override
+  public int hashCode() {
+    return resourceProvider.hashCode();
+  }
+  
+  /**
+   * {@inheritDoc}
+   * @see java.lang.Object#equals(java.lang.Object)
+   */
+  @Override
+  public boolean equals(Object obj) {
+    if ( obj instanceof WrappedResourceProvider ) {
+      return resourceProvider.equals(((WrappedResourceProvider) obj).resourceProvider);
+    } else if ( obj instanceof ResourceProvider) {
+      return resourceProvider.equals(obj);
+    }
+    return super.equals(obj);
+  }
+
+
+}

Propchange: sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java?rev=832781&r1=832780&r2=832781&view=diff
==============================================================================
--- sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
(original)
+++ sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
Wed Nov  4 16:06:16 2009
@@ -23,6 +23,7 @@
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.jcr.resource.JcrResourceTypeProvider;
 import org.apache.sling.jcr.resource.internal.helper.ResourceProviderEntry2;
+import org.osgi.framework.ServiceReference;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -62,14 +63,14 @@
     }
 
     @Override
-    public boolean addResourceProvider(String prefix, ResourceProvider provider) {
-        return delegatee.addResourceProvider(prefix, provider);
+    public boolean addResourceProvider(String prefix, ResourceProvider provider, ServiceReference
serviceReference) {
+        return delegatee.addResourceProvider(prefix, provider, serviceReference);
     }
 
     @Override
     public boolean removeResourceProvider(String prefix,
-            ResourceProvider provider) {
-        return delegatee.removeResourceProvider(prefix, provider);
+            ResourceProvider provider, ServiceReference serviceReference) {
+        return delegatee.removeResourceProvider(prefix, provider, serviceReference);
     }
 
     /**

Modified: sling/trunk/contrib/jcr/resource2/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/jcr/resource2/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java?rev=832781&r1=832780&r2=832781&view=diff
==============================================================================
--- sling/trunk/contrib/jcr/resource2/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java
(original)
+++ sling/trunk/contrib/jcr/resource2/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryTest.java
Wed Nov  4 16:06:16 2009
@@ -26,12 +26,10 @@
 
 import junit.framework.TestCase;
 
-import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.SyntheticResource;
 
 public class ResourceProviderEntryTest extends TestCase {
 
@@ -65,7 +63,7 @@
     public void testAdd1Provider() {
         String firstPath = "/rootel";
         ResourceProvider first = new TestResourceProvider(firstPath);
-        root.addResourceProvider(firstPath, first);
+        root.addResourceProvider(firstPath, first, null);
         
 
         assertEquals(root, root.getResource(null, "/"));
@@ -88,9 +86,9 @@
         ResourceProvider second = new TestResourceProvider(secondPath);
         ResourceProvider third = new TestResourceProvider(thirdPath);
 
-        root.addResourceProvider(firstPath, first);
-        root.addResourceProvider(secondPath, second);
-        root.addResourceProvider(thirdPath, third);
+        root.addResourceProvider(firstPath, first, null);
+        root.addResourceProvider(secondPath, second, null);
+        root.addResourceProvider(thirdPath, third, null);
 
         
 
@@ -115,9 +113,9 @@
         ResourceProvider second = new TestResourceProvider(secondPath);
         ResourceProvider third = new TestResourceProvider(thirdPath);
 
-        root.addResourceProvider(thirdPath, third);
-        root.addResourceProvider(secondPath, second);
-        root.addResourceProvider(firstPath, first);
+        root.addResourceProvider(thirdPath, third, null);
+        root.addResourceProvider(secondPath, second, null);
+        root.addResourceProvider(firstPath, first, null);
 
         assertEquals(rootProvider, root.getResource(null, "/"));
         assertEquals(first, root.getResource(null, "/rootel"));
@@ -140,15 +138,15 @@
         ResourceProvider second = new TestResourceProvider(secondPath);
         ResourceProvider third = new TestResourceProvider(thirdPath);
 
-        root.addResourceProvider(firstPath, first);
-        root.addResourceProvider(secondPath, second);
-        root.addResourceProvider(thirdPath, third);
+        root.addResourceProvider(firstPath, first, null);
+        root.addResourceProvider(secondPath, second, null);
+        root.addResourceProvider(thirdPath, third, null);
 
         assertEquals(rootProvider, root.getResource(null, "/"));
         assertEquals(first, root.getResource(null, "/rootel/html.js"));
         assertEquals(second, root.getResource(null, "/rootel/child/html.js"));
 
-        root.removeResourceProvider(firstPath, first);
+        root.removeResourceProvider(firstPath, first, null);
         
 
         assertEquals(rootProvider, root.getResource(null, "/"));
@@ -156,7 +154,7 @@
         assertEquals(rootProvider, root.getResource(null, "/rootel/html.js"));
         assertEquals(second, root.getResource(null, "/rootel/child/html.js"));
 
-        root.addResourceProvider(firstPath, first);
+        root.addResourceProvider(firstPath, first, null);
 
         assertEquals(rootProvider, root.getResource(null, "/"));
         assertEquals(first, root.getResource(null, "/rootel/html.js"));



Mime
View raw message