1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.cmd.impl;
20
21 import nl.toolforge.karma.core.cmd.CommandDescriptor;
22 import nl.toolforge.karma.core.cmd.CommandException;
23 import nl.toolforge.karma.core.cmd.CommandResponse;
24 import nl.toolforge.karma.core.cmd.DefaultCommand;
25 import nl.toolforge.karma.core.location.LocationException;
26 import nl.toolforge.karma.core.manifest.Manifest;
27 import nl.toolforge.karma.core.manifest.ManifestException;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 import java.util.prefs.BackingStoreException;
32 import java.util.prefs.Preferences;
33
34 /***
35 * <p>This command activates a manifest, which is a general requirement for most other commands. The newly activated
36 * manifest is stored for the Karma session in the {@link nl.toolforge.karma.core.cmd.CommandContext} that is associated
37 * with the Karma session.
38 *
39 * @author W.H. Schraal
40 * @author D.A. Smedes
41 * @version $Id: SelectManifest.java,v 1.25 2004/11/10 22:25:09 hippe Exp $
42 */
43 public class SelectManifest extends DefaultCommand {
44
45 private static Log logger = LogFactory.getLog(SelectManifest.class);
46
47 private CommandResponse commandResponse = new CommandResponse();
48 private Manifest selectedManifest = null;
49
50 public SelectManifest(CommandDescriptor descriptor) {
51 super(descriptor);
52 }
53
54 /***
55 * Activates a manifest.
56 * */
57 public void execute() throws CommandException {
58
59
60
61 try {
62 getContext().changeCurrentManifest(getCommandLine().getOptionValue("m"));
63 selectedManifest = getContext().getCurrentManifest();
64 } catch (ManifestException me) {
65 throw new CommandException(me.getErrorCode(), me.getMessageArguments());
66 } catch (LocationException e) {
67 throw new CommandException(e.getErrorCode(), e.getMessageArguments());
68 }
69
70
71
72 String contextManifest = getWorkingContext().getContextManifestPreference();
73
74 Preferences.userRoot().put(contextManifest, getContext().getCurrentManifest().getName());
75 try {
76 Preferences.userRoot().flush();
77 } catch (BackingStoreException e) {
78 logger.warn("Could not write user preferences due to java.template.prefs.BackingStoreException.");
79 }
80 }
81
82 /***
83 * Gets the commands' response object.
84 *
85 * @return The commands' response object.
86 */
87 public CommandResponse getCommandResponse() {
88 return this.commandResponse;
89 }
90
91 protected Manifest getSelectedManifest() {
92 return selectedManifest;
93 }
94 }