You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/02/29 17:40:43 UTC

svn commit: r632379 - in /incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal: ./ helper/ helper/bundle/ helper/jcr/

Author: fmeschbe
Date: Fri Feb 29 08:40:30 2008
New Revision: 632379

URL: http://svn.apache.org/viewvc?rev=632379&view=rev
Log:
SLING-262 Fully implement the ResourceProvider.listChildren() methods in the
JcrResourceProvider and BundleResourceProvider interfaces and implement the
ResourceResolver.listChidlren method based on the registered resource
providers. This also allows the removal of the now unused Descendable
interface.

Removed:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/Descendable.java
Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java Fri Feb 29 08:40:30 2008
@@ -19,10 +19,8 @@
 package org.apache.sling.jcr.resource.internal;
 
 import java.security.AccessControlException;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 import javax.jcr.RepositoryException;
@@ -40,7 +38,6 @@
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
-import org.apache.sling.jcr.resource.internal.helper.Descendable;
 import org.apache.sling.jcr.resource.internal.helper.Mapping;
 import org.apache.sling.jcr.resource.internal.helper.ResourcePathIterator;
 import org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator;
@@ -185,23 +182,7 @@
     }
 
     public Iterator<Resource> listChildren(Resource parent) {
-        if (parent instanceof Descendable) {
-            return ((Descendable) parent).listChildren();
-        }
-
-        try {
-            parent = getResource(parent.getPath());
-            if (parent instanceof Descendable) {
-                return ((Descendable) parent).listChildren();
-            }
-        } catch (SlingException se) {
-            log.warn("listChildren: Error trying to resolve parent resource "
-                + parent.getPath(), se);
-        }
-
-        // return an empty iterator if parent has no node
-        List<Resource> empty = Collections.emptyList();
-        return empty.iterator();
+        return rootProvider.listChildren(parent);
     }
 
     public Iterator<Resource> findResources(String query, String language)

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java Fri Feb 29 08:40:30 2008
@@ -19,13 +19,19 @@
 package org.apache.sling.jcr.resource.internal.helper;
 
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import org.apache.sling.api.SlingException;
 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.api.resource.SyntheticResource;
 
 /**
  * The <code>ResourceProviderEntry</code> class represents a node in the tree
@@ -57,7 +63,7 @@
     /**
      * Creates an instance of this class with the given path relative to the
      * parent resource provider entry, encapsulating the given ResourceProvider.
-     *
+     * 
      * @param path The relative path supported by the provider
      * @param provider The resource provider to encapsulate by this entry.
      */
@@ -69,7 +75,7 @@
      * 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 provider The resource provider to encapsulate by this entry.
      */
@@ -104,60 +110,91 @@
      * 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 be found.
-     * @throws org.apache.sling.api.SlingException if an error occurrs trying to access an existing
-     *             resource.
+     * @throws org.apache.sling.api.SlingException if an error occurrs trying to
+     *             access an existing resource.
      */
     public Resource getResource(ResourceResolver resourceResolver, String path) {
         return getResource(resourceResolver, path, path);
     }
 
-    /**
-     * 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.
-     * <p>
-     * This method implements the {@link #getResource(String)} method
-     * recursively calling itself on any child provide entries matching the
-     * path.
-     *
-     * @param path The path to the resource to return relative to the parent
-     *            resource provider entry, which called this method.
-     * @param fullPath The actual path to the resource as provided to the
-     *            {@link #getResource(String)} method.
-     * @return The resource for the path or <code>null</code> if no resource
-     *         can be found.
-     * @throws SlingException if an error occurrs trying to access an existing
-     *             resource.
-     */
-    private Resource getResource(ResourceResolver resourceResolver,
-            String path, String fullPath) {
-        if (path.equals(this.path)) {
-            return getResourceProvider().getResource(resourceResolver, fullPath);
-        } else if (path.startsWith(this.prefix)) {
-            if (entries != null) {
+    public Iterator<Resource> listChildren(final Resource resource) {
+        return new Iterator<Resource>() {
+            private final Iterator<ResourceProvider> providers;
 
-                // consider relative path for further checks
-                path = path.substring(this.prefix.length());
+            private Iterator<Resource> resources;
 
-                for (ResourceProviderEntry entry : entries) {
-                    Resource test = entry.getResource(resourceResolver, path,
-                        fullPath);
-                    if (test != null) {
-                        return test;
-                    }
+            private Resource nextResource;
+
+            private Map<String, Resource> delayed;
+
+            private Iterator<Resource> delayedIter;
+
+            {
+                String path = resource.getPath();
+                if (!path.endsWith("/")) {
+                    path += "/";
                 }
+
+                // 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
+                Set<ResourceProvider> providersSet = new LinkedHashSet<ResourceProvider>();
+                getResourceProviders(path, providersSet);
+                
+                providers = providersSet.iterator();
+                delayed = new HashMap<String, Resource>();
+                nextResource = seek();
             }
 
-            // no more specific provider, return mine
-            return getResourceProvider().getResource(resourceResolver, fullPath);
-        }
+            public boolean hasNext() {
+                return nextResource != null;
+            }
 
-        // no match for my prefix, return null
-        return null;
+            public Resource next() {
+                if (!hasNext()) {
+                    throw new NoSuchElementException();
+                }
+
+                Resource result = nextResource;
+                nextResource = seek();
+                return result;
+            }
+
+            public void remove() {
+                throw new UnsupportedOperationException("remove");
+            }
+
+            private Resource seek() {
+                for (;;) {
+                    while ((resources == null || !resources.hasNext())
+                        && providers.hasNext()) {
+                        ResourceProvider provider = providers.next();
+                        resources = provider.listChildren(resource);
+                    }
+
+                    if (resources != null && resources.hasNext()) {
+                        Resource res = resources.next();
+                        if (res instanceof SyntheticResource) {
+                            delayed.put(res.getPath(), res);
+                        } else {
+                            return res;
+                        }
+                    } else {
+                        break;
+                    }
+                }
+
+                if (delayedIter == null) {
+                    delayedIter = delayed.values().iterator();
+                }
+
+                return delayedIter.hasNext() ? delayedIter.next() : null;
+            }
+        };
     }
 
     public boolean addResourceProvider(String prefix, ResourceProvider provider) {
@@ -257,6 +294,90 @@
 
     public int compareTo(ResourceProviderEntry o) {
         return prefix.compareTo(o.prefix);
+    }
+
+    // ---------- internal -----------------------------------------------------
+
+    /**
+     * 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.
+     * <p>
+     * This method implements the {@link #getResource(String)} method
+     * recursively calling itself on any child provide entries matching the
+     * path.
+     * 
+     * @param path The path to the resource to return relative to the parent
+     *            resource provider entry, which called this method.
+     * @param fullPath The actual path to the resource as provided to the
+     *            {@link #getResource(String)} method.
+     * @return The resource for the path or <code>null</code> if no resource
+     *         can be found.
+     * @throws SlingException if an error occurrs trying to access an existing
+     *             resource.
+     */
+    private Resource getResource(ResourceResolver resourceResolver,
+            String path, String fullPath) {
+        if (path.equals(this.path)) {
+            return getResourceProvider().getResource(resourceResolver, fullPath);
+        } else if (path.startsWith(this.prefix)) {
+            if (entries != null) {
+
+                // consider relative path for further checks
+                path = path.substring(this.prefix.length());
+
+                for (ResourceProviderEntry entry : entries) {
+                    Resource test = entry.getResource(resourceResolver, path,
+                        fullPath);
+                    if (test != null) {
+                        return test;
+                    }
+                }
+            }
+
+            // no more specific provider, return mine
+            return getResourceProvider().getResource(resourceResolver, fullPath);
+        }
+
+        // no match for my prefix, return null
+        return null;
+    }
+
+    /**
+     * Returns all resource providers which provider resources whose prefix is
+     * the given path.
+     * 
+     * @param path The prefix path to match the resource provider roots against
+     * @param providers The set of already found resource providers to which
+     * any additional resource providers are added.
+     */
+    private void getResourceProviders(String path,
+            Set<ResourceProvider> providers) {
+        if (path.startsWith(this.prefix)) {
+
+            if (entries != null) {
+
+                // consider relative path for further checks
+                path = path.substring(this.prefix.length());
+
+                for (ResourceProviderEntry entry : entries) {
+                    if (path.length() == 0) {
+                        providers.add(entry.getResourceProvider());
+                    } else {
+                        entry.getResourceProviders(path, providers);
+                    }
+                }
+            }
+
+            // add myself to the list
+            providers.add(getResourceProvider());
+            
+        } else if (this.prefix.startsWith(path)) {
+
+            // add myself to the list, as the path is my root
+            providers.add(getResourceProvider());
+
+        }
     }
 
 }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java Fri Feb 29 08:40:30 2008
@@ -35,14 +35,12 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.resource.internal.helper.Descendable;
 import org.osgi.framework.Bundle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** A Resource that wraps a Bundle entry */
-public class BundleResource extends SlingAdaptable implements Resource,
-        Descendable {
+public class BundleResource extends SlingAdaptable implements Resource {
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -209,23 +207,8 @@
         return null;
     }
 
-    // ---------- Descendable interface ----------------------------------------
-
-    public Iterator<Resource> listChildren() {
+    Iterator<Resource> listChildren() {
         return new BundleResourceIterator(this);
-    }
-
-    public Resource getDescendent(String relPath) {
-
-        // only consider folder resources for descendents
-        if (!isFile()) {
-            URL descendent = bundle.getEntry(path + relPath);
-            if (descendent != null) {
-                new BundleResource(resourceResolver, bundle, descendent.getPath());
-            }
-        }
-
-        return null;
     }
 
     Bundle getBundle() {

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java Fri Feb 29 08:40:30 2008
@@ -19,8 +19,12 @@
 package org.apache.sling.jcr.resource.internal.helper.bundle;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 import javax.servlet.http.HttpServletRequest;
@@ -29,6 +33,7 @@
 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.api.resource.SyntheticResource;
 import org.osgi.framework.Bundle;
 
 public class BundleResourceProvider implements ResourceProvider {
@@ -77,9 +82,82 @@
         return BundleResource.getResource(resourceResolver, bundle, path);
     }
 
-    public Iterator<Resource> listChildren(Resource parent)
+    public Iterator<Resource> listChildren(final Resource parent)
             throws SlingException {
-        // TODO Auto-generated method stub
-        return null;
+
+        // bundle resources can handle this request directly
+        if (parent instanceof BundleResource) {
+            return ((BundleResource) parent).listChildren();
+        }
+
+        // otherwise create an iterator which builds the entries based on
+        // the contents of the roots list
+        return new Iterator<Resource>() {
+            private final String parentPath;
+
+            private final ResourceResolver resolver;
+
+            private final Iterator<String> roots;
+
+            private Resource nextResult;
+            
+            private final Set<String> visited = new HashSet<String>();
+            {
+                String pp = parent.getPath();
+                if (!pp.endsWith("/")) {
+                    pp = pp.concat("/");
+                }
+                parentPath = pp;
+                resolver = parent.getResourceResolver();
+                roots = Arrays.asList(getRoots()).iterator();
+                nextResult = seek();
+            }
+
+            public boolean hasNext() {
+                return nextResult != null;
+            }
+
+            public Resource next() {
+                if (nextResult == null) {
+                    throw new NoSuchElementException();
+                }
+                
+                Resource result = nextResult;
+                nextResult = seek();
+                return result;
+            }
+
+            public void remove() {
+                throw new UnsupportedOperationException("remove");
+            }
+
+            private Resource seek() {
+                Resource result = null;
+                while (result == null && roots.hasNext()) {
+                    String path = roots.next();
+                    if (path.startsWith(parentPath)) {
+                        int nextSlash = path.indexOf('/', parentPath.length());
+                        if (nextSlash < 0) {
+                            result = BundleResource.getResource(resolver,
+                                bundle, path);
+                        } else {
+
+                            path = path.substring(0, nextSlash);
+                            if (!visited.contains(path)) {
+                                visited.add(path);
+                                if (resolver.getResource(path) == null) {
+                                    result = new SyntheticResource(resolver,
+                                        path, RESOURCE_TYPE_SYNTHETIC);
+                                }
+                            }
+                        }
+                    }
+
+                }
+                
+                return result;
+            }
+        };
+
     }
 }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java Fri Feb 29 08:40:30 2008
@@ -21,6 +21,8 @@
 import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY;
 import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
 
+import java.util.Iterator;
+
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
@@ -114,5 +116,11 @@
 
         return result;
     }
+    
+    /**
+     * Returns an iterator over the child resources or <code>null</code> if
+     * there are none.
+     */
+    abstract Iterator<Resource> listChildren();
 
 }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java Fri Feb 29 08:40:30 2008
@@ -23,7 +23,6 @@
 import static org.apache.jackrabbit.JcrConstants.JCR_LASTMODIFIED;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIMETYPE;
 import static org.apache.jackrabbit.JcrConstants.NT_FILE;
-import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
 
 import java.io.InputStream;
 import java.net.URL;
@@ -35,21 +34,16 @@
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
 
 import org.apache.jackrabbit.net.URLFactory;
-import org.apache.sling.adapter.SlingAdaptable;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
-import org.apache.sling.jcr.resource.internal.helper.Descendable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** A Resource that wraps a JCR Node */
-public class JcrNodeResource extends JcrItemResource implements Descendable {
+public class JcrNodeResource extends JcrItemResource {
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -171,7 +165,8 @@
 
     // ---------- Descendable interface ----------------------------------------
 
-    public Iterator<Resource> listChildren() {
+    @Override
+    Iterator<Resource> listChildren() {
         try {
             if (getNode().hasNodes()) {
                 return new JcrNodeResourceIterator(getResourceResolver(),
@@ -182,26 +177,6 @@
         }
 
         return Collections.<Resource> emptyList().iterator();
-    }
-
-    public Resource getDescendent(String relPath) {
-        try {
-            if (node.hasNode(relPath)) {
-                return new JcrNodeResource(getResourceResolver(),
-                    node.getNode(relPath));
-            } else if (node.hasProperty(relPath)) {
-                return new JcrPropertyResource(getResourceResolver(), getPath()
-                    + "/" + relPath, node.getProperty(relPath));
-            }
-
-            log.error("getResource: There is no node at {} below {}",
-                getPath(), getPath());
-            return null;
-        } catch (RepositoryException re) {
-            log.error("getResource: Problem accessing relative resource at "
-                + getPath(), re);
-            return null;
-        }
     }
 
     private void setMetaData(Node node, ResourceMetadata metadata) {

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java Fri Feb 29 08:40:30 2008
@@ -20,6 +20,8 @@
 
 import java.io.InputStream;
 import java.util.Calendar;
+import java.util.Collections;
+import java.util.Iterator;
 
 import javax.jcr.Item;
 import javax.jcr.Node;
@@ -28,6 +30,7 @@
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
 
+import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -119,6 +122,11 @@
         }
         
         // fall back to none in case of an error
+        return null;
+    }
+    
+    @Override
+    Iterator<Resource> listChildren() {
         return null;
     }
 }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=632379&r1=632378&r2=632379&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Fri Feb 29 08:40:30 2008
@@ -18,10 +18,7 @@
  */
 package org.apache.sling.jcr.resource.internal.helper.jcr;
 
-import java.security.AccessControlException;
-import java.util.Collections;
 import java.util.Iterator;
-import java.util.List;
 
 import javax.jcr.Item;
 import javax.jcr.Node;
@@ -35,7 +32,6 @@
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl;
-import org.apache.sling.jcr.resource.internal.helper.Descendable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -86,23 +82,31 @@
     }
 
     public Iterator<Resource> listChildren(Resource parent) {
-        if (parent instanceof Descendable) {
-            return ((Descendable) parent).listChildren();
-        }
-
-        try {
-            parent = getResource(parent.getResourceResolver(), parent.getPath());
-            if (parent instanceof Descendable) {
-                return ((Descendable) parent).listChildren();
+        
+        JcrItemResource parentItemResource;
+        
+        // short cut for known JCR resources
+        if (parent instanceof JcrItemResource) {
+        
+            parentItemResource = (JcrItemResource) parent;
+
+        } else {
+            
+            // try to get the JcrItemResource for the parent path to list
+            // children
+            try {
+                parentItemResource = createResource(
+                    parent.getResourceResolver(), parent.getPath());
+            } catch (RepositoryException re) {
+                parentItemResource = null;
             }
-        } catch (SlingException se) {
-            log.warn("listChildren: Error trying to resolve parent resource "
-                + parent.getPath(), se);
+            
         }
 
-        // return an empty iterator if parent has no node
-        List<Resource> empty = Collections.emptyList();
-        return empty.iterator();
+        // return children if there is a parent item resource, else null
+        return (parentItemResource != null)
+                ? parentItemResource.listChildren()
+                : null;
     }
 
     public Session getSession() {
@@ -124,7 +128,7 @@
      * @throws AccessControlException If the item really exists but this content
      *             manager's session has no read access to it.
      */
-    private Resource createResource(ResourceResolver resourceResolver,
+    private JcrItemResource createResource(ResourceResolver resourceResolver,
             String path) throws RepositoryException {
         if (itemExists(path)) {
             Item item = getSession().getItem(path);