incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1479986 - in /sling/trunk/contrib/extensions/collection/src: main/java/org/apache/sling/resource/collection/ main/java/org/apache/sling/resource/collection/impl/ test/java/org/apache/sling/resource/collection/impl/
Date Tue, 07 May 2013 17:21:30 GMT
Author: cziegeler
Date: Tue May  7 17:21:30 2013
New Revision: 1479986

URL: http://svn.apache.org/r1479986
Log:
SLING-2860 :  Make ResourceCollectionManager an OSGi service 

Modified:
    sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
    sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
    sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
    sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java

Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java?rev=1479986&r1=1479985&r2=1479986&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
(original)
+++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
Tue May  7 17:21:30 2013
@@ -28,65 +28,60 @@ import org.apache.sling.api.resource.Res
 /**
  * The <code>ResourceCollectionManager<code> defines the API to get, create and
delete
  * resource collections {@link org.apache.sling.resource.collection.ResourceCollection}.
- * 
- * A ResourceCollectionManager instance can be retrieved by adapting a {@link ResourceResolver}.

+ *
+ * A ResourceCollectionManager instance can be retrieved by adapting a {@link ResourceResolver}.
  */
 public interface ResourceCollectionManager {
-    
+
     /**
-     * This method returns a resource collection for the given <code>resource</code>

+     * This method returns a resource collection for the given <code>resource</code>
      * that represents a {@link ResourceCollection}.
-     *  
+     *
      * It returns null if given resource is not a collection
-     * 
+     *
      * @param resource resource that represents a collection
      * @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing
the collection.
-     *      
+     *
      */
     ResourceCollection getCollection(Resource resource);
-    
-    
+
+
     /**
-     * This method creates a resource collection with a given name under the <code>parentResource</code>.

+     * This method creates a resource collection with a given name under the <code>parentResource</code>.
      * The changes are transient and have to be saved by resourceResolver.commit()
-     * 
+     *
      * @param parentResource parent resource where collection needs to be created.
      * @param name The name for collection.
      *
      * @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing
the created collection.
-     * 
+     *
      * @throws {@link PersistenceException} if the operation fails
      */
     ResourceCollection createCollection(Resource parentResource, String name) throws PersistenceException;
-    
+
     /**
      * This method creates a resource collection with a given name under the <code>parentResource</code>.
      * The changes are transient and have to be saved by resourceResolver.commit()
-     * 
+     *
      * @param parentResource parent resource where collection needs to be created.
      * @param name The name for collection.
      * @param properties The additional data for resource collection
      *
      * @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing
the created collection.
-     * 
+     *
      * @throws {@link PersistenceException} if the operation fails
      */
     ResourceCollection createCollection(Resource parentResource, String name, Map<String,Object>
properties) throws PersistenceException;
-    
+
     /**
-     * Removes the {@link org.apache.sling.resource.collection.ResourceCollection} corresponding
to the collection represented by 
+     * Removes the {@link org.apache.sling.resource.collection.ResourceCollection} corresponding
to the collection represented by
      * <code>resource</code>.
      * The changes are transient and have to be saved by resourceResolver.commit()
-     * 
+     *
      * @param resource resource representing a collection to be deleted.
      * @return <code>true</code> if the collection was successfully removed.
-     * 
+     *
      * @throws {@link PersistenceException} if the operation fails
      */
     boolean deleteCollection(Resource resource) throws PersistenceException;
-    
-    /**
-     * Returns the {@link ResourceResolver} from which this has been retrieved/adapted.
-     */
-    ResourceResolver getResourceResolver();
 }
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java?rev=1479986&r1=1479985&r2=1479986&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
(original)
+++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
Tue May  7 17:21:30 2013
@@ -21,6 +21,7 @@ package org.apache.sling.resource.collec
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.resource.Resource;
@@ -34,7 +35,7 @@ import org.slf4j.LoggerFactory;
  * AdapterFactory that adapts Resources to: {@link ResourceCollection}
  * And ResourceResolver to: {@link ResourceCollectionManager)
  */
-@Component(metatype = false)
+@Component
 @Service
 @Property(name = "service.description", value = "Collection Adapter Factory")
 public class ResourceCollectionAdapterFactory implements AdapterFactory {
@@ -57,6 +58,9 @@ public class ResourceCollectionAdapterFa
 
     };
 
+    @Reference
+    private ResourceCollectionManager collectionManager;
+
     // ---------- AdapterFactory -----------------------------------------------
 
     public <AdapterType> AdapterType getAdapter(Object adaptable,
@@ -93,7 +97,7 @@ public class ResourceCollectionAdapterFa
     private <AdapterType> AdapterType getAdapter(ResourceResolver resolver,
             Class<AdapterType> type) {
         if (COLLECTION_MGR_CLASS == type) {
-            return (AdapterType) new ResourceCollectionManagerImpl(resolver);
+            return (AdapterType) collectionManager;
         } else {
             log.warn("Unable to adapt resolver to requested type {}",
                 type.getName());

Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java?rev=1479986&r1=1479985&r2=1479986&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
(original)
+++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
Tue May  7 17:21:30 2013
@@ -22,9 +22,10 @@ package org.apache.sling.resource.collec
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.resource.collection.ResourceCollection;
 import org.apache.sling.resource.collection.ResourceCollectionManager;
@@ -32,21 +33,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * 
+ *
  * Implements <code>ResourceCollectionManger</code> interface. And provides
  * create, delete, get apis for ResourceCollection.
  *
  * A ResourceCollectionManager instance can be retrieved by adapting ResourceResolver.
  */
+@Component
+@Service(value=ResourceCollectionManager.class)
 public class ResourceCollectionManagerImpl implements ResourceCollectionManager {
 
-    private static final Logger log = LoggerFactory.getLogger(ResourceCollectionManager.class);
-
-    private final ResourceResolver resolver;
-
-    public ResourceCollectionManagerImpl(ResourceResolver resolver) {
-        this.resolver = resolver;
-    }
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
 
     /**
      * {@inheritDoc}
@@ -55,11 +52,11 @@ public class ResourceCollectionManagerIm
     	if (resource != null) {
     		if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) {
                 return new ResourceCollectionImpl(resource);
-            } 
+            }
     	} else {
     		throw new IllegalArgumentException("resource can not be null");
     	}
-    	
+
     	return null;
     }
 
@@ -76,15 +73,15 @@ public class ResourceCollectionManagerIm
      */
     public ResourceCollection createCollection(Resource parentResource, String name,
             Map<String, Object> properties) throws PersistenceException {
-        
+
         if (parentResource != null) {
         	String fullPath = parentResource.getPath() + "/" + name;
 
-            if (resolver.getResource(fullPath) != null) {
+            if (parentResource.getResourceResolver().getResource(fullPath) != null) {
                 throw new IllegalArgumentException("invalid path, " + fullPath
                     + "resource already exists");
             }
-            
+
             if (properties == null) {
                 properties = new HashMap<String, Object>();
             }
@@ -99,8 +96,8 @@ public class ResourceCollectionManagerIm
                     JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
                     ResourceCollection.RESOURCE_TYPE);
             }
-            Resource collectionRes = resolver.create(parentResource, name, properties);
-            resolver.create(collectionRes, ResourceCollectionConstants.MEMBERS_NODE_NAME,
null);
+            Resource collectionRes = parentResource.getResourceResolver().create(parentResource,
name, properties);
+            parentResource.getResourceResolver().create(collectionRes, ResourceCollectionConstants.MEMBERS_NODE_NAME,
null);
             log.debug("collection  {} created", fullPath);
 
             return new ResourceCollectionImpl(collectionRes);
@@ -113,25 +110,17 @@ public class ResourceCollectionManagerIm
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @throws PersistenceException
      */
     public boolean deleteCollection(Resource resource)
             throws PersistenceException {
     	if (resource != null) {
 	        log.debug("collection  {} deleted", resource.getPath());
-	        resolver.delete(resource);
+	        resource.getResourceResolver().delete(resource);
 	        return true;
     	} else {
     		throw new IllegalArgumentException("resource can not be null");
     	}
     }
-    
-    /**
-     * {@inheritDoc}
-     */
-	public ResourceResolver getResourceResolver() {
-		return resolver;
-	}
-
 }
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java?rev=1479986&r1=1479985&r2=1479986&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
(original)
+++ sling/trunk/contrib/extensions/collection/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
Tue May  7 17:21:30 2013
@@ -42,7 +42,7 @@ public class ResourceCollectionImplTest 
 	@Before
 	public void setUp() throws Exception {
 		resResolver = new MockResourceResolverFactory().getAdministrativeResourceResolver(null);
-		rcm = new ResourceCollectionManagerImpl(resResolver);
+		rcm = new ResourceCollectionManagerImpl();
 	}
 
 	@Test
@@ -76,14 +76,14 @@ public class ResourceCollectionImplTest 
         Assert.assertNotNull(resResolver.getResource("/test1"));
         Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
 	}
-	
+
 	@Test
 	public void testCheckPath() throws Exception {
 		final Resource rootResource = resResolver.create(resResolver.getResource("/"), "root",
                 Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
-		
+
         final ResourceCollection collection = rcm.createCollection(rootResource, "test1");
-        
+
 
         Assert.assertEquals(rootResource.getPath() + "/" + "test1", collection.getPath());
  	}
@@ -198,12 +198,12 @@ public class ResourceCollectionImplTest 
         	Assert.assertEquals(resPaths[numOfRes], entry.getPath());
         	numOfRes ++;
         }
-        
+
         try {
         	collection.orderBefore(resource, resource);
         	Assert.fail("should have thrown IllegalArgument");
         } catch (IllegalArgumentException e) {
-        	
+
         }
 
         //change the order



Mime
View raw message