incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1345278 - in /sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl: ./ helper/
Date Fri, 01 Jun 2012 17:17:31 GMT
Author: cziegeler
Date: Fri Jun  1 17:17:30 2012
New Revision: 1345278

URL: http://svn.apache.org/viewvc?rev=1345278&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/ResourceDecoratorTracker.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RedirectResource.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

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java?rev=1345278&r1=1345277&r2=1345278&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java
Fri Jun  1 17:17:30 2012
@@ -68,10 +68,6 @@ public class ResourceDecoratorTracker {
         return result;
     }
 
-    public ResourceDecorator[] getResourceDecorators() {
-        return this.resourceDecoratorsArray;
-    }
-
     protected void bindResourceDecorator(final ResourceDecorator decorator,
             final Map<String, Object> props) {
         synchronized (this.resourceDecorators) {
@@ -102,7 +98,7 @@ public class ResourceDecoratorTracker {
      * Updates the ResourceDecorators array, this method is not thread safe and
      * should only be called from a synchronized block.
      */
-    protected void updateResourceDecoratorsArray() {
+    private void updateResourceDecoratorsArray() {
         final ResourceDecorator[] decorators;
         if (this.resourceDecorators.size() > 0) {
             decorators = new ResourceDecorator[this.resourceDecorators.size()];
@@ -135,7 +131,7 @@ public class ResourceDecoratorTracker {
             this.decorator = d;
         }
 
-        public int compareTo(ResourceDecoratorEntry o) {
+        public int compareTo(final ResourceDecoratorEntry o) {
             return comparable.compareTo(o.comparable);
         }
     }

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java?rev=1345278&r1=1345277&r2=1345278&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
Fri Jun  1 17:17:30 2012
@@ -26,7 +26,9 @@ import java.util.regex.Pattern;
 
 import org.apache.commons.collections.BidiMap;
 import org.apache.commons.collections.bidimap.TreeBidiMap;
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.PropertyUnbounded;
@@ -156,7 +158,7 @@ public class ResourceResolverFactoryImpl
     // the root location of the /etc/map entries
     private String mapRoot;
 
-    private final RootResourceProviderEntry rootProviderEntry;
+    private final RootResourceProviderEntry rootProviderEntry = new RootResourceProviderEntry();
 
     // whether to mangle paths with namespaces or not
     private boolean mangleNamespacePrefixes;
@@ -164,14 +166,8 @@ public class ResourceResolverFactoryImpl
     /** Event admin. */
     private EventAdmin eventAdmin;
 
-    public ResourceResolverFactoryImpl() {
-        this.rootProviderEntry = new RootResourceProviderEntry();
-
-    }
-
-    public ResourceDecoratorTracker getResourceDecoratorTracker() {
-        return this.resourceDecoratorTracker;
-    }
+    /** The web console plugin. */
+    private ResourceResolverWebConsolePlugin plugin;
 
     // ---------- Resource Resolver Factory ------------------------------------
 
@@ -189,12 +185,18 @@ public class ResourceResolverFactoryImpl
         return getResourceResolverInternal(authenticationInfo, false);
     }
 
+    // ---------- Implementation helpers --------------------------------------
+
     /**
-     * Create a new ResourceResolver wrapping a Session object. Carries map of
-     * authentication info in order to create a new resolver as needed.
-     */
-    private ResourceResolver getResourceResolverInternal(final Map<String, Object>
authenticationInfo, final boolean isAdmin)
-                    throws LoginException {
+     * Create a new ResourceResolver
+     * @param authenticationInfo The authentication map
+     * @param isAdmin is an administrative resolver requested?
+     * @return A resource resolver
+     * @throws LoginException if login to any of the required resource providers fails.
+     */
+    private ResourceResolver getResourceResolverInternal(final Map<String, Object>
authenticationInfo,
+                    final boolean isAdmin)
+    throws LoginException {
         // create context
         final ResourceResolverContext ctx = new ResourceResolverContext(isAdmin, authenticationInfo);
 
@@ -204,7 +206,12 @@ public class ResourceResolverFactoryImpl
         return new ResourceResolverImpl(this, ctx);
     }
 
-    // ---------- Implementation helpers --------------------------------------
+    /**
+     * Get the resource decorator tracker.
+     */
+    public ResourceDecoratorTracker getResourceDecoratorTracker() {
+        return this.resourceDecoratorTracker;
+    }
 
     /**
      * This method is called from {@link MapEntries}
@@ -251,6 +258,7 @@ public class ResourceResolverFactoryImpl
     // ---------- SCR Integration ---------------------------------------------
 
     /** Activates this component, called by SCR before registering as a service */
+    @Activate
     protected void activate(final ComponentContext componentContext) {
         this.rootProviderEntry.setEventAdmin(this.eventAdmin);
         final Dictionary<?, ?> properties = componentContext.getProperties();
@@ -322,10 +330,11 @@ public class ResourceResolverFactoryImpl
         }
     }
 
-    private ResourceResolverWebConsolePlugin plugin;
-
-    /** Deativates this component, called by SCR to take out of service */
-    protected void deactivate(final ComponentContext componentContext) {
+    /**
+     * Deativates this component (called by SCR to take out of service)
+     */
+    @Deactivate
+    protected void deactivate() {
         this.rootProviderEntry.setEventAdmin(null);
         if (plugin != null) {
             plugin.dispose();
@@ -367,10 +376,16 @@ public class ResourceResolverFactoryImpl
         this.rootProviderEntry.unbindResourceProviderFactory(provider, props);
     }
 
+    /**
+     * Bind a resource decorator.
+     */
     protected void bindResourceDecorator(final ResourceDecorator decorator, final Map<String,
Object> props) {
         this.resourceDecoratorTracker.bindResourceDecorator(decorator, props);
     }
 
+    /**
+     * Unbind a resource decorator.
+     */
     protected void unbindResourceDecorator(final ResourceDecorator decorator, final Map<String,
Object> props) {
         this.resourceDecoratorTracker.unbindResourceDecorator(decorator, props);
     }

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1345278&r1=1345277&r2=1345278&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Fri Jun  1 17:17:30 2012
@@ -643,9 +643,13 @@ public class ResourceResolverImpl extend
         if ( session != null ) {
             return session.getUserID();
         }
-        final Object value = this.getAttribute(ResourceResolverFactory.USER);
-        if ( value != null ) {
-            return value.toString();
+        final Object impUser = this.getAttribute(ResourceResolverFactory.USER_IMPERSONATION);
+        if ( impUser != null ) {
+            return impUser.toString();
+        }
+        final Object user = this.getAttribute(ResourceResolverFactory.USER);
+        if ( user != null ) {
+            return user.toString();
         }
         return null;
     }

Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RedirectResource.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RedirectResource.java?rev=1345278&r1=1345277&r2=1345278&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RedirectResource.java
(original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RedirectResource.java
Fri Jun  1 17:17:30 2012
@@ -45,7 +45,7 @@ public final class RedirectResource exte
             final String target, final int status) {
         super(resolver, path, RT_SLING_REDIRECT);
 
-        HashMap<String, Object> props = new HashMap<String, Object>();
+        final Map<String, Object> props = new HashMap<String, Object>();
         props.put(PROP_SLING_TARGET, target);
         props.put(PROP_SLING_STATUS, status);
         this.values = Collections.unmodifiableMap(props);
@@ -55,7 +55,7 @@ public final class RedirectResource exte
      * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class)
      */
     @SuppressWarnings("unchecked")
-    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+    public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
         if (type == ValueMap.class) {
             return (AdapterType) new ValueMapDecorator(values);
         } else if (type == Map.class) {

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=1345278&r1=1345277&r2=1345278&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
Fri Jun  1 17:17:30 2012
@@ -20,7 +20,6 @@ package org.apache.sling.resourceresolve
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -28,6 +27,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Set;
 
 import org.apache.sling.api.SlingConstants;
@@ -120,15 +120,58 @@ public class RootResourceProviderEntry e
     public Iterator<Resource> findResources(final ResourceResolverContext ctx,
                     final ResourceResolver resolver, final String query, final String language)
{
         final Iterator<QueriableResourceProvider> i = this.queriableProviders.getProviders(ctx);
-        while ( i.hasNext() ) {
-            final QueriableResourceProvider adap = i.next();
-            final Iterator<Resource> iter = adap.findResources(resolver, query, language);
-            if ( iter != null ) {
-                // TODO
+        return new Iterator<Resource>() {
+
+            private Resource nextObject = this.seek();
+
+            private Iterator<Resource> nextResourceIter;
+
+            private Resource seek() {
+                Resource result = null;
+                if ( nextResourceIter == null || !nextResourceIter.hasNext() ) {
+                    nextResourceIter = null;
+                    while ( i.hasNext() && nextResourceIter == null ) {
+                        final QueriableResourceProvider adap = i.next();
+                        nextResourceIter = adap.findResources(resolver, query, language);
+                    }
+                }
+                if ( nextResourceIter != null ) {
+                    while ( nextResourceIter.hasNext() && result == null ) {
+                        result = nextResourceIter.next();
+                    }
+                    if ( result == null ) {
+                        result = seek();
+                    }
+                }
+                return result;
             }
-        }
-        // TODO
-        return Collections.EMPTY_LIST.iterator();
+
+            /**
+             * @see java.util.Iterator#hasNext()
+             */
+            public boolean hasNext() {
+                return this.nextObject != null;
+            }
+
+            /**
+             * @see java.util.Iterator#next()
+             */
+            public Resource next() {
+                if ( this.nextObject == null ) {
+                    throw new NoSuchElementException();
+                }
+                final Resource result = this.nextObject;
+                this.nextObject = this.seek();
+                return result;
+            }
+
+            /**
+             * @see java.util.Iterator#remove()
+             */
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+        };
     }
 
     /**
@@ -137,15 +180,58 @@ public class RootResourceProviderEntry e
      */
     public Iterator<Map<String, Object>> queryResources(final ResourceResolverContext
ctx, final String query, final String language) {
         final Iterator<QueriableResourceProvider> i = this.queriableProviders.getProviders(ctx);
-        while ( i.hasNext() ) {
-            final QueriableResourceProvider adap = i.next();
-            final Iterator<Map<String, Object>> iter = adap.queryResources(query,
language);
-            if ( iter != null ) {
-                // TODO
+        return new Iterator<Map<String, Object>>() {
+
+            private Map<String, Object> nextObject = this.seek();
+
+            private Iterator<Map<String, Object>> nextResourceIter;
+
+            private Map<String, Object> seek() {
+                Map<String, Object> result = null;
+                if ( nextResourceIter == null || !nextResourceIter.hasNext() ) {
+                    nextResourceIter = null;
+                    while ( i.hasNext() && nextResourceIter == null ) {
+                        final QueriableResourceProvider adap = i.next();
+                        nextResourceIter = adap.queryResources(query, language);
+                    }
+                }
+                if ( nextResourceIter != null ) {
+                    while ( nextResourceIter.hasNext() && result == null ) {
+                        result = nextResourceIter.next();
+                    }
+                    if ( result == null ) {
+                        result = seek();
+                    }
+                }
+                return result;
             }
-        }
-        // TODO
-        return Collections.EMPTY_LIST.iterator();
+
+            /**
+             * @see java.util.Iterator#hasNext()
+             */
+            public boolean hasNext() {
+                return this.nextObject != null;
+            }
+
+            /**
+             * @see java.util.Iterator#next()
+             */
+            public Map<String, Object> next() {
+                if ( this.nextObject == null ) {
+                    throw new NoSuchElementException();
+                }
+                final Map<String, Object> result = this.nextObject;
+                this.nextObject = this.seek();
+                return result;
+            }
+
+            /**
+             * @see java.util.Iterator#remove()
+             */
+            public void remove() {
+                throw new UnsupportedOperationException();
+            }
+        };
     }
 
     private static final String FORBIDDEN_ATTRIBUTE = ResourceResolverFactory.PASSWORD;
@@ -279,6 +365,7 @@ public class RootResourceProviderEntry e
         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
         if (roots != null && roots.length > 0) {
             final EventAdmin localEA = this.eventAdmin;
             for (String root : roots) {

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=1345278&r1=1345277&r2=1345278&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
Fri Jun  1 17:17:30 2012
@@ -22,10 +22,11 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import org.apache.sling.api.resource.LoginException;
 
-
+// TODO - Implement sorting
 public class SortedProviderList<T> {
 
     private final Class<T> genericClass;
@@ -85,6 +86,9 @@ public class SortedProviderList<T> {
              */
             @SuppressWarnings("unchecked")
             public T next() {
+                if ( this.nextObject == null ) {
+                    throw new NoSuchElementException();
+                }
                 final Object result = this.nextObject;
                 this.nextObject = seek();
                 return (T)result;
@@ -118,12 +122,20 @@ public class SortedProviderList<T> {
     }
 
     public void remove(final T provider) {
-        // TODO Auto-generated method stub
-
+        synchronized ( this ) {
+            final List<Object> list = new LinkedList<Object>();
+            list.addAll(Arrays.asList(this.sortedList));
+            list.remove(provider);
+            this.sortedList = list.toArray(new Object[list.size()]);
+        }
     }
 
-    public void remove(final WrappedResourceProviderFactory wrapper) {
-        // TODO Auto-generated method stub
-
+    public void remove(final WrappedResourceProviderFactory factory) {
+        synchronized ( this ) {
+            final List<Object> list = new LinkedList<Object>();
+            list.addAll(Arrays.asList(this.sortedList));
+            list.remove(factory);
+            this.sortedList = list.toArray(new Object[list.size()]);
+        }
     }
 }



Mime
View raw message