Package org.opencms.lock
Class CmsLock
- java.lang.Object
-
- org.opencms.lock.CmsLock
-
- All Implemented Interfaces:
java.lang.Comparable<CmsLock>
public class CmsLock extends java.lang.Object implements java.lang.Comparable<CmsLock>
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
- See Also:
CmsObject.getLock(org.opencms.file.CmsResource)
,CmsLockManager
-
-
Constructor Summary
Constructors Constructor Description CmsLock(java.lang.String resourceName, CmsUUID userId, CmsProject project, CmsLockType type)
Constructor for a new Cms lock.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
clone()
int
compareTo(CmsLock other)
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()
Returnstrue
if this is an directly inherited lock.boolean
isDirectlyOwnedBy(CmsUser user)
Returnstrue
if this is an exclusive, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock.boolean
isDirectlyOwnedInProjectBy(CmsObject cms)
Returnstrue
if this is an exclusive, temporary exclusive, or directly inherited lock, and the current user is the owner of this lock, checking also the project of the lock.boolean
isDirectlyOwnedInProjectBy(CmsUser user, CmsProject project)
Returnstrue
if this is an exclusive, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock, checking also the project of the lock.boolean
isExclusive()
Returnstrue
if this is an exclusive (or temporary exclusive) lock.boolean
isExclusiveOwnedBy(CmsUser user)
Returnstrue
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)
Returnstrue
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()
Returnstrue
if this is an inherited lock, which may either be directly or shared inherited.boolean
isInProject(CmsProject project)
Returnstrue
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()
boolean
isOwnedBy(CmsUser user)
Returnstrue
if the given user is the owner of this lock.boolean
isOwnedInProjectBy(CmsUser user, CmsProject project)
Returnstrue
if the given user is the owner of this lock, and this lock belongs to the given project.boolean
isPersistent()
Returnstrue
if this is a persistent lock that should be saved when the systems shuts down.boolean
isPublish()
Returnstrue
if this is a publish lock.boolean
isShared()
Returnstrue
if this is a shared lock.boolean
isSystemLock()
Returnstrue
if this is a system (2nd level) lock.boolean
isTemporary()
Returnstrue
if this is a temporary lock.boolean
isUnlocked()
Returnstrue
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.
-
-
-
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 rootuserId
- the ID of the user who locked the resourceproject
- the project where the resource is lockedtype
- flag indicating how the resource is locked
-
-
Method Detail
-
getNullLock
public static CmsLock getNullLock()
Returns the shared Null CmsLock.- Returns:
- the shared Null CmsLock
-
compareTo
public int compareTo(CmsLock other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<CmsLock>
- See Also:
Comparable.compareTo(java.lang.Object)
-
equals
public boolean equals(java.lang.Object obj)
Compares this lock to the specified object.- Overrides:
equals
in classjava.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 classjava.lang.Object
- See Also:
Object.hashCode()
-
isDirectlyInherited
public boolean isDirectlyInherited()
Returnstrue
if this is an directly inherited lock.- Returns:
true
if this is an directly inherited lock
-
isDirectlyOwnedBy
public boolean isDirectlyOwnedBy(CmsUser user)
Returnstrue
if this is an exclusive, temporary exclusive, or directly inherited 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, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock
-
isDirectlyOwnedInProjectBy
public boolean isDirectlyOwnedInProjectBy(CmsObject cms)
Returnstrue
if this is an exclusive, temporary exclusive, or directly inherited lock, and the current user is the owner of this lock, checking also the project of the lock.- Parameters:
cms
- the CMS context to check- Returns:
true
if this is an exclusive, temporary exclusive, or directly inherited lock, and the current user is the owner of this lock
-
isDirectlyOwnedInProjectBy
public boolean isDirectlyOwnedInProjectBy(CmsUser user, CmsProject project)
Returnstrue
if this is an exclusive, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock, checking also the project of the lock.- Parameters:
user
- the user to compare to the owner of this lockproject
- the project to compare to the project of this lock- Returns:
true
if this is an exclusive, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock
-
isExclusive
public boolean isExclusive()
Returnstrue
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)
Returnstrue
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)
Returnstrue
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 lockproject
- 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()
Returnstrue
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)
Returnstrue
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()
Returnstrue
if this lock is theNULL
lock which can be obtained bygetNullLock()
.Only for the
NULL
lock,isUnlocked()
istrue
.- Returns:
true
if this lock is theNULL
lock
-
isOwnedBy
public boolean isOwnedBy(CmsUser user)
Returnstrue
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)
Returnstrue
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 lockproject
- 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()
Returnstrue
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()
Returnstrue
if this is a publish lock.- Returns:
true
if this is a publish lock
-
isShared
public boolean isShared()
Returnstrue
if this is a shared lock.- Returns:
true
if this is a shared lock
-
isSystemLock
public boolean isSystemLock()
Returnstrue
if this is a system (2nd level) lock.- Returns:
true
if this is a system (2nd level) lock
-
isTemporary
public boolean isTemporary()
Returnstrue
if this is a temporary lock.- Returns:
true
if this is a temporary lock
-
isUnlocked
public boolean isUnlocked()
Returnstrue
if this lock is in fact unlocked.Only if this is
true
, the result lock is equal to theNULL
lock, which can be obtained bygetNullLock()
.- 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 classjava.lang.Object
- See Also:
Object.toString()
-
clone
protected java.lang.Object clone()
- Overrides:
clone
in classjava.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
-
-