incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1345668 - in /sling/whiteboard/SLING-2396/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/helper/ test/java/org/apache/sling/resourceresolver/impl/helper/
Date Sun, 03 Jun 2012 13:17:21 GMT
Author: cziegeler
Date: Sun Jun  3 13:17:21 2012
New Revision: 1345668

URL: http://svn.apache.org/viewvc?rev=1345668&view=rev
Log:
SLING-2396 : Add new resource provider interfaces (WiP)

Added:
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java
  (contents, props changed)
      - copied, changed from r1345530, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/AbstractWrappedResourceProvider.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java
  (contents, props changed)
      - copied, changed from r1345530, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProviderFactory.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderHandler.java
  (contents, props changed)
      - copied, changed from r1345530, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProvider.java
Removed:
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/AbstractWrappedResourceProvider.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProvider.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProviderFactory.java
Modified:
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceIterator.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntry.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RootResourceProviderEntry.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
    sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java

Copied: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java
(from r1345530, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/AbstractWrappedResourceProvider.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java?p2=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java&p1=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/AbstractWrappedResourceProvider.java&r1=1345530&r2=1345668&rev=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/AbstractWrappedResourceProvider.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java
Sun Jun  3 13:17:21 2012
@@ -23,50 +23,73 @@ import java.util.Map;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.osgi.ServiceUtil;
+import org.osgi.framework.Constants;
 
 /**
- *
+ * The provider handler is the common base class for the
+ * {@link ResourceProviderHandler} and the
+ * {@link ResourceProviderFactoryHandler}.
  */
-public abstract class AbstractWrappedResourceProvider {
-
-    private final Comparable<?> comparable;
-
-    /** Unique key to identify this resource provider. */
-    private final String key;
+public abstract class ProviderHandler implements Comparable<ProviderHandler> {
 
     /** Service properties. */
     private final Map<String, Object> properties;
 
+    /** Unique service id */
+    private final Long serviceId;
+
     /**
      *
      */
-    public AbstractWrappedResourceProvider(final Map<String, Object> properties,
-                    final String key) {
-        this.comparable = ServiceUtil.getComparableForServiceRanking(properties);
+    public ProviderHandler(final Map<String, Object> properties) {
         this.properties = properties;
-        this.key = key;
+        this.serviceId = (Long) properties.get(Constants.SERVICE_ID);
     }
 
     /**
-     * Return the unique key for a provider.
+     * Return the service properties.
      */
-    public String getKey() {
-        return this.key;
+    public Map<String, Object> getProperties() {
+        return this.properties;
     }
 
     /**
-     * Return the service properties.
+     * Return the service id.
      */
-    public Map<String, Object> getProperties() {
-        return this.properties;
+    public Long getServiceId() {
+        return this.serviceId;
     }
 
     /**
-     *
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
      */
-    public Comparable<?> getComparable() {
-        return this.comparable;
+    public int compareTo(final ProviderHandler other) {
+        if (this.serviceId.equals(other.serviceId)) {
+            return 0; // same service
+        }
+
+        Object rankObj = this.getProperties().get(Constants.SERVICE_RANKING);
+        Object otherRankObj = other.getProperties().get(Constants.SERVICE_RANKING);
+
+        // If no rank, then spec says it defaults to zero.
+        rankObj = (rankObj == null) ? new Integer(0) : rankObj;
+        otherRankObj = (otherRankObj == null) ? new Integer(0) : otherRankObj;
+
+        // If rank is not Integer, then spec says it defaults to zero.
+        Integer rank = (rankObj instanceof Integer)
+            ? (Integer) rankObj : new Integer(0);
+        Integer otherRank = (otherRankObj instanceof Integer)
+            ? (Integer) otherRankObj : new Integer(0);
+
+        // Sort by rank in ascending order.
+        if (rank.compareTo(otherRank) < 0) {
+            return -1; // lower rank
+        } else if (rank.compareTo(otherRank) > 0) {
+            return 1; // higher rank
+        }
+
+        // If ranks are equal, then sort by service id in descending order.
+        return (this.serviceId.compareTo(other.serviceId) < 0) ? 1 : -1;
     }
 
     /**
@@ -82,5 +105,13 @@ public abstract class AbstractWrappedRes
     /**
      * Return a name of the resource provider/factory.
      */
-    public abstract String getName();
+    public String getName() {
+        final StringBuilder snBuilder = new StringBuilder(64);
+        snBuilder.append('{');
+        snBuilder.append(this.toString());
+        snBuilder.append('/');
+        snBuilder.append(this.serviceId.toString());
+        snBuilder.append('}');
+        return snBuilder.toString();
+    }
 }

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ProviderHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceIterator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceIterator.java?rev=1345668&r1=1345667&r2=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceIterator.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceIterator.java
Sun Jun  3 13:17:21 2012
@@ -65,7 +65,7 @@ public class ResourceIterator implements
      * <code>ResourceProvider</code> objects registered as nodes above the
      * {@link #parentResource} up to the root of the resource tree
      */
-    private final Iterator<AbstractWrappedResourceProvider> providers;
+    private final Iterator<ProviderHandler> providers;
 
     /**
      * The child {@link ResourceProviderEntry} registered at the node of the
@@ -133,7 +133,7 @@ public class ResourceIterator implements
         // gather the providers in linked set, such that we keep
         // the order of addition and make sure we only get one entry
         // for each resource provider
-        final Set<AbstractWrappedResourceProvider> providersSet = new LinkedHashSet<AbstractWrappedResourceProvider>();
+        final Set<ProviderHandler> providersSet = new LinkedHashSet<ProviderHandler>();
         final ResourceProviderEntry atPath = getResourceProviders(path, providersSet);
 
         if (log.isDebugEnabled()) {
@@ -171,7 +171,7 @@ public class ResourceIterator implements
         while (delayedIter == null) {
             while ((resources == null || !resources.hasNext())
                             && providers.hasNext()) {
-                final AbstractWrappedResourceProvider provider = providers.next();
+                final ProviderHandler provider = providers.next();
                 resources = provider.listChildren(this.resourceResolverContext, parentResource);
                 log.debug("     Checking Provider {} ", provider);
             }
@@ -270,7 +270,7 @@ public class ResourceIterator implements
      *         <code>null</code> if there is no entry at the given location
      */
     private ResourceProviderEntry getResourceProviders(final String path,
-                    final Set<AbstractWrappedResourceProvider> providers) {
+                    final Set<ProviderHandler> providers) {
 
         // collect providers along the ancestor path segements
         final String[] elements = ResourceProviderEntry.split(path, '/');
@@ -282,7 +282,7 @@ public class ResourceIterator implements
                     log.debug("Loading from {}  {} ", element,
                                     base.getResourceProviders().length);
                 }
-                for (final AbstractWrappedResourceProvider rp : base.getResourceProviders())
{
+                for (final ProviderHandler rp : base.getResourceProviders()) {
                     log.debug("Adding {} for {} ", rp, path);
                     providers.add(rp);
                 }
@@ -294,7 +294,7 @@ public class ResourceIterator implements
         }
 
         // add in providers at this node in the tree, ie the root provider
-        for (final AbstractWrappedResourceProvider rp : rootProviderEntry.getResourceProviders())
{
+        for (final ProviderHandler rp : rootProviderEntry.getResourceProviders()) {
             log.debug("Loading All at {} ", path);
             providers.add(rp);
         }

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntry.java?rev=1345668&r1=1345667&r2=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntry.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntry.java
Sun Jun  3 13:17:21 2012
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -57,7 +56,7 @@ public class ResourceProviderEntry imple
 
     // the resource provider kept in this entry supporting resources at and
     // below the path of this entry.
-    private AbstractWrappedResourceProvider[] providers = new AbstractWrappedResourceProvider[0];
+    private ProviderHandler[] providers = new ProviderHandler[0];
 
     private long ttime = 0L;
 
@@ -75,13 +74,13 @@ public class ResourceProviderEntry imple
      * Creates an instance of this class with the given path relative to the
      * parent resource provider entry, encapsulating the given ResourceProvider,
      * and a number of inital child entries.
-     * 
+     *
      * @param path
      *            The relative path supported by the provider
      * @param providerList
      *            The resource provider to encapsulate by this entry.
      */
-    public ResourceProviderEntry(final String path, final AbstractWrappedResourceProvider[]
providerList) {
+    public ResourceProviderEntry(final String path, final ProviderHandler[] providerList)
{
         if (path.endsWith("/")) {
             this.path = path.substring(0, path.length() - 1);
             this.prefix = path;
@@ -90,7 +89,7 @@ public class ResourceProviderEntry imple
             this.prefix = path + "/";
         }
         if (providerList != null) {
-            providers = new AbstractWrappedResourceProvider[providerList.length];
+            providers = new ProviderHandler[providerList.length];
             for (int i = 0; i < providerList.length; i++) {
                 providers[i] = providerList[i];
             }
@@ -108,7 +107,7 @@ public class ResourceProviderEntry imple
     /**
      * Returns the resource providers contained in this entry
      */
-    public AbstractWrappedResourceProvider[] getResourceProviders() {
+    public ProviderHandler[] getResourceProviders() {
         return providers;
     }
 
@@ -116,7 +115,7 @@ public class ResourceProviderEntry imple
      * Returns the resource with the given path or <code>null</code> if neither
      * the resource provider of this entry nor the resource provider of any of
      * the child entries can provide the resource.
-     * 
+     *
      * @param path
      *            The path to the resource to return.
      * @return The resource for the path or <code>null</code> if no resource
can
@@ -130,12 +129,12 @@ public class ResourceProviderEntry imple
 
     /**
      * Adds the given resource provider into the tree for the given prefix.
-     * 
+     *
      * @return <code>true</code> if the provider could be entered into the
      *         subtree below this entry. Otherwise <code>false</code> is
      *         returned.
      */
-    public synchronized boolean addResourceProvider(final String prefix, final AbstractWrappedResourceProvider
provider) {
+    public synchronized boolean addResourceProvider(final String prefix, final ProviderHandler
provider) {
         final String[] elements = split(prefix, '/');
         final List<ResourceProviderEntry> entryPath = new ArrayList<ResourceProviderEntry>();
         entryPath.add(this); // add this the start so if the list is empty
@@ -143,7 +142,7 @@ public class ResourceProviderEntry imple
         populateProviderPath(entryPath, elements);
         for (int i = entryPath.size() - 1; i < elements.length; i++) {
             final String stubPrefix = elements[i];
-            final ResourceProviderEntry rpe2 = new ResourceProviderEntry(stubPrefix, new
AbstractWrappedResourceProvider[0]);
+            final ResourceProviderEntry rpe2 = new ResourceProviderEntry(stubPrefix, new
ProviderHandler[0]);
             entryPath.get(i).put(stubPrefix, rpe2);
             entryPath.add(rpe2);
         }
@@ -172,7 +171,7 @@ public class ResourceProviderEntry imple
         return storageMapValues;
     }
 
-    public synchronized boolean removeResourceProvider(final String prefix, final AbstractWrappedResourceProvider
resourceProvider) {
+    public synchronized boolean removeResourceProvider(final String prefix, final ProviderHandler
resourceProvider) {
         final String[] elements = split(prefix, '/');
         final List<ResourceProviderEntry> entryPath = new ArrayList<ResourceProviderEntry>();
         populateProviderPath(entryPath, elements);
@@ -193,14 +192,12 @@ public class ResourceProviderEntry imple
 
     /**
      * Adds a list of providers to this entry.
-     * 
+     *
      * No sync required as this is called by a sync method!
-     * 
-     * @param provider
      */
-    private boolean addInternalProvider(final AbstractWrappedResourceProvider provider) {
+    private boolean addInternalProvider(final ProviderHandler provider) {
         final int before = providers.length;
-        final Set<AbstractWrappedResourceProvider> set = new HashSet<AbstractWrappedResourceProvider>();
+        final Set<ProviderHandler> set = new HashSet<ProviderHandler>();
         if (providers != null) {
             set.addAll(Arrays.asList(providers));
         }
@@ -212,12 +209,12 @@ public class ResourceProviderEntry imple
 
     /**
      * Remove a provider from the list of entries.
-     * 
+     *
      * No sync required as this is called by a sync method!
      */
-    private boolean removeInternalProvider(final AbstractWrappedResourceProvider provider)
{
+    private boolean removeInternalProvider(final ProviderHandler provider) {
         final int before = providers.length;
-        final Set<AbstractWrappedResourceProvider> set = new HashSet<AbstractWrappedResourceProvider>();
+        final Set<ProviderHandler> set = new HashSet<ProviderHandler>();
         if (providers != null) {
             set.addAll(Arrays.asList(providers));
         }
@@ -227,39 +224,21 @@ public class ResourceProviderEntry imple
     }
 
     /**
-     * @param set
-     * @return
+     * Return a sorted array of handlers.
      */
-    private AbstractWrappedResourceProvider[] conditionalSort(final Set<AbstractWrappedResourceProvider>
set) {
+    private ProviderHandler[] conditionalSort(final Set<ProviderHandler> set) {
 
-        final List<AbstractWrappedResourceProvider> providerList = new ArrayList<AbstractWrappedResourceProvider>(set);
+        final List<ProviderHandler> providerList = new ArrayList<ProviderHandler>(set);
 
-        Collections.sort(providerList, new Comparator<AbstractWrappedResourceProvider>()
{
+        Collections.sort(providerList);
 
-            @SuppressWarnings({ "rawtypes", "unchecked" })
-            public int compare(final AbstractWrappedResourceProvider o1, final AbstractWrappedResourceProvider
o2) {
-                final Comparable c1 = o1.getComparable();
-                final Comparable c2 = o2.getComparable();
-                if (c1 == null && c2 == null) {
-                    return 0;
-                }
-                if (c1 == null) {
-                    return -1;
-                }
-                if (c2 == null) {
-                    return 1;
-                }
-                return c1.compareTo(c2);
-            }
-        });
-
-        return providerList.toArray(new AbstractWrappedResourceProvider[providerList.size()]);
+        return providerList.toArray(new ProviderHandler[providerList.size()]);
     }
 
     /**
      * Get a of ResourceProvidersEntries leading to the fullPath in reverse
      * order.
-     * 
+     *
      * @param fullPath
      *            the full path
      */
@@ -281,7 +260,7 @@ public class ResourceProviderEntry imple
 
     /**
      * Resolve a resource from a path into a Resource
-     * 
+     *
      * @param resolver
      *            the ResourceResolver.
      * @param fullPath
@@ -304,8 +283,8 @@ public class ResourceProviderEntry imple
             // the path is in reverse order end first
 
             for (int i = list.size() - 1; i >= 0; i--) {
-                final AbstractWrappedResourceProvider[] rps = list.get(i).getResourceProviders();
-                for (final AbstractWrappedResourceProvider rp : rps) {
+                final ProviderHandler[] rps = list.get(i).getResourceProviders();
+                for (final ProviderHandler rp : rps) {
 
                     final Resource resource = rp.getResource(ctx, resourceResolver, fullPath);
                     if (resource != null) {
@@ -346,8 +325,8 @@ public class ResourceProviderEntry imple
     }
 
     Resource getResourceFromProviders(final ResourceResolverContext ctx, final ResourceResolver
resourceResolver, final String fullPath) {
-        final AbstractWrappedResourceProvider[] rps = getResourceProviders();
-        for (final AbstractWrappedResourceProvider rp : rps) {
+        final ProviderHandler[] rps = getResourceProviders();
+        for (final ProviderHandler rp : rps) {
             final Resource resource = rp.getResource(ctx, resourceResolver, fullPath);
             if (resource != null) {
                 nreal++;
@@ -420,7 +399,7 @@ public class ResourceProviderEntry imple
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see java.util.AbstractMap#toString()
      */
     @Override

Copied: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java
(from r1345530, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProviderFactory.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java?p2=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java&p1=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProviderFactory.java&r1=1345530&r2=1345668&rev=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProviderFactory.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java
Sun Jun  3 13:17:21 2012
@@ -27,14 +27,14 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceProviderFactory;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
+ * The resource provider factory handler handles access to
+ * resource provider factories.
  */
-public class WrappedResourceProviderFactory extends AbstractWrappedResourceProvider {
+public class ResourceProviderFactoryHandler extends ProviderHandler {
 
     /** The logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -63,10 +63,11 @@ public class WrappedResourceProviderFact
     private final ResourceProviderFactory resourceProviderFactory;
 
     /**
-     *
+     * Create a new handler
      */
-    public WrappedResourceProviderFactory(final ResourceProviderFactory factory, final Map<String,
Object> properties) {
-        super(properties, "f-" + String.valueOf(properties.get(Constants.SERVICE_ID)));
+    public ResourceProviderFactoryHandler(final ResourceProviderFactory factory,
+                                          final Map<String, Object> properties) {
+        super(properties);
         this.resourceProviderFactory = factory;
     }
 
@@ -77,7 +78,7 @@ public class WrappedResourceProviderFact
      * @return A resource provider or <code>null</code>
      */
     private ResourceProvider getResourceProvider(final ResourceResolverContext ctx) {
-        ResourceProvider rp = ctx.getFactoryResourceProvider(this.getKey());
+        ResourceProvider rp = ctx.getFactoryResourceProvider(this.getServiceId());
         if ( rp == null ) {
             try {
                 rp = this.login(ctx);
@@ -88,7 +89,7 @@ public class WrappedResourceProviderFact
                 logger.debug("Unable to login to " + this.getName(), le);
             }
             if ( rp == null ) {
-                ctx.addFactoryResourceProvider(this.getKey(), NULL_PROVIDER);
+                ctx.addFactoryResourceProvider(this.getServiceId(), NULL_PROVIDER);
             }
         } else if ( rp == NULL_PROVIDER ) {
             rp = null;
@@ -133,8 +134,8 @@ public class WrappedResourceProviderFact
      */
     @Override
     public boolean equals(final Object obj) {
-        if ( obj instanceof WrappedResourceProviderFactory ) {
-            return resourceProviderFactory.equals(((WrappedResourceProviderFactory) obj).resourceProviderFactory);
+        if ( obj instanceof ResourceProviderFactoryHandler ) {
+            return resourceProviderFactory.equals(((ResourceProviderFactoryHandler) obj).resourceProviderFactory);
         } else if ( obj instanceof ResourceProviderFactory) {
             return resourceProviderFactory.equals(obj);
         }
@@ -161,18 +162,7 @@ public class WrappedResourceProviderFact
         } else {
             rp = this.resourceProviderFactory.getResourceProvider(ctx.getAuthenticationInfo());
         }
-        ctx.addFactoryResourceProvider(this.getKey(), rp);
+        ctx.addFactoryResourceProvider(this.getServiceId(), rp);
         return rp;
     }
-
-    @Override
-    public String getName() {
-        final StringBuilder snBuilder = new StringBuilder(64);
-        snBuilder.append('{');
-        snBuilder.append(this.resourceProviderFactory.toString());
-        snBuilder.append('/');
-        snBuilder.append(this.getProperties().get(Constants.SERVICE_ID));
-        snBuilder.append('}');
-        return snBuilder.toString();
-    }
 }

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderFactoryHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderHandler.java
(from r1345530, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProvider.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderHandler.java?p2=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderHandler.java&p1=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProvider.java&r1=1345530&r2=1345668&rev=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProvider.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderHandler.java
Sun Jun  3 13:17:21 2012
@@ -23,20 +23,22 @@ import java.util.Map;
 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.Constants;
 
 /**
- *
+ * The resource provider handler handles access to
+ * resource providers.
  */
-public class WrappedResourceProvider extends AbstractWrappedResourceProvider {
+public class ResourceProviderHandler extends ProviderHandler {
 
+    /** The handled resource provider.*/
     private final ResourceProvider resourceProvider;
 
     /**
-     *
+     * Create a new handler.
      */
-    public WrappedResourceProvider(final ResourceProvider resourceProvider, final Map<String,
Object> properties) {
-        super(properties, "p-" + String.valueOf(properties.get(Constants.SERVICE_ID)));
+    public ResourceProviderHandler(final ResourceProvider resourceProvider,
+                                   final Map<String, Object> properties) {
+        super(properties);
         this.resourceProvider = resourceProvider;
     }
 
@@ -69,8 +71,8 @@ public class WrappedResourceProvider ext
      */
     @Override
     public boolean equals(final Object obj) {
-        if ( obj instanceof WrappedResourceProvider ) {
-            return resourceProvider.equals(((WrappedResourceProvider) obj).resourceProvider);
+        if ( obj instanceof ResourceProviderHandler ) {
+            return resourceProvider.equals(((ResourceProviderHandler) obj).resourceProvider);
         } else if ( obj instanceof ResourceProvider) {
             return resourceProvider.equals(obj);
         }
@@ -86,15 +88,4 @@ public class WrappedResourceProvider ext
     public String toString() {
         return resourceProvider.toString();
     }
-
-    @Override
-    public String getName() {
-        final StringBuilder snBuilder = new StringBuilder(64);
-        snBuilder.append('{');
-        snBuilder.append(this.resourceProvider.toString());
-        snBuilder.append('/');
-        snBuilder.append(this.getProperties().get(Constants.SERVICE_ID));
-        snBuilder.append('}');
-        return snBuilder.toString();
-    }
 }

Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java?rev=1345668&r1=1345667&r2=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
Sun Jun  3 13:17:21 2012
@@ -33,7 +33,7 @@ import org.apache.sling.api.resource.Res
 public class ResourceResolverContext {
 
     /** A map of all used providers created by a factory. */
-    private final Map<String, ResourceProvider> providers = new HashMap<String,
ResourceProvider>();
+    private final Map<Long, ResourceProvider> providers = new HashMap<Long, ResourceProvider>();
 
     /** A set of all dynamic providers (for closing them later on) */
     private final Set<DynamicResourceProvider> dynamicProviders = new HashSet<DynamicResourceProvider>();
@@ -73,7 +73,7 @@ public class ResourceResolverContext {
      * @param key      The unique key of the provider
      * @param provider The provider.
      */
-    public void addFactoryResourceProvider(final String key, final ResourceProvider provider)
{
+    public void addFactoryResourceProvider(final Long key, final ResourceProvider provider)
{
         this.providers.put(key, provider);
         if (provider instanceof DynamicResourceProvider) {
             this.dynamicProviders.add((DynamicResourceProvider) provider);
@@ -85,7 +85,7 @@ public class ResourceResolverContext {
      * @param key The unique key of a provider
      * @return The resource provider or <code>null</code>
      */
-    public ResourceProvider getFactoryResourceProvider(final String key) {
+    public ResourceProvider getFactoryResourceProvider(final Long key) {
         return this.providers.get(key);
     }
 

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RootResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RootResourceProviderEntry.java?rev=1345668&r1=1345667&r2=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RootResourceProviderEntry.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RootResourceProviderEntry.java
Sun Jun  3 13:17:21 2012
@@ -59,7 +59,7 @@ public class RootResourceProviderEntry e
     private EventAdmin eventAdmin;
 
     /** Array of required factories. */
-    private WrappedResourceProviderFactory[] requiredFactories = new WrappedResourceProviderFactory[0];
+    private ResourceProviderFactoryHandler[] requiredFactories = new ResourceProviderFactoryHandler[0];
 
     /** All adaptable resource providers. */
     private final SortedProviderList<Adaptable> adaptableProviders = new SortedProviderList<Adaptable>(Adaptable.class);
@@ -87,8 +87,8 @@ public class RootResourceProviderEntry e
      */
     public void loginToRequiredFactories(final ResourceResolverContext ctx) throws LoginException
{
         try {
-            final WrappedResourceProviderFactory[] factories = this.requiredFactories;
-            for (final WrappedResourceProviderFactory wrapper : factories) {
+            final ResourceProviderFactoryHandler[] factories = this.requiredFactories;
+            for (final ResourceProviderFactoryHandler wrapper : factories) {
                 wrapper.login(ctx);
             }
         } catch (final LoginException le) {
@@ -282,7 +282,7 @@ public class RootResourceProviderEntry e
      * Bind a resource provider.
      */
     public void bindResourceProvider(final ResourceProvider provider, final Map<String,
Object> props) {
-        this.bindWrapper(new WrappedResourceProvider(provider, props));
+        this.bindWrapper(new ResourceProviderHandler(provider, props));
         if ( provider instanceof Adaptable ) {
             this.adaptableProviders.add((Adaptable)provider);
         }
@@ -298,7 +298,7 @@ public class RootResourceProviderEntry e
      * Unbind a resource provider.
      */
     public void unbindResourceProvider(final ResourceProvider provider, final Map<String,
Object> props) {
-        this.unbindWrapper(new WrappedResourceProvider(provider, props));
+        this.unbindWrapper(new ResourceProviderHandler(provider, props));
         if ( provider instanceof Adaptable ) {
             this.adaptableProviders.remove((Adaptable)provider);
         }
@@ -314,7 +314,7 @@ public class RootResourceProviderEntry e
      * Bind a resource provider factory.
      */
     public void bindResourceProviderFactory(final ResourceProviderFactory factory, final
Map<String, Object> props) {
-        final WrappedResourceProviderFactory wrapper = new WrappedResourceProviderFactory(factory,
props);
+        final ResourceProviderFactoryHandler wrapper = new ResourceProviderFactoryHandler(factory,
props);
 
         this.bindWrapper(wrapper);
         this.adaptableProviders.add(wrapper);
@@ -324,10 +324,10 @@ public class RootResourceProviderEntry e
         final boolean required = PropertiesUtil.toBoolean(props.get(ResourceProviderFactory.PROPERTY_REQUIRED),
false);
         if (required) {
             synchronized (this) {
-                final List<WrappedResourceProviderFactory> factories = new LinkedList<WrappedResourceProviderFactory>();
+                final List<ResourceProviderFactoryHandler> factories = new LinkedList<ResourceProviderFactoryHandler>();
                 factories.addAll(Arrays.asList(this.requiredFactories));
                 factories.add(wrapper);
-                this.requiredFactories = factories.toArray(new WrappedResourceProviderFactory[factories.size()]);
+                this.requiredFactories = factories.toArray(new ResourceProviderFactoryHandler[factories.size()]);
             }
         }
     }
@@ -336,9 +336,9 @@ public class RootResourceProviderEntry e
      * Unbind a resource provider factory
      */
     public void unbindResourceProviderFactory(final ResourceProviderFactory factory, final
Map<String, Object> props) {
-        final WrappedResourceProviderFactory wrapper = new WrappedResourceProviderFactory(factory,
props);
+        final ResourceProviderFactoryHandler wrapper = new ResourceProviderFactoryHandler(factory,
props);
 
-        this.unbindWrapper(new WrappedResourceProvider(null, props));
+        this.unbindWrapper(new ResourceProviderHandler(null, props));
         this.adaptableProviders.remove(wrapper);
         this.queriableProviders.remove(wrapper);
         this.attributableProviders.remove(wrapper);
@@ -346,10 +346,10 @@ public class RootResourceProviderEntry e
         final boolean required = PropertiesUtil.toBoolean(props.get(ResourceProviderFactory.PROPERTY_REQUIRED),
false);
         if (required) {
             synchronized (this) {
-                final List<WrappedResourceProviderFactory> factories = new LinkedList<WrappedResourceProviderFactory>();
+                final List<ResourceProviderFactoryHandler> factories = new LinkedList<ResourceProviderFactoryHandler>();
                 factories.addAll(Arrays.asList(this.requiredFactories));
                 factories.remove(wrapper);
-                this.requiredFactories = factories.toArray(new WrappedResourceProviderFactory[factories.size()]);
+                this.requiredFactories = factories.toArray(new ResourceProviderFactoryHandler[factories.size()]);
             }
         }
     }
@@ -357,7 +357,7 @@ public class RootResourceProviderEntry e
     /**
      * Bind a resource provider wrapper
      */
-    private void bindWrapper(final AbstractWrappedResourceProvider provider) {
+    private void bindWrapper(final ProviderHandler provider) {
         // this is just used for debug logging
         final String debugServiceName = getDebugServiceName(provider);
 
@@ -395,7 +395,7 @@ public class RootResourceProviderEntry e
     /**
      * Unbind a resource provider wrapper
      */
-    private void unbindWrapper(final AbstractWrappedResourceProvider provider) {
+    private void unbindWrapper(final ProviderHandler provider) {
         // this is just used for debug logging
         final String debugServiceName = getDebugServiceName(provider);
 
@@ -428,7 +428,7 @@ public class RootResourceProviderEntry e
         logger.debug("unbindResourceProvider: Unbound {}", debugServiceName);
     }
 
-    private String getDebugServiceName(final AbstractWrappedResourceProvider provider) {
+    private String getDebugServiceName(final ProviderHandler provider) {
         if (logger.isDebugEnabled()) {
             return provider.getName();
         }

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java?rev=1345668&r1=1345667&r2=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java
Sun Jun  3 13:17:21 2012
@@ -55,9 +55,9 @@ public class SortedProviderList<T> {
                 if ( this.index < list.length ) {
                     result = list[this.index];
                     this.index++;
-                    if ( result instanceof WrappedResourceProviderFactory ) {
+                    if ( result instanceof ResourceProviderFactoryHandler ) {
                         try {
-                            result = ((WrappedResourceProviderFactory)result).login(ctx);
+                            result = ((ResourceProviderFactoryHandler)result).login(ctx);
                             if ( !genericClass.isAssignableFrom(result.getClass())) {
                                 result = null;
                             }
@@ -112,7 +112,7 @@ public class SortedProviderList<T> {
         }
     }
 
-    public void add(final WrappedResourceProviderFactory factory) {
+    public void add(final ResourceProviderFactoryHandler factory) {
         synchronized ( this ) {
             final List<Object> list = new LinkedList<Object>();
             list.addAll(Arrays.asList(this.sortedList));
@@ -130,7 +130,7 @@ public class SortedProviderList<T> {
         }
     }
 
-    public void remove(final WrappedResourceProviderFactory factory) {
+    public void remove(final ResourceProviderFactoryHandler factory) {
         synchronized ( this ) {
             final List<Object> list = new LinkedList<Object>();
             list.addAll(Arrays.asList(this.sortedList));

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java?rev=1345668&r1=1345667&r2=1345668&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntryTest.java
Sun Jun  3 13:17:21 2012
@@ -48,7 +48,7 @@ public class ResourceProviderEntryTest e
         rootProvider = new TestResourceProvider("/");
         final Map<String, Object> props = new HashMap<String, Object>();
         props.put(Constants.SERVICE_ID, "the.root");
-        root = new ResourceProviderEntry("/", new WrappedResourceProvider[]{ new WrappedResourceProvider(rootProvider,
props)});
+        root = new ResourceProviderEntry("/", new ResourceProviderHandler[]{ new ResourceProviderHandler(rootProvider,
props)});
     }
 
     @Override
@@ -71,7 +71,7 @@ public class ResourceProviderEntryTest e
         ResourceProvider first = new TestResourceProvider(firstPath);
         final Map<String, Object> firstProps = new HashMap<String, Object>();
         firstProps.put(Constants.SERVICE_ID, "first");
-        root.addResourceProvider(firstPath, new WrappedResourceProvider(first, firstProps));
+        root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
 
 
         assertEquals(root, root.getResource(null, null, "/"));
@@ -100,9 +100,9 @@ public class ResourceProviderEntryTest e
         final Map<String, Object> thirdProps = new HashMap<String, Object>();
         thirdProps.put(Constants.SERVICE_ID, "third");
 
-        root.addResourceProvider(firstPath, new WrappedResourceProvider(first, firstProps));
-        root.addResourceProvider(secondPath, new WrappedResourceProvider(second, secondProps));
-        root.addResourceProvider(thirdPath, new WrappedResourceProvider(third, thirdProps));
+        root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+        root.addResourceProvider(secondPath, new ResourceProviderHandler(second, secondProps));
+        root.addResourceProvider(thirdPath, new ResourceProviderHandler(third, thirdProps));
 
 
         assertEquals(rootProvider, root.getResource(null, null, "/"));
@@ -132,9 +132,9 @@ public class ResourceProviderEntryTest e
         final Map<String, Object> thirdProps = new HashMap<String, Object>();
         thirdProps.put(Constants.SERVICE_ID, "third");
 
-        root.addResourceProvider(firstPath, new WrappedResourceProvider(first, firstProps));
-        root.addResourceProvider(secondPath, new WrappedResourceProvider(second, secondProps));
-        root.addResourceProvider(thirdPath, new WrappedResourceProvider(third, thirdProps));
+        root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+        root.addResourceProvider(secondPath, new ResourceProviderHandler(second, secondProps));
+        root.addResourceProvider(thirdPath, new ResourceProviderHandler(third, thirdProps));
 
         assertEquals(rootProvider, root.getResource(null, null, "/"));
         assertEquals(first, root.getResource(null, null, "/rootel"));
@@ -163,22 +163,22 @@ public class ResourceProviderEntryTest e
         final Map<String, Object> thirdProps = new HashMap<String, Object>();
         thirdProps.put(Constants.SERVICE_ID, "third");
 
-        root.addResourceProvider(firstPath, new WrappedResourceProvider(first, firstProps));
-        root.addResourceProvider(secondPath, new WrappedResourceProvider(second, secondProps));
-        root.addResourceProvider(thirdPath, new WrappedResourceProvider(third, thirdProps));
+        root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
+        root.addResourceProvider(secondPath, new ResourceProviderHandler(second, secondProps));
+        root.addResourceProvider(thirdPath, new ResourceProviderHandler(third, thirdProps));
 
         assertEquals(rootProvider, root.getResource(null, null, "/"));
         assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
         assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
 
-        root.removeResourceProvider(firstPath, new WrappedResourceProvider(first, firstProps));
+        root.removeResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
 
         assertEquals(rootProvider, root.getResource(null, null, "/"));
         assertEquals(rootProvider, root.getResource(null, null, "/rootel/sddsf/sdfsdf/html.js"));
         assertEquals(rootProvider, root.getResource(null, null, "/rootel/html.js"));
         assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
 
-        root.addResourceProvider(firstPath, new WrappedResourceProvider(first, firstProps));
+        root.addResourceProvider(firstPath, new ResourceProviderHandler(first, firstProps));
 
         assertEquals(rootProvider, root.getResource(null, null, "/"));
         assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
@@ -191,8 +191,8 @@ public class ResourceProviderEntryTest e
 
     protected void assertEquals(ResourceProviderEntry resProviderEntry,
             Resource res) {
-        AbstractWrappedResourceProvider[] resourceProviders = resProviderEntry.getResourceProviders();
-        for ( AbstractWrappedResourceProvider rp : resourceProviders ) {
+        ProviderHandler[] resourceProviders = resProviderEntry.getResourceProviders();
+        for ( ProviderHandler rp : resourceProviders ) {
             if ( rp.equals(res.getResourceResolver())) {
                 return;
             }



Mime
View raw message