source: trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDprintDot.java @ 664

Last change on this file since 664 was 664, checked in by sherbold, 12 years ago
  • modified Command.help(): the help now returns a string with its usage instead of writing directly to the console
  • modified listCommands: now writes the help string of each command instead of just the name; this way, the parameters are displayed directly
  • moved listCommands from quest-ui-core to java-utils
File size: 1.4 KB
RevLine 
[434]1package de.ugoe.cs.quest.ui.commands;
[1]2
3import java.security.InvalidParameterException;
4import java.util.List;
5
[432]6import de.ugoe.cs.quest.CommandHelpers;
[434]7import de.ugoe.cs.quest.ui.GlobalDataContainer;
[433]8import de.ugoe.cs.quest.usageprofiles.IDotCompatible;
[1]9import de.ugoe.cs.util.console.Command;
10import de.ugoe.cs.util.console.Console;
11
[171]12/**
13 * <p>
14 * Command that prints a dot representation of a model (if supported) to the
15 * console.
16 * </p>
17 *
18 * @author Steffen Herbold
19 * @version 1.0
20 */
[1]21public class CMDprintDot implements Command {
22
[171]23        /*
24         * (non-Javadoc)
25         *
26         * @see de.ugoe.cs.util.console.Command#help()
27         */
[1]28        @Override
[664]29        public String help() {
30                return "printDot <modelname>";
[1]31        }
32
[171]33        /*
34         * (non-Javadoc)
35         *
36         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
37         */
[1]38        @Override
39        public void run(List<Object> parameters) {
40                String modelname = "";
41                try {
42                        modelname = (String) parameters.get(0);
43                } catch (Exception e) {
44                        throw new InvalidParameterException();
45                }
[171]46
47                IDotCompatible model = null;
48                Object dataObject = GlobalDataContainer.getInstance()
49                                .getData(modelname);
50                if (dataObject == null) {
[240]51                        CommandHelpers.objectNotFoundMessage(modelname);
[209]52                        return;
53                }
54                if (!(dataObject instanceof IDotCompatible)) {
[240]55                        CommandHelpers.objectNotType(modelname, "IDotCompatible");
[209]56                        return;
[1]57                }
[209]58
59                model = (IDotCompatible) dataObject;
60                Console.println(model.getDotRepresentation());
[1]61        }
62
63}
Note: See TracBrowser for help on using the repository browser.