source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/misc/CMDloadObject.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 2.2 KB
Line 
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
15package de.ugoe.cs.autoquest.commands.misc;
16
17import java.io.FileInputStream;
18import java.io.IOException;
19import java.io.ObjectInputStream;
20import java.util.List;
21
22import de.ugoe.cs.autoquest.CommandHelpers;
23import de.ugoe.cs.util.console.Command;
24import de.ugoe.cs.util.console.Console;
25import de.ugoe.cs.util.console.GlobalDataContainer;
26
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 */
36public class CMDloadObject implements Command {
37
38        /*
39         * (non-Javadoc)
40         *
41         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
42         */
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) {
51                        throw new IllegalArgumentException();
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) {
63                        Console.logException(ex);
64                } catch (ClassNotFoundException ex) {
65                        Console.logException(ex);
66                }
67                if (GlobalDataContainer.getInstance().addData(objectName, data)) {
68                        CommandHelpers.dataOverwritten(objectName);
69                }
70        }
71
72        /*
73         * (non-Javadoc)
74         *
75         * @see de.ugoe.cs.util.console.Command#help()
76         */
77        @Override
78        public String help() {
79                return "loadObject <filename> <objectName>";
80        }
81
82}
Note: See TracBrowser for help on using the repository browser.