001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.shared; 029 030import com.google.gwt.user.client.rpc.IsSerializable; 031 032/** 033 * Client side lock class.<p> 034 * 035 * @since 8.0.0 036 */ 037public class CmsClientLock implements IsSerializable { 038 039 /** 040 * The available lock types. Replace with {@link org.opencms.lock.CmsLockType} as soon that fulfills the serializable convention. 041 */ 042 public enum LockType { 043 /** 044 * A lock that allows the user to edit the resource's structure record, 045 * it's resource record, and its content record.<p> 046 * 047 * This lock is assigned to files that are locked via the context menu. 048 */ 049 EXCLUSIVE(4), 050 051 /** A lock that is inherited from a locked parent folder. */ 052 INHERITED(3), 053 054 /** A lock that indicates that the resource is waiting to be published in the publish queue. */ 055 PUBLISH(7), 056 057 /** 058 * A lock that allows the user to edit the resource's structure record only, 059 * but not it's resource record nor content record.<p> 060 * 061 * This lock is assigned to files if a sibling of the resource record has 062 * already an exclusive lock. 063 */ 064 SHARED_EXCLUSIVE(2), 065 066 /** 067 * A lock that allows the user to edit the resource's structure record only, 068 * but not it's resource record nor content record.<p> 069 * 070 * This lock is assigned to resources that already have a shared exclusive lock, 071 * and then inherit a lock because one if it's parent folders gets locked. 072 */ 073 SHARED_INHERITED(1), 074 075 /** 076 * A temporary exclisive lock that allows the user to edit the resource's structure record, 077 * it's resource record, and its content record.<p> 078 * 079 * This lock is identical to the {@link #EXCLUSIVE} lock, but it is automatically removed after 080 * a user is logged out.<p> 081 */ 082 TEMPORARY(6), 083 084 /** Type of the NULL lock obtained by {@link org.opencms.lock.CmsLock#getNullLock()}. */ 085 SYSTEM_UNLOCKED(8), 086 087 /** Type of the NULL system lock. */ 088 UNLOCKED(0); 089 090 /** The lock mode/type. */ 091 private int m_mode; 092 093 /** 094 * Constructor.<p> 095 * 096 * @param mode the lock mode/type 097 */ 098 LockType(int mode) { 099 100 m_mode = mode; 101 } 102 103 /** 104 * Returns the lock type according to the given mode.<p> 105 * 106 * @param mode the lock mode/type int 107 * 108 * @return the lock type 109 */ 110 public static LockType valueOf(int mode) { 111 112 switch (mode) { 113 case 1: 114 return SHARED_INHERITED; 115 case 2: 116 return SHARED_EXCLUSIVE; 117 case 3: 118 return INHERITED; 119 case 4: 120 return EXCLUSIVE; 121 case 6: 122 return TEMPORARY; 123 case 7: 124 return PUBLISH; 125 case 8: 126 return SYSTEM_UNLOCKED; 127 default: 128 return UNLOCKED; 129 } 130 } 131 132 /** 133 * Returns <code>true</code> if this lock is in fact unlocked.<p> 134 * 135 * Only if this is <code>true</code>, the result lock is equal to the <code>NULL</code> lock, 136 * which can be obtained by {@link org.opencms.lock.CmsLock#getNullLock()}.<p> 137 * 138 * @return <code>true</code> if this lock is in fact unlocked 139 */ 140 public boolean isUnlocked() { 141 142 return ((this == UNLOCKED) || (this == SYSTEM_UNLOCKED)); 143 } 144 145 /** 146 * @see java.lang.Object#toString() 147 */ 148 @Override 149 public String toString() { 150 151 switch (m_mode) { 152 case 1: 153 return "shared inherited"; 154 case 2: 155 return "shared exclusive"; 156 case 3: 157 return "inherited"; 158 case 4: 159 return "exclusive"; 160 case 6: 161 return "temporary exclusive"; 162 case 7: 163 return "publish"; 164 case 8: 165 return "system unlocked"; 166 default: 167 return "unlocked"; 168 } 169 } 170 171 /** 172 * Return the lock mode/type.<p> 173 * 174 * @return the lock mode/type 175 */ 176 public int getMode() { 177 178 return m_mode; 179 } 180 } 181 182 /** Flag to indicate if the current lock is owned by the current user. */ 183 private boolean m_isOwnedByUser; 184 185 /** The lock owner name. */ 186 private String m_lockOwner; 187 188 /** The lock type. */ 189 private LockType m_lockType; 190 191 /** 192 * Default constructor for serialization.<p> 193 */ 194 public CmsClientLock() { 195 196 // nothing to do 197 } 198 199 /** 200 * Returns the lock owner name.<p> 201 * 202 * @return the lock owner name 203 */ 204 public String getLockOwner() { 205 206 return m_lockOwner; 207 } 208 209 /** 210 * Returns the lock type.<p> 211 * 212 * @return the lock type 213 */ 214 public LockType getLockType() { 215 216 return m_lockType; 217 } 218 219 /** 220 * Returns if the current lock is owned by the current user.<p> 221 * 222 * @return if the current lock is owned by the current user 223 */ 224 public boolean isOwnedByUser() { 225 226 return m_isOwnedByUser; 227 } 228 229 /** 230 * Sets the lock owner name.<p> 231 * 232 * @param lockOwner the lock owner name to set 233 */ 234 public void setLockOwner(String lockOwner) { 235 236 m_lockOwner = lockOwner; 237 } 238 239 /** 240 * Sets the lock type.<p> 241 * 242 * @param lockType the lock type to set 243 */ 244 public void setLockType(LockType lockType) { 245 246 m_lockType = lockType; 247 } 248 249 /** 250 * Sets if the current lock is owned by the current user.<p> 251 * 252 * @param isOwnedByUser if the current lock is owned by the current user 253 */ 254 public void setOwnedByUser(boolean isOwnedByUser) { 255 256 m_isOwnedByUser = isOwnedByUser; 257 } 258}