1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
7 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
8 | import de.ugoe.cs.eventbench.models.IDotCompatible;
|
---|
9 | import de.ugoe.cs.util.console.Command;
|
---|
10 | import de.ugoe.cs.util.console.Console;
|
---|
11 |
|
---|
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 | */
|
---|
21 | public class CMDprintDot implements Command {
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * (non-Javadoc)
|
---|
25 | *
|
---|
26 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
27 | */
|
---|
28 | @Override
|
---|
29 | public void help() {
|
---|
30 | Console.println("Usage: printDot <modelname>");
|
---|
31 | }
|
---|
32 |
|
---|
33 | /*
|
---|
34 | * (non-Javadoc)
|
---|
35 | *
|
---|
36 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
37 | */
|
---|
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 | }
|
---|
46 |
|
---|
47 | IDotCompatible model = null;
|
---|
48 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
49 | .getData(modelname);
|
---|
50 | if (dataObject == null) {
|
---|
51 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
52 | return;
|
---|
53 | }
|
---|
54 | if (!(dataObject instanceof IDotCompatible)) {
|
---|
55 | CommandHelpers.objectNotType(modelname, "IDotCompatible");
|
---|
56 | return;
|
---|
57 | }
|
---|
58 |
|
---|
59 | model = (IDotCompatible) dataObject;
|
---|
60 | Console.println(model.getDotRepresentation());
|
---|
61 | }
|
---|
62 |
|
---|
63 | }
|
---|