KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Locks the 'command object' for the current user, if it
27  * implements <code>Editable</code>
28  *
29  * @author Michael Bell
30  * @version $Revision: 1.3 $
31  *
32  */

33 public class CmdLock extends AbstractCmd {
34     
35     /**
36      * Creates an instance of the command
37      *
38      */

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

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

75     public String JavaDoc getName() {
76         return "Lock";
77     }
78     
79     /* (non-Javadoc)
80      * @see org.openharmonise.rm.commands.AbstractCmd#isValidCommandObject(java.lang.Object)
81      */

82     public boolean isValidCommandObject(Object JavaDoc obj) {
83         return (obj instanceof Editable);
84     }
85 }
Popular Tags