jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r354822 - /incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
Date Wed, 07 Dec 2005 18:20:47 GMT
Author: bcm
Date: Wed Dec  7 10:20:44 2005
New Revision: 354822

URL: http://svn.apache.org/viewcvs?rev=354822&view=rev
Log:
refactor the version of createResource() which calls
resource.setIsCollection() so that the decision when to call that
method and the calculation of the value passed to it are delegated to
helper methods.

isCreateRequest() returns true if the request method signifies that a
resource needs to be created. this is the circumstance in which
resource.setIsCollection() needs to be called. the default
implementation of isCreateRequest() returns true when the method is
MKCOL, PUT or POST.

isCreateCollectionRequest() erturns true if the request method
signifies that a *collection* resource needs to be created. it is used
to decide whether to pass true or false to
resource.setIsCollection(). the default implementation returns true
when the method is MKCOL.

this refactoring allows subclasses to override/extend the logic used
for making these choices. for example, cosmo's
CosmoResourceFactoryImpl extends the methods to return true when the
http request method is MKCALENDAR.

we also add accessors for the lockManager and resourceConfig
attributes and make them non-final so that other objects can modify
them.

Modified:
    incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java?rev=354822&r1=354821&r2=354822&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
Wed Dec  7 10:20:44 2005
@@ -34,12 +34,12 @@
  */
 public class ResourceFactoryImpl implements DavResourceFactory {
 
-    private final LockManager lockMgr;
-    private final ResourceConfig resourceConfig;
+    private LockManager lockMgr;
+    private ResourceConfig resourceConfig;
 
     /**
      * Create a new <code>ResourceFactory</code> that uses the given lock
-     * manager and the default {@link DefaultResourceFilter resource filter}.
+     * manager and the default {@link ResourceConfig resource config}.
      *
      * @param lockMgr
      */
@@ -75,12 +75,8 @@
     public DavResource createResource(DavResourceLocator locator, DavServletRequest request,
                                       DavServletResponse response) throws DavException {
         DavResourceImpl resource = (DavResourceImpl)createResource(locator, request.getDavSession());
-        int methodCode = DavMethods.getMethodCode(request.getMethod());
-        if (methodCode == DavMethods.DAV_MKCOL || methodCode == DavMethods.DAV_PUT || methodCode
== DavMethods.DAV_POST) {
-            if (!resource.exists()) {
-                boolean isCollection = DavMethods.getMethodCode(request.getMethod()) == DavMethods.DAV_MKCOL;
-                resource.setIsCollection(isCollection);
-            }
+        if (isCreateRequest(request) && ! resource.exists()) {
+            resource.setIsCollection(isCreateCollectionRequest(request));
         }
         return resource;
     }
@@ -103,5 +99,50 @@
         } catch (RepositoryException e) {
             throw new JcrDavException(e);
         }
+    }
+ 
+    /**
+     * Returns <code>true</code> if the request is to create a
+     * resource. True for <code>MKCOL</code>, <code>PUT</code> and
+     * <code>POST</code> requests.
+     */
+    protected boolean isCreateRequest(DavServletRequest request) {
+        int methodCode = DavMethods.getMethodCode(request.getMethod());
+        return (methodCode == DavMethods.DAV_MKCOL ||
+                methodCode == DavMethods.DAV_PUT ||
+                methodCode == DavMethods.DAV_POST);
+    }
+ 
+    /**
+     * Returns <code>true</code> if the request is to create a
+     * collection resource. True for <code>MKCOL</code> requests.
+     */
+    protected boolean isCreateCollectionRequest(DavServletRequest request) {
+        return (DavMethods.getMethodCode(request.getMethod()) ==
+                DavMethods.DAV_MKCOL);
+    }
+ 
+    /**
+     */
+    public LockManager getLockManager() {
+        return lockMgr;
+    }
+ 
+    /**
+     */
+    public void setLockManager(LockManager lockMgr) {
+        this.lockMgr = lockMgr;
+    }
+ 
+    /**
+     */
+    public ResourceConfig getResourceConfig() {
+        return resourceConfig;
+    }
+ 
+    /**
+     */
+    public void setResourceConfig(ResourceConfig resourceConfig) {
+        this.resourceConfig = resourceConfig;
     }
 }



Mime
View raw message