/**
* Copyright 1999-2009 The Pegadi Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pegadi.model;
import java.io.Serializable;
import java.util.Date;
/**
* A class representing a lock for a given article.
* Objects should be created and changed ONLY on the server side.
* Client access must be READ ONLY!
* <code>ArticleLock</code> objects are created, stored and returned
* by {@link org.pegadi.server.ServerImpl#getArticleLock(int, String, boolean)}.
* @author Eirik Bjørsnøs <bjorsnos@underdusken.no>
* @author Øystein Handegard <handegar@underdusken.no>
* @version $Revision$, $Date$
*/
public class ArticleLock implements Serializable {
/** The id of the article that this lock holds */
private int articleID;
/** The session key */
private String sessionKey;
/** When this lock was initially issued */
private Date firstLocked;
/** The hostname this article is locked from */
private String host;
/** The username of the user holding the lock */
private String username;
/** The date when this lock was last renewed */
private Date lastRenewed;
/** Constructor
* @param articleID The ID of the article to lock
* @param sessionKey The session that is locking the article
* @param username The user logged in in this session
* @param host The host the user is logged in from
*/
public ArticleLock(int articleID,
String sessionKey,
String username,
String host) {
this.articleID = articleID;
transfer(sessionKey, username, host);
}
/**
* Transfers a lock from one session to another.
* This means the firstLocked date is updated.
* @param sessionKey the session to transfer the lock to
* @param username the username of the session
* @param host the host of the session
*/
public void transfer(String sessionKey, String username, String host) {
this.sessionKey = sessionKey;
this.firstLocked = new Date();
this.host = host;
this.username = username;
this.lastRenewed = this.firstLocked;
}
/**
* Sets the lastRenewd date to the current date
*/
public void renew() {
this.lastRenewed = new Date();
}
/**
* Returns the date (time) that this lock was created or last tranfered.
* @return the time of creation
*/
public long getFirstLocked() {
return this.firstLocked.getTime();
}
/**
* Returns the time this lock was last renewed.
* If the lock has not been renewed, this method will return the same as
* {@link #getFirstLocked()}.
* @return time when this lock was last renewed
*/
public long getLastRenewed() {
return this.lastRenewed.getTime();
}
/**
* Returns the host the article is locked from.
* @return The host name of the machine the article was locked from.
*/
public String getHost() {
return this.host;
}
/**
* Returns the name of the user that locked this article
* @return the user name
*/
public String getUsername() {
return this.username;
}
/**
* Returns the ID of the locked article
* @return the ID of the article
*/
public int getArticleID() {
return this.articleID;
}
/**
* Returns the session key of the session that has this lock
* @return the session key
*/
public String getSessionKey() {
return this.sessionKey;
}
/**
* Sets the session key of the session that has this lock
* @param sessionKey the session key
*/
public void setSessionKey(String sessionKey) {
this.sessionKey = sessionKey;
}
/**
* Sets the host name the article is locked from.
* @param host the host
*/
public void setHost(String host) {
this.host = host;
}
/**
* Sets the user name that has the current lock
* @param username the user name
*/
public void setUsername(String username) {
this.username = username;
}
}