You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/07/24 08:42:21 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/lock LockImpl.java ObjectIsAlreadyLockedException.java

remm        01/07/23 23:42:21

  Modified:    src/share/org/apache/slide/lock LockImpl.java
                        ObjectIsAlreadyLockedException.java
  Log:
  - Use nested exceptions to report locking errors.
  - Apply Christopher Lenz's fix to the locking algorithm.
  
  Revision  Changes    Path
  1.17      +43 -11    jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java
  
  Index: LockImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- LockImpl.java	2001/06/01 07:23:44	1.16
  +++ LockImpl.java	2001/07/24 06:42:20	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 1.16 2001/06/01 07:23:44 remm Exp $
  - * $Revision: 1.16 $
  - * $Date: 2001/06/01 07:23:44 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/LockImpl.java,v 1.17 2001/07/24 06:42:20 remm Exp $
  + * $Revision: 1.17 $
  + * $Date: 2001/07/24 06:42:20 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,7 @@
    * Lock helper class.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.16 $
  + * @version $Revision: 1.17 $
    */
   public final class LockImpl implements Lock {
       
  @@ -141,7 +141,10 @@
           throws ServiceAccessException, ObjectIsAlreadyLockedException, 
           AccessDeniedException, ObjectNotFoundException {
           
  -        boolean canLock = !isLocked(slideToken, token, true);
  +        ObjectIsAlreadyLockedException nestedException = 
  +            new ObjectIsAlreadyLockedException(token.getObjectUri());
  +        boolean canLock = 
  +            !isLockedInternal(slideToken, token, true, nestedException);
           
           // Then we try to lock the subject.
           // If the User doesn't have enough priviledges to accomplish this 
  @@ -157,7 +160,7 @@
               Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri());
               lockedUri.getStore().putLock(lockedUri, token);
           } else {
  -            throw new ObjectIsAlreadyLockedException(token.getObjectUri());
  +            throw nestedException;
           }
   	
       }
  @@ -468,6 +471,28 @@
                               boolean tryToLock)
           throws ServiceAccessException, ObjectNotFoundException {
           
  +        return isLockedInternal(slideToken, token, tryToLock, null);
  +        
  +    }
  +    
  +    
  +    // -------------------------------------------------------- Private Methods
  +    
  +    
  +    /**
  +     * Tests if an element is locked.
  +     * 
  +     * @param token Lock token to test
  +     * @return boolean True if locked
  +     * @exception ServiceAccessException Low level service access exception
  +     * @exception ObjectNotFoundException One of the objects referenced 
  +     * in the lock token were not found
  +     */
  +    private boolean isLockedInternal
  +        (SlideToken slideToken, NodeLock token,
  +         boolean tryToLock, ObjectIsAlreadyLockedException nestedException)
  +        throws ServiceAccessException, ObjectNotFoundException {
  +
           Uri objectUri = namespace.getUri(slideToken, token.getObjectUri());
           ObjectNode initialObject = objectUri.getStore()
               .retrieveObject(objectUri);
  @@ -491,6 +516,11 @@
                   if (!isCompatible(slideToken, token, currentLockToken, 
                                     tryToLock)) {
                       isLocked = true;
  +                    if (nestedException != null) {
  +                        nestedException.addException
  +                            (new ObjectLockedException
  +                             (currentScopeUri.toString()));
  +                    }
                   }
               }
           }
  @@ -514,6 +544,11 @@
                       if (!isCompatible(slideToken, token, 
                                         currentLockToken, tryToLock)) {
                           isLocked = true;
  +                        if (nestedException != null) {
  +                            nestedException.addException
  +                                (new ObjectLockedException
  +                                 (currentObjectUri.toString()));
  +                        }
                       }
                   }
                   
  @@ -543,9 +578,6 @@
       }
       
       
  -    // -------------------------------------------------------- Private Methods
  -    
  -    
       /**
        * Return true if a lock token for this lock has been given in the 
        * credentials token.
  @@ -604,8 +636,8 @@
               boolean condition2 = 
                   (token1.getSubjectUri().startsWith(token2.getSubjectUri()));
               // The two lock types are the same
  -            boolean condition3 = token1.getTypeUri()
  -                .startsWith(token2.getTypeUri());
  +            boolean condition3 = token2.getTypeUri()
  +                .startsWith(token1.getTypeUri());
               // The lockType is exclusive
               boolean condition4 = token1.isExclusive();
               // Was a proper lock token given out ?
  
  
  
  1.3       +10 -5     jakarta-slide/src/share/org/apache/slide/lock/ObjectIsAlreadyLockedException.java
  
  Index: ObjectIsAlreadyLockedException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/ObjectIsAlreadyLockedException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectIsAlreadyLockedException.java	2000/09/26 02:44:16	1.2
  +++ ObjectIsAlreadyLockedException.java	2001/07/24 06:42:21	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/ObjectIsAlreadyLockedException.java,v 1.2 2000/09/26 02:44:16 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/09/26 02:44:16 $
  + * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/lock/ObjectIsAlreadyLockedException.java,v 1.3 2001/07/24 06:42:21 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/07/24 06:42:21 $
    *
    * ====================================================================
    *
  @@ -63,16 +63,20 @@
   
   package org.apache.slide.lock;
   
  +import java.util.Vector;
  +import java.util.Enumeration;
   import org.apache.slide.common.Uri;
  +import org.apache.slide.common.NestedSlideException;
  +import org.apache.slide.common.SlideException;
   import org.apache.slide.util.Messages;
   
   /**
    * Object is already locked.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
  -public class ObjectIsAlreadyLockedException extends LockException {
  +public class ObjectIsAlreadyLockedException extends NestedSlideException {
       
       
       // ----------------------------------------------------------- Constructors
  @@ -87,5 +91,6 @@
           super(Messages.format(ObjectIsAlreadyLockedException.class.getName(), 
                                 objectUri));
       }
  +
       
   }