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