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 ju...@apache.org on 2003/04/07 16:26:25 UTC

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

juergen     2003/04/07 07:26:25

  Modified:    src/share/org/apache/slide/lock LockImpl.java
  Log:
  a shared lock can be taken by any user.
  
  Revision  Changes    Path
  1.29      +93 -93    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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- LockImpl.java	14 Mar 2003 15:49:08 -0000	1.28
  +++ LockImpl.java	7 Apr 2003 14:26:25 -0000	1.29
  @@ -81,10 +81,10 @@
    * @version $Revision$
    */
   public final class LockImpl implements Lock {
  -    
  +
       // ----------------------------------------------------------- Constructors
  -    
  -    
  +
  +
       /**
        * Constructor.
        *
  @@ -98,32 +98,32 @@
           this.namespaceConfig = namespaceConfig;
           this.securityHelper = securityHelper;
       }
  -    
  -    
  +
  +
       // ----------------------------------------------------- Instance Variables
  -    
  -    
  +
  +
       /**
        * Namespace.
        */
       private Namespace namespace;
  -    
  -    
  +
  +
       /**
        * Namespace configuration.
        */
       private NamespaceConfig namespaceConfig;
  -    
  -    
  +
  +
       /**
        * Security helper.
        */
       private Security securityHelper;
  -    
  -    
  +
  +
       // ----------------------------------------------------------- Lock Methods
  -    
  -    
  +
  +
       /**
        * Put a lock on a subject.
        *
  @@ -140,13 +140,13 @@
       public void lock(SlideToken slideToken, NodeLock token)
           throws ServiceAccessException, ObjectIsAlreadyLockedException,
           AccessDeniedException, ObjectNotFoundException {
  -        
  +
           ObjectIsAlreadyLockedException nestedException =
               new ObjectIsAlreadyLockedException(token.getObjectUri());
           Uri objectUri = namespace.getUri(slideToken, token.getObjectUri(), true);
           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
           // action, we will get a SecurityException which will in turn be
  @@ -161,28 +161,28 @@
           } else {
               throw nestedException;
           }
  -    
  +
       }
  -    
  -    
  +
  +
       /**
        * Removes a lock.
        *
        * @param crendentialsToken Credentials token
        * @param token Object containing all the lock information
  -     * 
  +     *
        * @return <code>true</code> if the lock could be removed
  -     * 
  +     *
        * @exception ServiceAccessException Low level service access exception
        * @exception LockTokenNotFoundException Cannot find the Lock in the
        * Lock Store service
        */
       public boolean unlock(SlideToken slideToken, NodeLock token)
           throws ServiceAccessException, LockTokenNotFoundException {
  -        
  +
           try {
               if (!slideToken.isEnforceLockTokens()) {
  -                // Lock-Token checking is not being enforced, so we simply 
  +                // Lock-Token checking is not being enforced, so we simply
                   // check whether the principal is also the owner of the lock.
                   ObjectNode principal = securityHelper.getPrincipal(slideToken);
                   if (!token.getSubjectUri().startsWith(principal.getUri())) {
  @@ -196,15 +196,15 @@
           } catch (ObjectNotFoundException e) {
               return false;
           }
  -        
  +
           // all checks successful, so try to actually remove the lock
           Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri(),
                                            true);
           lockedUri.getStore().removeLock(lockedUri, token);
           return true;
       }
  -    
  -    
  +
  +
       /**
        * Removes a set of linked locks.
        *
  @@ -219,7 +219,7 @@
                          String lockId)
           throws ServiceAccessException, LockTokenNotFoundException,
           ObjectNotFoundException {
  -        
  +
           Enumeration locksList = enumerateLocks(slideToken, objectUri, false);
           while (locksList.hasMoreElements()) {
               NodeLock currentLock = (NodeLock) locksList.nextElement();
  @@ -229,10 +229,10 @@
                   unlock(slideToken, currentLock);
               }
           }
  -        
  +
       }
  -    
  -    
  +
  +
       /**
        * Renew a lock.
        *
  @@ -250,8 +250,8 @@
           Uri lockedUri = namespace.getUri(slideToken, token.getObjectUri());
           lockedUri.getStore().renewLock(lockedUri, token);
       }
  -    
  -    
  +
  +
       /**
        * Renew a set of linked locks.
        *
  @@ -266,7 +266,7 @@
                         String lockId, Date newExpirationDate)
           throws ServiceAccessException, LockTokenNotFoundException,
           ObjectNotFoundException {
  -        
  +
           Enumeration locksList = enumerateLocks(slideToken, objectUri, false);
           while (locksList.hasMoreElements()) {
               NodeLock currentLock = (NodeLock) locksList.nextElement();
  @@ -274,10 +274,10 @@
                   renew(slideToken, currentLock, newExpirationDate);
               }
           }
  -        
  +
       }
  -    
  -    
  +
  +
       /**
        * Kills locks.
        *
  @@ -294,7 +294,7 @@
       public void kill(SlideToken slideToken, SubjectNode subject)
           throws ServiceAccessException, AccessDeniedException,
           LockTokenNotFoundException, ObjectNotFoundException {
  -        
  +
           // We retrieve the enumeration of locks which have been put on the
           // subject.
           Uri subjectUri = namespace.getUri(slideToken, subject.getUri());
  @@ -308,24 +308,24 @@
               subjectUri.getStore()
                   .killLock(subjectUri, (NodeLock) locks.nextElement());
           }
  -        
  +
       }
  -    
  +
       public Enumeration enumerateLocks(SlideToken slideToken, String objectUri)
           throws ServiceAccessException, ObjectNotFoundException,
           LockTokenNotFoundException {
  -        
  +
           return enumerateLocks(slideToken, objectUri, true);
       }
  -    
  +
       public Enumeration enumerateLocks(SlideToken slideToken, String objectUri,
                                         boolean inherited)
           throws ServiceAccessException, ObjectNotFoundException,
           LockTokenNotFoundException {
  -        
  +
           // We retrieve the LockStore service from the namespace.
           Uri subjectUri = namespace.getUri(slideToken, objectUri);
  -        
  +
           Enumeration scopes = null;
           if (inherited) {
               // traverse the namespace up to the root node, and add any locks
  @@ -364,8 +364,8 @@
           }
           return locksVector.elements();
       }
  -    
  -    
  +
  +
       /**
        * Utility function for lock checking. Mirrors Security.checkCredentials.
        *
  @@ -382,9 +382,9 @@
                             ObjectNode object, ActionNode action)
           throws ServiceAccessException, ObjectNotFoundException,
           ObjectLockedException {
  -        
  +
           if (Configuration.useIntegratedLocking()) {
  -            
  +
               Uri objectUri = namespace.getUri(token, object.getUri());
               ObjectNode realObject = objectUri.getStore()
                   .retrieveObject(objectUri);
  @@ -395,11 +395,11 @@
               SubjectNode subject = (SubjectNode) subjectUri
                   .getStore().retrieveObject(subjectUri);
               checkLock(token, realObject, subject, action);
  -            
  +
           }
       }
  -    
  -    
  +
  +
       /**
        * Check locking for a specific action and credential.
        *
  @@ -418,16 +418,16 @@
                             ActionNode action)
           throws ServiceAccessException, ObjectNotFoundException,
           ObjectLockedException {
  -        
  +
           if (Configuration.useIntegratedLocking()) {
               if (isLocked(slideToken, subject, user, action, false)) {
                   throw new ObjectLockedException(subject.getUri());
               }
           }
  -        
  +
       }
  -    
  -    
  +
  +
       /**
        * Tests if an element is locked.
        *
  @@ -448,8 +448,8 @@
                                         new Date(), false);
           return isLocked(slideToken, token, tryToLock);
       }
  -    
  -    
  +
  +
       /**
        * Tests if an element is locked.
        *
  @@ -475,8 +475,8 @@
                                         inheritance);
           return isLocked(slideToken, token, tryToLock);
       }
  -    
  -    
  +
  +
       /**
        * Tests if an element is locked.
        *
  @@ -489,13 +489,13 @@
       public boolean isLocked(SlideToken slideToken, NodeLock token,
                               boolean tryToLock)
           throws ServiceAccessException, ObjectNotFoundException {
  -        
  +
           return isLockedInternal(slideToken, token, tryToLock, null);
  -        
  +
       }
  -    
  +
       public void clearExpiredLocks( SlideToken slideToken, String objectUri, UnlockListener listener ) throws SlideException {
  -        
  +
           Uri uri =
               namespace.getUri(slideToken, objectUri);
           Enumeration currentLocks =
  @@ -515,10 +515,10 @@
               }
           }
       }
  -    
  +
       // -------------------------------------------------------- Private Methods
  -    
  -    
  +
  +
       /**
        * Tests if an element is locked.
        *
  @@ -537,11 +537,11 @@
           ObjectNode initialObject = objectUri.getStore()
               .retrieveObject(objectUri);
           Enumeration scopes = objectUri.getScopes();
  -        
  +
           // At the end of the test, this boolean's value is true if we can
           // actually put the lock on the desired subject.
           boolean isLocked = false;
  -        
  +
           // We parse all of the scopes which encompass the subject we want
           // to lock.
           // First, we parse all the parents of the subject.
  @@ -550,7 +550,7 @@
               Uri currentScopeUri = namespace.getUri(slideToken, currentScope, false);
               Enumeration locks = currentScopeUri.getStore()
                   .enumerateLocks(currentScopeUri);
  -            
  +
               while (locks.hasMoreElements()) {
                   NodeLock currentLockToken = (NodeLock) locks.nextElement();
                   if (!isCompatible(slideToken, token, currentLockToken,
  @@ -564,7 +564,7 @@
                   }
               }
           }
  -        
  +
           // Then, if the desired scope is inheritable, we parse the
           // locked subject's children to see if any of them has been
           // locked with an incompatible lock.
  @@ -578,7 +578,7 @@
                   // We test the compatibility of the child
                   Enumeration locks = currentObjectUri.getStore()
                       .enumerateLocks(currentObjectUri);
  -                
  +
                   while (locks.hasMoreElements()) {
                       NodeLock currentLockToken = (NodeLock) locks.nextElement();
                       if (!isCompatible(slideToken, token,
  @@ -591,9 +591,9 @@
                           }
                       }
                   }
  -                
  +
                   // We get the children and add them to the Stack.
  -                
  +
                   Vector childrenVector = new Vector();
                   Enumeration childrenUri = currentObject.enumerateChildren();
                   while (childrenUri.hasMoreElements()) {
  @@ -603,7 +603,7 @@
                           .retrieveObject(tempUri);
                       childrenVector.addElement(child);
                   }
  -                
  +
                   Enumeration children = childrenVector.elements();
                   while (children.hasMoreElements()) {
                       ObjectNode tempObject =
  @@ -612,12 +612,12 @@
                   }
               }
           }
  -        
  +
           return isLocked;
  -        
  +
       }
  -    
  -    
  +
  +
       /**
        * Return true if a lock token for this lock has been given in the
        * credentials token.
  @@ -627,15 +627,15 @@
        */
       private boolean checkLockToken(SlideToken slideToken,
                                      NodeLock token) {
  -        
  +
           if (!slideToken.isEnforceLockTokens())
               return true;
  -        
  +
           return (slideToken.checkLockToken(token.getLockId()));
  -        
  +
       }
  -    
  -    
  +
  +
       /**
        * Tells whether or not two locks are compatible.
        *
  @@ -655,9 +655,9 @@
             + token2.getObjectUri() + " action "
             + token2.getTypeUri());
           */
  -        
  +
           boolean compatible = true;
  -        
  +
           // We first check whether or not the lock is still valid
           if (token2.hasExpired()) {
               // Since the lock has expired, it is removed
  @@ -689,9 +689,9 @@
                   || (condition3 && !condition5 && condition6)) {
                   compatible = false;
               }
  -            
  +
               // sharing the lock is OK
  -            if (token1.isShared() && token2.isShared() && condition1 && !condition2) {
  +            if (token1.isShared() && token2.isShared() && condition1 ) {
                   compatible = true;
               }
   
  @@ -713,11 +713,11 @@
   //              System.out.println("C5:" + condition5);
   //              System.out.println("C6:" + condition6);
   //              System.out.println("Compatible:" + compatible);
  -            
  +
           }
           return compatible;
       }
  -    
  +
   }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org