KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (C) Copyright SimulacraMedia 2003. All rights reserved.
3  *
4  *
5  */

6 package org.openharmonise.rm.commands;
7
8 import org.openharmonise.rm.resources.lifecycle.*;
9
10 /**
11  * Saves the command object, if it implements <code>Editable<code>.
12  *
13  * @author Michael Bell
14  * @version $Revision: 1.3 $
15  *
16  */

17 public class CmdSave extends AbstractCmd {
18
19     /**
20      * Creates an instance of the command
21      *
22      */

23     public CmdSave() {
24         super();
25     }
26
27     /* (non-Javadoc)
28      * @see org.openharmonise.rm.commands.AbstractCmd#execute()
29      */

30     public Object JavaDoc execute(Context context) throws CommandException {
31         if ((m_commandObj instanceof Editable) == false) {
32             throw new InvalidCommandException(
33                 "Command is not valid for this object:" + m_commandObj.getClass());
34         }
35
36         if (isAvailable(context) == false) {
37           throw new InvalidCommandException("Command is not available for this object");
38         }
39         
40         Editable eObj = (Editable) getCommandObject(context);
41         Editable rtnObj = null;
42
43         try {
44             rtnObj = eObj.save();
45         } catch (Exception JavaDoc e) {
46             throw new CommandException("Problem executing save", e);
47         }
48         
49         addResultContext(rtnObj, context);
50
51         logCommand(context);
52
53         return rtnObj;
54     }
55
56     /* (non-Javadoc)
57      * @see org.openharmonise.rm.commands.AbstractCmd#getName()
58      */

59     public String JavaDoc getName() {
60
61         return "Save";
62     }
63
64     /* (non-Javadoc)
65      * @see org.openharmonise.rm.commands.AbstractCmd#isValidCommandObject(java.lang.Object)
66      */

67     public boolean isValidCommandObject(Object JavaDoc obj) {
68         return (obj instanceof Editable);
69     }
70 }
Popular Tags