incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1406767 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/resource/ jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/ jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/ resourcere...
Date Wed, 07 Nov 2012 19:32:48 GMT
Author: cziegeler
Date: Wed Nov  7 19:32:47 2012
New Revision: 1406767

URL: http://svn.apache.org/viewvc?rev=1406767&view=rev
Log:
SLING-2641 :  Make listChildren() Iterable 

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
Wed Nov  7 19:32:47 2012
@@ -94,6 +94,18 @@ public abstract class AbstractResource
     }
 
     /**
+     * @see org.apache.sling.api.resource.Resource#getChildren()
+     */
+    public Iterable<Resource> getChildren() {
+        return new Iterable<Resource>() {
+
+            public Iterator<Resource> iterator() {
+                return listChildren();
+            }
+        };
+    }
+
+    /**
      * Returns <code>true</code> if this resource is of the given resource type
      * or if any of the super resource types equals the given resource type.
      * <p>
@@ -123,6 +135,6 @@ public abstract class AbstractResource
             superType = ResourceUtil.getResourceSuperType(getResourceResolver(),
                     superType);
         }
-        return false; 
+        return false;
     }
 }

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java Wed
Nov  7 19:32:47 2012
@@ -81,6 +81,17 @@ public interface Resource extends Adapta
     Iterator<Resource> listChildren();
 
     /**
+     * Returns an iterator of the direct children of this resource.
+     * <p>
+     * This method is a convenience and returns exactly the same resources as
+     * calling <code>getResourceResolver().listChildren(resource)</code>.
+     *
+     * @since 2.2.0
+     * @see ResourceResolver#listChildren(Resource)
+     */
+    Iterable<Resource> getChildren();
+
+    /**
      * Returns the child at the given relative path of this resource or
      * <code>null</code> if no such child exists.
      * <p>

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
Wed Nov  7 19:32:47 2012
@@ -356,6 +356,27 @@ public interface ResourceResolver extend
     Iterator<Resource> listChildren(Resource parent);
 
     /**
+     * Returns an <code>Iterator</code> of {@link Resource} objects loaded from
+     * the children of the given <code>Resource</code>.
+     * <p>
+     * This specification does not define what the term "child" means. This is
+     * left to the implementation to define. For example an implementation
+     * reading content from a Java Content Repository, the children could be the
+     * {@link Resource} objects loaded from child items of the <code>Item</code>
+     * of the given <code>Resource</code>.
+     *
+     * @param parent The {@link Resource Resource} whose children are requested.
+     * @return An <code>Iterator</code> of {@link Resource} objects.
+     * @throws NullPointerException If <code>parent</code> is <code>null</code>.
+     * @throws org.apache.sling.api.SlingException If any error occurs acquiring
+     *             the child resource iterator.
+     * @throws IllegalStateException if this resource resolver has already been
+     *             {@link #close() closed}.
+     * @since 2.2
+     */
+    Iterable<Resource> getChildren(Resource parent);
+
+    /**
      * Searches for resources using the given query formulated in the given
      * language.
      * <p>

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
Wed Nov  7 19:32:47 2012
@@ -97,6 +97,13 @@ public class ResourceWrapper implements 
     }
 
     /**
+     * @see org.apache.sling.api.resource.Resource#getChildren()
+     */
+    public Iterable<Resource> getChildren() {
+        return getResource().getChildren();
+    }
+
+    /**
      * Returns the value of calling <code>getResourceMetadata</code> on the
      * {@link #getResource() wrapped resource}.
      */

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
Wed Nov  7 19:32:47 2012
@@ -184,6 +184,11 @@ public class JcrResourceListenerTest ext
                 return null;
             }
 
+            public Iterable<Resource> getChildren(Resource parent) {
+                // TODO Auto-generated method stub
+                return null;
+            }
+
             public Iterator<Resource> findResources(String query, String language)
{
                 // TODO Auto-generated method stub
                 return null;

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/MockResourceResolver.java
Wed Nov  7 19:32:47 2012
@@ -76,6 +76,10 @@ public class MockResourceResolver implem
         return null;
     }
 
+    public Iterable<Resource> getChildren(Resource parent) {
+        return null;
+    }
+
     public String map(String resourcePath) {
         return null;
     }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Wed Nov  7 19:32:47 2012
@@ -618,6 +618,18 @@ public class ResourceResolverImpl extend
                 new ResourceIterator(this.context, parent, this.factory.getRootProviderEntry()));
     }
 
+    /**
+     * @see org.apache.sling.api.resource.Resource#getChildren()
+     */
+    public Iterable<Resource> getChildren(final Resource parent) {
+        return new Iterable<Resource>() {
+
+            public Iterator<Resource> iterator() {
+                return listChildren(parent);
+            }
+        };
+    }
+
     // ---------- Querying resources
 
     private static final String DEFAULT_QUERY_LANGUAGE = "xpath";

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java?rev=1406767&r1=1406766&r2=1406767&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
Wed Nov  7 19:32:47 2012
@@ -181,33 +181,33 @@ public class ResourceProviderEntryTest {
         assertEquals(first, root.getResource(null, null, "/rootel/html.js"));
         assertEquals(second, root.getResource(null, null, "/rootel/child/html.js"));
     }
-    
+
     @Test public void testRemoveTheOnlyProvider() {
         final ResourceProviderEntry e = new ResourceProviderEntry("/", null);
         long counter = 1;
-        
+
         for(String path : new String[] { "/foo", "/", "/foo/bar" }) {
             final ResourceProvider p = new TestResourceProvider(path);
             final Map<String, Object> props = new HashMap<String, Object>();
             props.put(Constants.SERVICE_ID, ++counter);
-            
+
             e.addResourceProvider(path, new ResourceProviderHandler(p, props));
             {
-                final Resource r = e.getResource(null, null, path); 
+                final Resource r = e.getResource(null, null, path);
                 assertEquals(p, r);
                 assertFalse(r instanceof SyntheticResource);
             }
-            
+
             e.removeResourceProvider(path, new ResourceProviderHandler(p, props));
             {
-                final Resource r = e.getResource(null, null, path); 
+                final Resource r = e.getResource(null, null, path);
                 // If our provider is indeed gone, we should get one of the following conditions
                 if(r == null) {
                     //fine
                 } else if(!p.equals(r.getResourceResolver())) {
                     //fine
                 } else {
-                    fail("Expecting inactive provider after removing it for " + path); 
+                    fail("Expecting inactive provider after removing it for " + path);
                 }
             }
         }
@@ -257,6 +257,10 @@ public class ResourceProviderEntryTest {
             return null;
         }
 
+        public Iterable<Resource> getChildren(Resource parent) {
+            return null;
+        }
+
         // just dummy implementation to mark our resources for the tests
         public Iterator<Resource> findResources(String query, String language) {
             return null;
@@ -388,6 +392,7 @@ public class ResourceProviderEntryTest {
             return null;
         }
 
+        @Override
         public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
             return null;
         }



Mime
View raw message