[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.misc;
|
---|
[87] | 16 |
|
---|
| 17 | import java.io.FileInputStream;
|
---|
| 18 | import java.io.IOException;
|
---|
| 19 | import java.io.ObjectInputStream;
|
---|
| 20 | import java.util.List;
|
---|
| 21 |
|
---|
[922] | 22 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
[87] | 23 | import de.ugoe.cs.util.console.Command;
|
---|
| 24 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 25 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[87] | 26 |
|
---|
[171] | 27 | /**
|
---|
| 28 | * <p>
|
---|
| 29 | * Command to load a previously serialized object and store it in the
|
---|
| 30 | * {@link GlobalDataContainer}.
|
---|
| 31 | * </p>
|
---|
| 32 | *
|
---|
| 33 | * @author Steffen Herbold
|
---|
| 34 | * @version 1.0
|
---|
| 35 | */
|
---|
[87] | 36 | public class CMDloadObject implements Command {
|
---|
| 37 |
|
---|
[171] | 38 | /*
|
---|
| 39 | * (non-Javadoc)
|
---|
| 40 | *
|
---|
| 41 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 42 | */
|
---|
[87] | 43 | @Override
|
---|
| 44 | public void run(List<Object> parameters) {
|
---|
| 45 | String filename;
|
---|
| 46 | String objectName;
|
---|
| 47 | try {
|
---|
| 48 | filename = (String) parameters.get(0);
|
---|
| 49 | objectName = (String) parameters.get(1);
|
---|
| 50 | } catch (Exception e) {
|
---|
[766] | 51 | throw new IllegalArgumentException();
|
---|
[87] | 52 | }
|
---|
| 53 |
|
---|
| 54 | Object data = null;
|
---|
| 55 | FileInputStream fis = null;
|
---|
| 56 | ObjectInputStream in = null;
|
---|
| 57 | try {
|
---|
| 58 | fis = new FileInputStream(filename);
|
---|
| 59 | in = new ObjectInputStream(fis);
|
---|
| 60 | data = in.readObject();
|
---|
| 61 | in.close();
|
---|
| 62 | } catch (IOException ex) {
|
---|
[211] | 63 | Console.logException(ex);
|
---|
[87] | 64 | } catch (ClassNotFoundException ex) {
|
---|
[211] | 65 | Console.logException(ex);
|
---|
[87] | 66 | }
|
---|
[171] | 67 | if (GlobalDataContainer.getInstance().addData(objectName, data)) {
|
---|
[240] | 68 | CommandHelpers.dataOverwritten(objectName);
|
---|
[87] | 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[171] | 72 | /*
|
---|
| 73 | * (non-Javadoc)
|
---|
| 74 | *
|
---|
| 75 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 76 | */
|
---|
[87] | 77 | @Override
|
---|
[664] | 78 | public String help() {
|
---|
| 79 | return "loadObject <filename> <objectName>";
|
---|
[87] | 80 | }
|
---|
| 81 |
|
---|
| 82 | }
|
---|