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

Last change on this file since 1885 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
RevLine 
[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]15package de.ugoe.cs.autoquest.commands.misc;
[87]16
17import java.io.FileOutputStream;
18import java.io.IOException;
19import java.io.ObjectOutputStream;
20import java.util.List;
21
[922]22import de.ugoe.cs.autoquest.CommandHelpers;
[87]23import de.ugoe.cs.util.console.Command;
24import de.ugoe.cs.util.console.Console;
[667]25import de.ugoe.cs.util.console.GlobalDataContainer;
[87]26
[171]27/**
28 * <p>
29 * Command that saves an object contained in the {@link GlobalDataContainer}
30 * through serialization.
31 * </p>
32 *
33 * @author Steffen Herbold
[223]34 * @version 1.0
[171]35 */
[87]36public class CMDsaveObject 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);
[171]50                } catch (Exception e) {
[766]51                        throw new IllegalArgumentException();
[87]52                }
[171]53
54                Object dataObject = GlobalDataContainer.getInstance().getData(
55                                objectName);
56                if (dataObject == null) {
[240]57                        CommandHelpers.objectNotFoundMessage(objectName);
58                        return;
[87]59                }
[171]60
[87]61                FileOutputStream fos = null;
62                ObjectOutputStream out = null;
63                try {
64                        fos = new FileOutputStream(filename);
65                        out = new ObjectOutputStream(fos);
66                        out.writeObject(dataObject);
67                        out.close();
68                } catch (IOException ex) {
[211]69                        Console.logException(ex);
[87]70                }
71        }
72
[171]73        /*
74         * (non-Javadoc)
75         *
76         * @see de.ugoe.cs.util.console.Command#help()
77         */
[87]78        @Override
[664]79        public String help() {
80                return "saveObject <filename> <objectName>";
[87]81        }
82
83}
Note: See TracBrowser for help on using the repository browser.