1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.io.FileInputStream;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.io.ObjectInputStream;
|
---|
6 | import java.security.InvalidParameterException;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.util.console.Command;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * <p>
|
---|
15 | * Command to load a previously serialized object and store it in the
|
---|
16 | * {@link GlobalDataContainer}.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class CMDloadObject implements Command {
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * (non-Javadoc)
|
---|
26 | *
|
---|
27 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
28 | */
|
---|
29 | @Override
|
---|
30 | public void run(List<Object> parameters) {
|
---|
31 | String filename;
|
---|
32 | String objectName;
|
---|
33 | try {
|
---|
34 | filename = (String) parameters.get(0);
|
---|
35 | objectName = (String) parameters.get(1);
|
---|
36 | } catch (Exception e) {
|
---|
37 | throw new InvalidParameterException();
|
---|
38 | }
|
---|
39 |
|
---|
40 | Object data = null;
|
---|
41 | FileInputStream fis = null;
|
---|
42 | ObjectInputStream in = null;
|
---|
43 | try {
|
---|
44 | fis = new FileInputStream(filename);
|
---|
45 | in = new ObjectInputStream(fis);
|
---|
46 | data = in.readObject();
|
---|
47 | in.close();
|
---|
48 | } catch (IOException ex) {
|
---|
49 | Console.logException(ex);
|
---|
50 | } catch (ClassNotFoundException ex) {
|
---|
51 | Console.logException(ex);
|
---|
52 | }
|
---|
53 | if (GlobalDataContainer.getInstance().addData(objectName, data)) {
|
---|
54 | Console.traceln("Old data \"" + objectName + "\" overwritten");
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * (non-Javadoc)
|
---|
60 | *
|
---|
61 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
62 | */
|
---|
63 | @Override
|
---|
64 | public void help() {
|
---|
65 | Console.println("Usage: loadObject <filename> <objectName>");
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|