[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;
|
---|
[88] | 16 |
|
---|
[2285] | 17 | import java.io.File;
|
---|
[88] | 18 | import java.io.FileInputStream;
|
---|
| 19 | import java.io.IOException;
|
---|
| 20 | import java.io.ObjectInputStream;
|
---|
[2285] | 21 | import java.io.ObjectStreamClass;
|
---|
[88] | 22 | import java.util.List;
|
---|
| 23 |
|
---|
[2285] | 24 | import de.ugoe.cs.autoquest.plugin.AutoQUESTPlugin;
|
---|
| 25 | import de.ugoe.cs.autoquest.plugin.PluginLoader;
|
---|
[88] | 26 | import de.ugoe.cs.util.console.Command;
|
---|
[2285] | 27 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
[88] | 28 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 29 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[88] | 30 |
|
---|
[171] | 31 | /**
|
---|
| 32 | * <p>
|
---|
| 33 | * Command that loads a previously serialized {@link GlobalDataContainer}.
|
---|
| 34 | * </p>
|
---|
| 35 | *
|
---|
| 36 | * @author Steffen Herbold
|
---|
| 37 | * @version 1.0
|
---|
| 38 | */
|
---|
[88] | 39 | public class CMDload implements Command {
|
---|
| 40 |
|
---|
[171] | 41 | /*
|
---|
| 42 | * (non-Javadoc)
|
---|
| 43 | *
|
---|
| 44 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 45 | */
|
---|
[88] | 46 | @Override
|
---|
| 47 | public void run(List<Object> parameters) {
|
---|
| 48 | String filename;
|
---|
| 49 | try {
|
---|
| 50 | filename = (String) parameters.get(0);
|
---|
| 51 | } catch (Exception e) {
|
---|
[766] | 52 | throw new IllegalArgumentException();
|
---|
[88] | 53 | }
|
---|
| 54 |
|
---|
[2285] | 55 | final PluginLoader pluginLoader = new PluginLoader(new File("lib"));
|
---|
| 56 | pluginLoader.load();
|
---|
| 57 |
|
---|
| 58 | FileInputStream fis = null;
|
---|
[88] | 59 | ObjectInputStream in = null;
|
---|
| 60 | try {
|
---|
| 61 | fis = new FileInputStream(filename);
|
---|
[2285] | 62 | in = new ObjectInputStream(fis) {
|
---|
| 63 | @Override
|
---|
| 64 | protected Class<?> resolveClass(ObjectStreamClass clazz)
|
---|
| 65 | throws IOException, ClassNotFoundException
|
---|
| 66 | {
|
---|
| 67 | try {
|
---|
| 68 | return this.getClass().getClassLoader().loadClass(clazz.getName());
|
---|
| 69 | }
|
---|
| 70 | catch (Exception e) {
|
---|
| 71 | for (AutoQUESTPlugin plugin : pluginLoader.getPlugins()) {
|
---|
| 72 | try {
|
---|
| 73 | return plugin.getClass().getClassLoader().loadClass(clazz.getName());
|
---|
| 74 | }
|
---|
| 75 | catch (Exception e2) {
|
---|
| 76 | // ignore and try next
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | throw new ClassNotFoundException("could not load class " + clazz.getName() +
|
---|
| 82 | " neither from normal class loader nor from " +
|
---|
| 83 | "plug in class loaders");
|
---|
| 84 | }
|
---|
| 85 | };
|
---|
[89] | 86 | in.readObject();
|
---|
[88] | 87 | in.close();
|
---|
| 88 | } catch (IOException ex) {
|
---|
[211] | 89 | Console.logException(ex);
|
---|
[88] | 90 | } catch (ClassNotFoundException ex) {
|
---|
[211] | 91 | Console.logException(ex);
|
---|
[88] | 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[171] | 95 | /*
|
---|
| 96 | * (non-Javadoc)
|
---|
| 97 | *
|
---|
| 98 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 99 | */
|
---|
[88] | 100 | @Override
|
---|
[664] | 101 | public String help() {
|
---|
| 102 | return "load <filename>";
|
---|
[88] | 103 | }
|
---|
[171] | 104 |
|
---|
[88] | 105 | }
|
---|