incubator-sling-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=832783&view=rev
Log:
SLING-1156
Removed binding to ServiceReference since I think its possible to bind to Comparable instead,
might be wrong when
the sort happens.

Modified:
    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/WrappedResourceProvider.java
    sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java

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=832783&r1=832782&r2=832783&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:48 2009
@@ -23,7 +23,6 @@
 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;
 
@@ -254,7 +253,7 @@
      *         subtree below this entry. Otherwise <code>false</code> is
      *         returned.
      */
-    public boolean addResourceProvider(String prefix, ResourceProvider provider, ServiceReference
serviceReference) {
+    public boolean addResourceProvider(String prefix, ResourceProvider provider, Comparable<?>
comparable) {
         synchronized (this) {
             String[] elements = split(prefix, '/');
             List<ResourceProviderEntry2> entryPath = new ArrayList<ResourceProviderEntry2>();
@@ -267,7 +266,7 @@
                 entryPath.get(i).put(elements[i], rpe2);
                 entryPath.add(rpe2);
             }
-            return entryPath.get(elements.length).addInternalProvider(new WrappedResourceProvider(provider,
serviceReference));
+            return entryPath.get(elements.length).addInternalProvider(new WrappedResourceProvider(provider,
comparable));
 
         }
     }
@@ -308,14 +307,14 @@
     }
 
     public boolean removeResourceProvider(String prefix,
-            ResourceProvider resourceProvider, ServiceReference serviceReference) {
+            ResourceProvider resourceProvider, Comparable<?> comparable) {
         synchronized (this) {
             String[] elements = split(prefix, '/');
             List<ResourceProviderEntry2> entryPath = new ArrayList<ResourceProviderEntry2>();
             populateProviderPath(entryPath, elements);
             if (entryPath.size() == elements.length) {
                 // the last element is a perfect match;
-                return entryPath.get(entryPath.size()-1).removeInternalProvider(new WrappedResourceProvider(resourceProvider,
serviceReference));
+                return entryPath.get(entryPath.size()-1).removeInternalProvider(new WrappedResourceProvider(resourceProvider,
comparable));
             }
             return false;
         }
@@ -370,40 +369,26 @@
      * @return
      */
     private WrappedResourceProvider[] conditionalSort(Set<WrappedResourceProvider>
set) {
-        //
-        // convert to a list so we can selectively sort. We can't guarantee that
-        // all
-        // ResourceProviders implement Comparable so can't use a TreeSet.
-        // However, using a set in the first instance ensures that no one relies
-        // on the add
-        // order.
 
-        List<ResourceProvider> providerList = new ArrayList<ResourceProvider>(
+        List<WrappedResourceProvider> providerList = new ArrayList<WrappedResourceProvider>(
                 set);
-        // ResourceProviders that need to get into the list ahead of others must
-        // implement
-        // the comparable interface. Ones that don't implement the comparable
-        // interface get
-        // placed in a group in the center ordered by the way they were added.
-        // eg high-priority ..... non conflicting .... explicitly low priority
-        // In general if a ResourceProvider will only ever respond with non null
-        // to paths
-        // that no other resource provider will respond with non null its non
-        // conflicting and
-        // so does not require special treatment (eg no Comparable required)
 
-        Collections.sort(providerList, new Comparator<ResourceProvider>() {
+        Collections.sort(providerList, new Comparator<WrappedResourceProvider>() {
 
             @SuppressWarnings("unchecked")
-            public int compare(ResourceProvider o1, ResourceProvider o2) {
-                if (o1 instanceof Comparable) {
-                    Comparable c1 = (Comparable) o1;
-                    return c1.compareTo(o2);
-                } else if (o2 instanceof Comparable) {
-                    Comparable c2 = (Comparable) o2;
-                    return c2.compareTo(o1) * (-1);
+            public int compare(WrappedResourceProvider o1, WrappedResourceProvider o2) {
+                Comparable c1 = o1.getComparable();
+                Comparable c2 = o2.getComparable();
+                if ( c1 == null && c2 == null ) {
+                  return 0;
+                } 
+                if ( c1 == null ) {
+                  return -1;
                 }
-                return 0;
+                if ( c2 == null ) {
+                  return 1;
+                }
+                return c1.compareTo(c2);
             }
         });
 

Modified: 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=832783&r1=832782&r2=832783&view=diff
==============================================================================
--- sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
(original)
+++ sling/trunk/contrib/jcr/resource2/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
Wed Nov  4 16:06:48 2009
@@ -20,7 +20,6 @@
 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;
 
@@ -32,12 +31,12 @@
 public class WrappedResourceProvider  implements ResourceProvider {
 
   private ResourceProvider resourceProvider;
-  private ServiceReference serviceReference;
+  private Comparable<?> serviceReference;
 
   /**
    * 
    */
-  public WrappedResourceProvider(ResourceProvider resourceProvider, ServiceReference serviceReference)
{
+  public WrappedResourceProvider(ResourceProvider resourceProvider, Comparable<?> serviceReference)
{
     this.resourceProvider = resourceProvider;
     this.serviceReference = serviceReference;
   }
@@ -67,7 +66,7 @@
   /**
    * @return
    */
-  public ServiceReference getServiceReference() {
+  public Comparable<?> getComparable() {
     return serviceReference;
   }
   

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=832783&r1=832782&r2=832783&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:48 2009
@@ -23,7 +23,6 @@
 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;
@@ -63,14 +62,14 @@
     }
 
     @Override
-    public boolean addResourceProvider(String prefix, ResourceProvider provider, ServiceReference
serviceReference) {
-        return delegatee.addResourceProvider(prefix, provider, serviceReference);
+    public boolean addResourceProvider(String prefix, ResourceProvider provider, Comparable<?>
comparable) {
+        return delegatee.addResourceProvider(prefix, provider, comparable);
     }
 
     @Override
     public boolean removeResourceProvider(String prefix,
-            ResourceProvider provider, ServiceReference serviceReference) {
-        return delegatee.removeResourceProvider(prefix, provider, serviceReference);
+            ResourceProvider provider, Comparable<?> comparable) {
+        return delegatee.removeResourceProvider(prefix, provider, comparable);
     }
 
     /**



Mime
View raw message