01: /*
02: * (C) Copyright SimulacraMedia 2003. All rights reserved.
03: *
04: *
05: */
06: package org.openharmonise.rm.commands;
07:
08: import org.openharmonise.rm.resources.lifecycle.*;
09:
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 execute(Context context) throws CommandException {
31: if ((m_commandObj instanceof Editable) == false) {
32: throw new InvalidCommandException(
33: "Command is not valid for this object:"
34: + m_commandObj.getClass());
35: }
36:
37: if (isAvailable(context) == false) {
38: throw new InvalidCommandException(
39: "Command is not available for this object");
40: }
41:
42: Editable eObj = (Editable) getCommandObject(context);
43: Editable rtnObj = null;
44:
45: try {
46: rtnObj = eObj.save();
47: } catch (Exception e) {
48: throw new CommandException("Problem executing save", e);
49: }
50:
51: addResultContext(rtnObj, context);
52:
53: logCommand(context);
54:
55: return rtnObj;
56: }
57:
58: /* (non-Javadoc)
59: * @see org.openharmonise.rm.commands.AbstractCmd#getName()
60: */
61: public String getName() {
62:
63: return "Save";
64: }
65:
66: /* (non-Javadoc)
67: * @see org.openharmonise.rm.commands.AbstractCmd#isValidCommandObject(java.lang.Object)
68: */
69: public boolean isValidCommandObject(Object obj) {
70: return (obj instanceof Editable);
71: }
72: }
|