KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > commands > CmdUnlock


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.rm.commands;
20
21 import org.openharmonise.rm.resources.lifecycle.*;
22 import org.openharmonise.rm.resources.users.*;
23
24
25 /**
26  * Unlocks the command object, if it implements <code>Editable</code> and has
27  * been locked by the user executing the unlock.
28  *
29  * <p>Note: A super user can unlock any locked object.</p>
30  *
31  * @author Michael Bell
32  * @version $Revision: 1.3 $
33  *
34  */

35 public class CmdUnlock extends AbstractCmd {
36
37     /**
38      * Creates an instance of the command.
39      *
40      */

41     public CmdUnlock() {
42         super();
43     }
44
45     /* (non-Javadoc)
46      * @see org.openharmonise.rm.commands.AbstractCmd#execute()
47      */

48     public Object JavaDoc execute(Context context) throws CommandException {
49         if ((m_commandObj instanceof Editable) == false) {
50             throw new InvalidCommandException(
51                     "Command is not valid for this object:"
52                             + m_commandObj.getClass());
53         }
54
55         User usr = getExecutingUser();
56
57         if (usr == null) {
58             throw new InvalidCommandException(
59                     "Command is not valid with out specifying a user");
60         }
61
62         if (isAvailable(context) == false) {
63             throw new InvalidCommandException(
64                     "Command is not available for this object");
65         }
66
67         Editable editable = (Editable) getCommandObject(context);
68
69         try {
70             editable.unlock(usr);
71         } catch(InvalidLockOwnerException e) {
72             throw new InvalidCommandException(e);
73         } catch (EditException e) {
74             throw new CommandException("Error locking object", e);
75         }
76
77         logCommand(context);
78
79         return null;
80     }
81
82     /* (non-Javadoc)
83      * @see org.openharmonise.rm.commands.AbstractCmd#getName()
84      */

85     public String JavaDoc getName() {
86         return "Unlock";
87     }
88
89     /* (non-Javadoc)
90      * @see org.openharmonise.rm.commands.AbstractCmd#isValidCommandObject(java.lang.Object)
91      */

92     public boolean isValidCommandObject(Object JavaDoc obj) {
93         return (obj instanceof Editable);
94     }
95 }
Popular Tags