[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;
|
---|
[245] | 16 |
|
---|
| 17 | import java.util.List;
|
---|
| 18 |
|
---|
[922] | 19 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
[245] | 20 | import de.ugoe.cs.util.console.Command;
|
---|
| 21 | import de.ugoe.cs.util.console.FileOutputListener;
|
---|
[667] | 22 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[245] | 23 |
|
---|
| 24 | /**
|
---|
| 25 | * <p>
|
---|
| 26 | * Command to stop a {@link FileOutputListener}.
|
---|
| 27 | * </p>
|
---|
| 28 | * @author Steffen Herbold
|
---|
| 29 | * @version 1.0
|
---|
| 30 | */
|
---|
| 31 | public class CMDstopFileListener implements Command {
|
---|
| 32 |
|
---|
| 33 | @Override
|
---|
| 34 | public void run(List<Object> parameters) {
|
---|
| 35 | String filename;
|
---|
| 36 | try {
|
---|
| 37 | filename = (String) parameters.get(0);
|
---|
| 38 | } catch (Exception e) {
|
---|
[766] | 39 | throw new IllegalArgumentException();
|
---|
[245] | 40 | }
|
---|
| 41 |
|
---|
| 42 | Object dataObject = GlobalDataContainer.getInstance().getData(filename);
|
---|
| 43 | if( dataObject==null ) {
|
---|
| 44 | CommandHelpers.objectNotFoundMessage(filename);
|
---|
| 45 | return;
|
---|
| 46 | }
|
---|
| 47 | if( !(dataObject instanceof FileOutputListener) ) {
|
---|
| 48 | CommandHelpers.objectNotType(filename, "FileOutputListener");
|
---|
| 49 | return;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | FileOutputListener listener = (FileOutputListener) dataObject;
|
---|
| 53 | listener.stop();
|
---|
| 54 | GlobalDataContainer.getInstance().removeData(filename);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | @Override
|
---|
[664] | 58 | public String help() {
|
---|
| 59 | return "stopFileListener <filename>";
|
---|
[245] | 60 |
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | }
|
---|