View Javadoc

1   /*
2    *  Copyright (C) 2003-2005 SINTEF
3    *  Author:  Fredrik Vraalsen (fredrik dot vraalsen at sintef dot no)
4    *  Webpage: http://coras.sourceforge.net/
5    *
6    *  This program is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public License
8    *  as published by the Free Software Foundation; either version 2.1
9    *  of the License, or (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this program; if not, write to the Free
18   *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   *  02111-1307 USA
20   */
21  package no.sintef.lock;
22  
23  import java.text.SimpleDateFormat;
24  import java.util.Calendar;
25  
26  /***
27   * Lock target is already locked by other user.
28   * 
29   * @author Fredrik Vraalsen
30   */
31  public class LockedByOtherUserException extends LockException {
32  
33  	private String lockedBy = null;
34  	private Calendar lockedDate = null;
35  	
36  	/***
37  	 * @param lockedBy
38  	 *            user name of user who owns the lock on the target
39  	 * @param lockedDate
40  	 *            date when target was locked
41  	 */
42  	public LockedByOtherUserException(String lockedBy, Calendar lockedDate) {
43  		super("Locked by user " + lockedBy + " at " + getDateString(lockedDate));
44  		this.lockedBy = lockedBy;
45  		this.lockedDate = lockedDate;
46  	}
47  
48  	/***
49  	 * @return the user name of the user who owns the lock on the target
50  	 */
51  	public String getLockedBy() {
52  		return lockedBy;
53  	}
54  	
55  	/***
56  	 * @return the date when the target was locked
57  	 */
58  	public Calendar getLockedDate() {
59  		return lockedDate;
60  	}
61  	
62  	/***
63  	 * Get formatted date string using default SimpleDateFormat.
64  	 * 
65  	 * @param date
66  	 *            date to format
67  	 * @return formatted date string
68  	 */
69  	private static String getDateString(Calendar date) {
70  		if (date == null) {
71  			return null;
72  		}
73  		return new SimpleDateFormat().format(date.getTime());
74  	}
75  
76  }
77