01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * 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: * Unlocks the command object, if it implements <code>Editable</code> and has
26: * been locked by the user executing the unlock.
27: *
28: * <p>Note: A super user can unlock any locked object.</p>
29: *
30: * @author Michael Bell
31: * @version $Revision: 1.3 $
32: *
33: */
34: public class CmdUnlock extends AbstractCmd {
35:
36: /**
37: * Creates an instance of the command.
38: *
39: */
40: public CmdUnlock() {
41: super ();
42: }
43:
44: /* (non-Javadoc)
45: * @see org.openharmonise.rm.commands.AbstractCmd#execute()
46: */
47: public Object execute(Context context) throws CommandException {
48: if ((m_commandObj instanceof Editable) == false) {
49: throw new InvalidCommandException(
50: "Command is not valid for this object:"
51: + m_commandObj.getClass());
52: }
53:
54: User usr = getExecutingUser();
55:
56: if (usr == null) {
57: throw new InvalidCommandException(
58: "Command is not valid with out specifying a user");
59: }
60:
61: if (isAvailable(context) == false) {
62: throw new InvalidCommandException(
63: "Command is not available for this object");
64: }
65:
66: Editable editable = (Editable) getCommandObject(context);
67:
68: try {
69: editable.unlock(usr);
70: } catch (InvalidLockOwnerException e) {
71: throw new InvalidCommandException(e);
72: } catch (EditException e) {
73: throw new CommandException("Error locking object", e);
74: }
75:
76: logCommand(context);
77:
78: return null;
79: }
80:
81: /* (non-Javadoc)
82: * @see org.openharmonise.rm.commands.AbstractCmd#getName()
83: */
84: public String getName() {
85: return "Unlock";
86: }
87:
88: /* (non-Javadoc)
89: * @see org.openharmonise.rm.commands.AbstractCmd#isValidCommandObject(java.lang.Object)
90: */
91: public boolean isValidCommandObject(Object obj) {
92: return (obj instanceof Editable);
93: }
94: }
|