incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1345511 - /sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/
Date Sat, 02 Jun 2012 14:22:55 GMT
Author: cziegeler
Date: Sat Jun  2 14:22:54 2012
New Revision: 1345511

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

Modified:
    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/RootResourceProviderEntry.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/AbstractWrappedResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/AbstractWrappedResourceProvider.java?rev=1345511&r1=1345510&r2=1345511&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/AbstractWrappedResourceProvider.java
Sat Jun  2 14:22:54 2012
@@ -78,4 +78,9 @@ public abstract class AbstractWrappedRes
      * @see ResourceProvider#listChildren(Resource)
      */
     public abstract Iterator<Resource> listChildren(final ResourceResolverContext ctx,
final Resource parent);
+
+    /**
+     * Return a name of the resource provider/factory.
+     */
+    public abstract String getName();
 }

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=1345511&r1=1345510&r2=1345511&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
Sat Jun  2 14:22:54 2012
@@ -41,7 +41,6 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.osgi.framework.Constants;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.slf4j.Logger;
@@ -360,16 +359,17 @@ public class RootResourceProviderEntry e
      */
     private void bindWrapper(final AbstractWrappedResourceProvider provider) {
         // this is just used for debug logging
-        final String debugServiceName = getDebugServiceName(provider, provider.getProperties());
+        final String debugServiceName = getDebugServiceName(provider);
 
         logger.debug("bindResourceProvider: Binding {}", debugServiceName);
 
         final String[] roots = PropertiesUtil.toStringArray(provider.getProperties().get(ResourceProvider.ROOTS));
-        // TODO - log if no root or only empty roots are configured
+        boolean foundRoot = false;
         if (roots != null && roots.length > 0) {
             final EventAdmin localEA = this.eventAdmin;
             for (String root : roots) {
                 if (root != null && root.length() > 0) {
+                    foundRoot = true;
                     // cut off trailing slash
                     if (root.endsWith("/") && root.length() > 1) {
                         root = root.substring(0, root.length() - 1);
@@ -386,7 +386,9 @@ public class RootResourceProviderEntry e
                 }
             }
         }
-
+        if ( !foundRoot ) {
+            logger.info("Ignoring ResourceProvider(Factory) {} : no configured roots.", provider.getName());
+        }
         logger.debug("bindResourceProvider: Bound {}", debugServiceName);
     }
 
@@ -395,7 +397,7 @@ public class RootResourceProviderEntry e
      */
     private void unbindWrapper(final AbstractWrappedResourceProvider provider) {
         // this is just used for debug logging
-        final String debugServiceName = getDebugServiceName(provider, provider.getProperties());
+        final String debugServiceName = getDebugServiceName(provider);
 
         logger.debug("unbindResourceProvider: Unbinding {}", debugServiceName);
 
@@ -426,15 +428,9 @@ public class RootResourceProviderEntry e
         logger.debug("unbindResourceProvider: Unbound {}", debugServiceName);
     }
 
-    private String getDebugServiceName(final AbstractWrappedResourceProvider provider, final
Map<String, Object> props) {
+    private String getDebugServiceName(final AbstractWrappedResourceProvider provider) {
         if (logger.isDebugEnabled()) {
-            final StringBuilder snBuilder = new StringBuilder(64);
-            snBuilder.append('{');
-            snBuilder.append(provider.toString());
-            snBuilder.append('/');
-            snBuilder.append(props.get(Constants.SERVICE_ID));
-            snBuilder.append('}');
-            return snBuilder.toString();
+            return provider.getName();
         }
 
         return null;

Modified: 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/WrappedResourceProvider.java?rev=1345511&r1=1345510&r2=1345511&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/WrappedResourceProvider.java
Sat Jun  2 14:22:54 2012
@@ -86,4 +86,15 @@ 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();
+    }
 }

Modified: 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/WrappedResourceProviderFactory.java?rev=1345511&r1=1345510&r2=1345511&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/WrappedResourceProviderFactory.java
Sat Jun  2 14:22:54 2012
@@ -28,12 +28,17 @@ import org.apache.sling.api.resource.Res
 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;
 
 /**
  *
  */
 public class WrappedResourceProviderFactory extends AbstractWrappedResourceProvider {
 
+    /** The logger. */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
     /**
      * A do nothing resource provider.
      */
@@ -65,18 +70,28 @@ public class WrappedResourceProviderFact
         this.resourceProviderFactory = factory;
     }
 
+    /**
+     * Get a resource provider
+     * If the user can't be authenticated <code>null</code> is returned.
+     * @param ctx The user context.
+     * @return A resource provider or <code>null</code>
+     */
     private ResourceProvider getResourceProvider(final ResourceResolverContext ctx) {
         ResourceProvider rp = ctx.getFactoryResourceProvider(this.getKey());
         if ( rp == null ) {
             try {
                 rp = this.login(ctx);
             } catch (final LoginException le ) {
-                // SHOULD WE LOG? (TODO)
+                // for now we log to debug, as a failed login for not required resource provider
+                // is expected
+                // TODO - we could introduce a service property controlling this?
+                logger.debug("Unable to login to " + this.getName(), le);
             }
             if ( rp == null ) {
-                rp = NULL_PROVIDER;
-                ctx.addFactoryResourceProvider(this.getKey(), rp);
+                ctx.addFactoryResourceProvider(this.getKey(), NULL_PROVIDER);
             }
+        } else if ( rp == NULL_PROVIDER ) {
+            rp = null;
         }
         return rp;
     }
@@ -85,14 +100,22 @@ public class WrappedResourceProviderFact
      * @see ResourceProvider#getResource(ResourceResolver, String)
      */
     public Resource getResource(final ResourceResolverContext ctx, final ResourceResolver
resourceResolver, final String path) {
-        return this.getResourceProvider(ctx).getResource(resourceResolver, path);
+        final ResourceProvider rp = this.getResourceProvider(ctx);
+        if ( rp != null ) {
+            return rp.getResource(resourceResolver, path);
+        }
+        return null;
     }
 
     /**
      * @see ResourceProvider#listChildren(Resource)
      */
     public Iterator<Resource> listChildren(final ResourceResolverContext ctx, final
Resource parent) {
-        return this.getResourceProvider(ctx).listChildren(parent);
+        final ResourceProvider rp = this.getResourceProvider(ctx);
+        if ( rp != null ) {
+            return rp.listChildren(parent);
+        }
+        return null;
     }
 
     /**
@@ -141,4 +164,15 @@ public class WrappedResourceProviderFact
         ctx.addFactoryResourceProvider(this.getKey(), 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();
+    }
 }



Mime
View raw message