1 31 32 package org.opencms.lock; 33 34 import org.opencms.db.CmsDbUtil; 35 import org.opencms.util.CmsUUID; 36 37 58 public class CmsLock implements Cloneable { 59 60 61 public static final int COMMON = 0; 62 63 64 public static final int TEMPORARY = 1; 65 66 72 public static final int TYPE_EXCLUSIVE = 4; 73 74 77 public static final int TYPE_INHERITED = 3; 78 79 86 public static final int TYPE_SHARED_EXCLUSIVE = 2; 87 88 95 public static final int TYPE_SHARED_INHERITED = 1; 96 97 100 public static final int TYPE_UNLOCKED = 0; 101 102 103 private static final CmsLock NULL_LOCK = new CmsLock( 104 "", 105 CmsUUID.getNullUUID(), 106 CmsDbUtil.UNKNOWN_ID, 107 CmsLock.TYPE_UNLOCKED); 108 109 110 private int m_mode; 111 112 113 private int m_projectId; 114 115 116 private String m_resourceName; 117 118 119 private int m_type; 120 121 122 private CmsUUID m_userId; 123 124 132 public CmsLock(String resourceName, CmsUUID userId, int projectId, int type) { 133 134 m_resourceName = resourceName; 135 m_userId = userId; 136 m_projectId = projectId; 137 m_type = type; 138 m_mode = COMMON; 139 } 140 141 150 public CmsLock(String resourceName, CmsUUID userId, int projectId, int type, int mode) { 151 152 m_resourceName = resourceName; 153 m_userId = userId; 154 m_projectId = projectId; 155 m_type = type; 156 m_mode = mode; 157 } 158 159 164 public static CmsLock getNullLock() { 165 166 return CmsLock.NULL_LOCK; 167 } 168 169 175 public boolean equals(Object obj) { 176 177 if (obj == this) { 178 return true; 179 } 180 if (obj instanceof CmsLock) { 181 CmsLock other = (CmsLock)obj; 182 return other.m_resourceName.equals(m_resourceName) 183 && other.m_userId.equals(m_userId) 184 && (other.m_projectId == m_projectId); 185 } 186 return false; 187 } 188 189 194 public int getMode() { 195 196 return m_mode; 197 } 198 199 204 public int getProjectId() { 205 206 return m_projectId; 207 } 208 209 214 public String getResourceName() { 215 216 return m_resourceName; 217 } 218 219 224 public int getType() { 225 226 return m_type; 227 } 228 229 234 public CmsUUID getUserId() { 235 236 return m_userId; 237 } 238 239 242 public int hashCode() { 243 244 return getResourceName().hashCode(); 245 } 246 247 252 public boolean isNullLock() { 253 254 return this.equals(CmsLock.NULL_LOCK); 255 } 256 257 262 public String toString() { 263 264 StringBuffer buf = new StringBuffer (); 265 266 buf.append("resource: "); 267 buf.append(this.getResourceName()); 268 buf.append(" type: "); 269 switch (this.getType()) { 270 case CmsLock.TYPE_EXCLUSIVE: 271 buf.append("exclusive"); 272 break; 273 case CmsLock.TYPE_SHARED_EXCLUSIVE: 274 buf.append("shared exclusive"); 275 break; 276 case CmsLock.TYPE_INHERITED: 277 buf.append("inherited"); 278 break; 279 case CmsLock.TYPE_SHARED_INHERITED: 280 buf.append("shared inherited"); 281 break; 282 default: 283 buf.append("unlocked"); 284 break; 285 } 286 buf.append(" project: "); 287 buf.append(this.getProjectId()); 288 buf.append(" user: "); 289 buf.append(this.getUserId()); 290 291 return buf.toString(); 292 } 293 } 294 | Popular Tags |