org.opencms.lock
Class CmsLock

java.lang.Object
  extended by org.opencms.lock.CmsLock

public class CmsLock
extends java.lang.Object

Represents the lock state of a VFS resource.

The lock state is combination of how, by whom and in which project a resource is currently locked.

Since:
6.0.0
Version:
$Revision: 1.34 $
Author:
Thomas Weckert, Andreas Zahner, Michael Moossen
See Also:
CmsObject.getLock(org.opencms.file.CmsResource), CmsLockManager

Constructor Summary
CmsLock(java.lang.String resourceName, CmsUUID userId, CmsProject project, CmsLockType type)
          Constructor for a new Cms lock.
 
Method Summary
protected  java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
          Compares this lock to the specified object.
 CmsLock getEditionLock()
          Returns the edition lock.
static CmsLock getNullLock()
          Returns the shared Null CmsLock.
 CmsProject getProject()
          Returns the project where the resource is currently locked.
 CmsUUID getProjectId()
          Returns the ID of the project where the resource is currently locked.
protected  CmsLock getRelatedLock()
          Returns the related Lock.
 java.lang.String getResourceName()
          Returns the name of the locked resource.
 CmsLock getSystemLock()
          Returns the system lock.
 CmsLockType getType()
          Returns the type about how the resource is locked.
 CmsUUID getUserId()
          Returns the ID of the user who currently locked the resource.
 int hashCode()
           
 boolean isDirectlyInherited()
          Returns true if this is an directly inherited lock.
 boolean isExclusive()
          Returns true if this is an exclusive (or temporary exclusive) lock.
 boolean isExclusiveOwnedBy(CmsUser user)
          Returns true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner of this lock.
 boolean isExclusiveOwnedInProjectBy(CmsUser user, CmsProject project)
          Returns true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner and the given project is the project of this lock.
 boolean isInherited()
          Returns true if this is an inherited lock, which may either be directly or shared inherited.
 boolean isInProject(CmsProject project)
          Returns true if the given project is the project of this lock.
 boolean isLockableBy(CmsUser user)
          Checks if a resource can be locked by a user.
 boolean isNullLock()
          Returns true if this lock is the NULL lock which can be obtained by getNullLock().
 boolean isOwnedBy(CmsUser user)
          Returns true if the given user is the owner of this lock.
 boolean isOwnedInProjectBy(CmsUser user, CmsProject project)
          Returns true if the given user is the owner of this lock, and this lock belongs to the given project.
 boolean isPersistent()
          Returns true if this is a persistent lock that should be saved when the systems shuts down.
 boolean isPublish()
          Returns true if this is a publish lock.
 boolean isShared()
          Returns true if this is a shared lock.
 boolean isSystemLock()
          Returns true if this is a system (2nd level) lock.
 boolean isTemporary()
          Returns true if this is a temporary lock.
 boolean isUnlocked()
          Returns true if this lock is in fact unlocked.
protected  void setRelatedLock(CmsLock relatedLock)
          Sets the related Lock.
 java.lang.String toString()
          Builds a string representation of the current state.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsLock

public CmsLock(java.lang.String resourceName,
               CmsUUID userId,
               CmsProject project,
               CmsLockType type)
Constructor for a new Cms lock.

Parameters:
resourceName - the full resource name including the site root
userId - the ID of the user who locked the resource
project - the project where the resource is locked
type - flag indicating how the resource is locked
Method Detail

getNullLock

public static CmsLock getNullLock()
Returns the shared Null CmsLock.

Returns:
the shared Null CmsLock

equals

public boolean equals(java.lang.Object obj)
Compares this lock to the specified object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare to
Returns:
true if and only if member values of this CmsLock are the same with the compared CmsLock

getEditionLock

public CmsLock getEditionLock()
Returns the edition lock.

Returns:
the edition lock

getProject

public CmsProject getProject()
Returns the project where the resource is currently locked.

Returns:
the project where the resource is currently locked

getProjectId

public CmsUUID getProjectId()
Returns the ID of the project where the resource is currently locked.

Returns:
the ID of the project

getResourceName

public java.lang.String getResourceName()
Returns the name of the locked resource.

Returns:
the name of the locked resource

getSystemLock

public CmsLock getSystemLock()
Returns the system lock.

Returns:
the system lock

getType

public CmsLockType getType()
Returns the type about how the resource is locked.

Returns:
the type of the lock

getUserId

public CmsUUID getUserId()
Returns the ID of the user who currently locked the resource.

Returns:
the ID of the user

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

isDirectlyInherited

public boolean isDirectlyInherited()
Returns true if this is an directly inherited lock.

Returns:
true if this is an directly inherited lock

isExclusive

public boolean isExclusive()
Returns true if this is an exclusive (or temporary exclusive) lock.

Returns:
true if this is an exclusive (or temporary exclusive) lock

isExclusiveOwnedBy

public boolean isExclusiveOwnedBy(CmsUser user)
Returns true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner of this lock.

Parameters:
user - the user to compare to the owner of this lock
Returns:
true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner of this lock

isExclusiveOwnedInProjectBy

public boolean isExclusiveOwnedInProjectBy(CmsUser user,
                                           CmsProject project)
Returns true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner and the given project is the project of this lock.

Parameters:
user - the user to compare to the owner of this lock
project - the project to compare to the project of this lock
Returns:
true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner and the given project is the project of this lock

isInherited

public boolean isInherited()
Returns true if this is an inherited lock, which may either be directly or shared inherited.

Returns:
true if this is an inherited lock, which may either be directly or shared inherited

isInProject

public boolean isInProject(CmsProject project)
Returns true if the given project is the project of this lock.

Parameters:
project - the project to compare to the project of this lock
Returns:
true if the given project is the project of this lock

isLockableBy

public boolean isLockableBy(CmsUser user)
Checks if a resource can be locked by a user.

The resource is not lockable if it already has a lock of type CmsLockType.PUBLISH.

The resource is lockable either - if it is currently unlocked - if it has a lock of another type set and the user is the lock owner

Parameters:
user - the user to test lockeability for
Returns:
true if this lock blocks any operation on the locked resource until it is unlocked

isNullLock

public boolean isNullLock()
Returns true if this lock is the NULL lock which can be obtained by getNullLock().

Only for the NULL lock, isUnlocked() is true.

Returns:
true if this lock is the NULL lock

isOwnedBy

public boolean isOwnedBy(CmsUser user)
Returns true if the given user is the owner of this lock.

Parameters:
user - the user to compare to the owner of this lock
Returns:
true if the given user is the owner of this lock

isOwnedInProjectBy

public boolean isOwnedInProjectBy(CmsUser user,
                                  CmsProject project)
Returns true if the given user is the owner of this lock, and this lock belongs to the given project.

Parameters:
user - the user to compare to the owner of this lock
project - the project to compare to the project of this lock
Returns:
true if the given user is the owner of this lock, and this lock belongs to the given project

isPersistent

public boolean isPersistent()
Returns true if this is a persistent lock that should be saved when the systems shuts down.

Returns:
true if this is a persistent lock that should be saved when the systems shuts down

isPublish

public boolean isPublish()
Returns true if this is a publish lock.

Returns:
true if this is a publish lock

isShared

public boolean isShared()
Returns true if this is a shared lock.

Returns:
true if this is a shared lock

isSystemLock

public boolean isSystemLock()
Returns true if this is a system (2nd level) lock.

Returns:
true if this is a system (2nd level) lock

isTemporary

public boolean isTemporary()
Returns true if this is a temporary lock.

Returns:
true if this is a temporary lock

isUnlocked

public boolean isUnlocked()
Returns true if this lock is in fact unlocked.

Only if this is true, the result lock is equal to the NULL lock, which can be obtained by getNullLock().

Returns:
true if this lock is in fact unlocked

toString

public java.lang.String toString()
Builds a string representation of the current state.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

clone

protected java.lang.Object clone()
Overrides:
clone in class java.lang.Object
See Also:
Object.clone()

getRelatedLock

protected CmsLock getRelatedLock()
Returns the related Lock.

Returns:
the related Lock

setRelatedLock

protected void setRelatedLock(CmsLock relatedLock)
Sets the related Lock.

Parameters:
relatedLock - the related Lock to set