001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/repository/CmsRepositoryLockInfo.java,v $
003: * Date : $Date: 2008-02-27 12:05:47 $
004: * Version: $Revision: 1.5 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.repository;
033:
034: import java.util.Date;
035:
036: /**
037: * The class represents a lock to a {@link I_CmsRepositoryItem}.<p>
038: *
039: * @author Peter Bonrad
040: *
041: * @version $Revision: 1.5 $
042: *
043: * @since 6.2.4
044: */
045: public class CmsRepositoryLockInfo {
046:
047: /** The lock scope "exclusive". */
048: public static final String SCOPE_EXCLUSIVE = "exclusive";
049:
050: /** The default scope for locks. */
051: public static final String DEFAULT_SCOPE = SCOPE_EXCLUSIVE;
052:
053: /** Infinite timeout for the lock. */
054: public static final int TIMEOUT_INFINITE_VALUE = -1;
055:
056: /** The lock type "write". */
057: public static final String TYPE_WRITE = "write";
058:
059: /** The default type for locks. */
060: public static final String DEFAULT_TYPE = TYPE_WRITE;
061:
062: /** Default depth is infinite. */
063: public static final int DEPTH_INFINITY_VALUE = 3; // To limit tree browsing a bit
064:
065: /** The lock scope "shared". */
066: public static final String SCOPE_SHARED = "shared";
067:
068: /** The creation date of the lock. */
069: private Date m_creationDate = new Date();
070:
071: /** The depth the lock is valid for (0 for the resource or "Infinity" for inheriting). */
072: private int m_depth = 0;
073:
074: /** The time when the lock expires. */
075: private long m_expiresAt = TIMEOUT_INFINITE_VALUE;
076:
077: /** The owner of the lock. */
078: private String m_owner = "";
079:
080: /** The path of the resource item the lock belongs to. */
081: private String m_path = "/";
082:
083: /** The scope of the lock (shared or exclusive). */
084: private String m_scope = DEFAULT_SCOPE;
085:
086: /** The type of the lock (write or read). */
087: private String m_type = DEFAULT_TYPE;
088:
089: /** The login name of the current user. */
090: private String m_username = "";
091:
092: /**
093: * Empty default constructor.<p>
094: */
095: public CmsRepositoryLockInfo() {
096:
097: // empty default constructor
098: }
099:
100: /**
101: * Returns the creationDate.<p>
102: *
103: * @return the creationDate
104: */
105: public Date getCreationDate() {
106:
107: return m_creationDate;
108: }
109:
110: /**
111: * Returns the depth.<p>
112: *
113: * @return the depth
114: */
115: public int getDepth() {
116:
117: return m_depth;
118: }
119:
120: /**
121: * Returns the expiresAt.<p>
122: *
123: * @return the expiresAt
124: */
125: public long getExpiresAt() {
126:
127: return m_expiresAt;
128: }
129:
130: /**
131: * Returns the owner.<p>
132: *
133: * @return the owner
134: */
135: public String getOwner() {
136:
137: return m_owner;
138: }
139:
140: /**
141: * Returns the path.<p>
142: *
143: * @return the path
144: */
145: public String getPath() {
146:
147: return m_path;
148: }
149:
150: /**
151: * Returns the scope.<p>
152: *
153: * @return the scope
154: */
155: public String getScope() {
156:
157: return m_scope;
158: }
159:
160: /**
161: * Returns the type.<p>
162: *
163: * @return the type
164: */
165: public String getType() {
166:
167: return m_type;
168: }
169:
170: /**
171: * Returns the username.<p>
172: *
173: * @return the username
174: */
175: public String getUsername() {
176:
177: return m_username;
178: }
179:
180: /**
181: * Return true if the lock has expired.
182: *
183: * @return true if the lock has expired
184: */
185: public boolean hasExpired() {
186:
187: return (System.currentTimeMillis() > m_expiresAt);
188: }
189:
190: /**
191: * Return true if the lock is exclusive.
192: *
193: * @return true if the lock is exclusive
194: */
195: public boolean isExclusive() {
196:
197: return (m_scope.equals("exclusive"));
198:
199: }
200:
201: /**
202: * Sets the depth.<p>
203: *
204: * @param depth the depth to set
205: */
206: public void setDepth(int depth) {
207:
208: m_depth = depth;
209: }
210:
211: /**
212: * Sets the expiresAt.<p>
213: *
214: * @param expiresAt the expiresAt to set
215: */
216: public void setExpiresAt(long expiresAt) {
217:
218: m_expiresAt = expiresAt;
219: }
220:
221: /**
222: * Sets the owner.<p>
223: *
224: * @param owner the owner to set
225: */
226: public void setOwner(String owner) {
227:
228: m_owner = owner;
229: }
230:
231: /**
232: * Sets the path.<p>
233: *
234: * @param path the path to set
235: */
236: public void setPath(String path) {
237:
238: m_path = path;
239: }
240:
241: /**
242: * Sets the scope.<p>
243: *
244: * @param scope the scope to set
245: */
246: public void setScope(String scope) {
247:
248: m_scope = scope;
249: }
250:
251: /**
252: * Sets the type.<p>
253: *
254: * @param type the type to set
255: */
256: public void setType(String type) {
257:
258: m_type = type;
259: }
260:
261: /**
262: * Sets the username.<p>
263: *
264: * @param username the username to set
265: */
266: public void setUsername(String username) {
267:
268: m_username = username;
269: }
270:
271: /**
272: * Get a string representation of this lock info.<p>
273: *
274: * @return a string representation of this lock
275: */
276: public String toString() {
277:
278: String result = "Type:" + m_type + "\n";
279: result += "Scope:" + m_scope + "\n";
280: result += "Depth:" + m_depth + "\n";
281: result += "Owner:" + m_owner + "\n";
282: result += "Expiration:" + new Date(m_expiresAt) + "\n";
283:
284: return result;
285: }
286: }
|