001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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 * A bean for storing information about whether a resource could be locked or not, and if not, why.<p> 034 * 035 * @since 8.0.0 036 */ 037public class CmsLockInfo implements IsSerializable { 038 039 /** 040 * An enum indicating the success or type of failure of a locking operation.<p> 041 */ 042 public enum State { 043 /** The resource was already locked by another user. */ 044 locked, 045 /** The resource has changed in the meantime. */ 046 changed, 047 /** The resource was successfully locked. */ 048 success, 049 /** Some other error occurred. */ 050 other; 051 } 052 053 /** The state indicating whether (and how) the locking operation succeeded or failed. */ 054 private State m_state; 055 056 /** A user name. */ 057 private String m_user; 058 059 /** An additional error message. */ 060 private String m_exceptionMessage; 061 062 /** 063 * Creates a new lock info bean.<p> 064 * 065 * @param state the state of the locking operation 066 * @param user a user name 067 * @param exceptionMessage an additional error message 068 */ 069 public CmsLockInfo(State state, String user, String exceptionMessage) { 070 071 m_state = state; 072 m_user = user; 073 m_exceptionMessage = exceptionMessage; 074 } 075 076 /** 077 * Empty constructor for serialization.<p> 078 */ 079 protected CmsLockInfo() { 080 081 // do nothing 082 } 083 084 /** 085 * Creates a new info bean for a resource which has changed since it was opened.<p> 086 * 087 * @param user the user by which it was changed 088 * @return the new lock info bean 089 */ 090 public static CmsLockInfo forChangedResource(String user) { 091 092 return new CmsLockInfo(State.changed, user, null); 093 } 094 095 /** 096 * Creates a new info bean for other types of errors.<p> 097 * 098 * @param errorMessage the additional error message 099 * 100 * @return the new lock info bean 101 */ 102 public static CmsLockInfo forError(String errorMessage) { 103 104 return new CmsLockInfo(State.other, null, errorMessage); 105 } 106 107 /** 108 * Returns a lock info bean for a resource locked by another user.<p> 109 * 110 * @param lockUser the other user 111 * 112 * @return the new lock info bean 113 */ 114 public static CmsLockInfo forLockedResource(String lockUser) { 115 116 return new CmsLockInfo(State.locked, lockUser, null); 117 } 118 119 /** 120 * Returns a lock info bean for a successful lock operation.<p> 121 * 122 * @return the new lock info bean 123 */ 124 public static CmsLockInfo forSuccess() { 125 126 return new CmsLockInfo(State.success, null, null); 127 } 128 129 /** 130 * Returns true if the locking succeeded.<p> 131 * 132 * @return true if the locking succeeded 133 */ 134 public boolean couldLock() { 135 136 return m_state == State.success; 137 } 138 139 /** 140 * Returns the additional error message.<p> 141 * 142 * @return the additional error message 143 */ 144 public String getErrorMessage() { 145 146 return m_exceptionMessage; 147 } 148 149 /** 150 * Returns the state of the locking operation.<p> 151 * 152 * @return the state of the locking operation 153 */ 154 public State getState() { 155 156 return m_state; 157 } 158 159 /** 160 * Returns the user name.<p> 161 * 162 * @return a user name 163 */ 164 public String getUser() { 165 166 return m_user; 167 } 168 169}