01: /*
02: * $Id: XMLCommand.java 674 2006-10-06 12:15:59Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.sf.net).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.client.commandline;
15:
16: import java.beans.XMLDecoder;
17: import java.io.File;
18: import java.io.FileInputStream;
19: import java.io.FileNotFoundException;
20:
21: /**
22: * Run command from XML file.
23: * @version $Revision: 674 $
24: */
25: public class XMLCommand extends Command {
26: String fileName;
27:
28: public String getFileName() {
29: return fileName;
30: }
31:
32: public void setFileName(String fileName) {
33: this .fileName = fileName;
34: }
35:
36: public void setArguments(String[] args) {
37: fileName = args[0];
38: }
39:
40: public void run() {
41: try {
42: File file = new File(fileName);
43: Command command = decode(file);
44: command.setController(controller);
45: command.run();
46: } catch (Exception e) {
47: e.printStackTrace();
48: }
49: }
50:
51: private Command decode(File file) throws FileNotFoundException {
52: FileInputStream in = new FileInputStream(file);
53: XMLDecoder decoder = new XMLDecoder(in);
54: Command command = (Command) decoder.readObject();
55: decoder.close();
56: return command;
57: }
58: }
|