01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
20: * USA
21: *
22: *
23: * $Id: CommandInterpreter.java 11093 2007-12-21 18:22:22Z mpreston $
24: */
25: package com.bostechcorp.cbesb.runtime.ftp.interpreter;
26:
27: import java.io.File;
28: import java.util.LinkedList;
29: import java.util.Map;
30: import java.util.Queue;
31:
32: import org.apache.commons.net.ftp.FTPClient;
33:
34: /**
35: * @author j.zhang
36: * @version 1.0.0
37: */
38: public class CommandInterpreter {
39:
40: // private Map<String, Map<String, String>> cmdMap = new LinkedHashMap<String, Map<String, String>>();
41: private Queue<Command> cmdQueue = new LinkedList<Command>();
42:
43: public void addCommand(String cmdKey, Map<String, String> paramMap) {
44: // cmdMap.put(cmdKey, paramMap);
45: Command command = new Command();
46: command.setCmdKey(cmdKey);
47: command.setParamMap(paramMap);
48: cmdQueue.add(command);
49: }
50:
51: public void clearCommand() {
52: // cmdMap.clear();
53: cmdQueue.clear();
54: }
55:
56: public Object execute(FTPClient ftp) {
57: // Iterator iterator = cmdMap.keySet().iterator();
58: // Iterator iterator = cmdQueue.iterator();
59: Object obj = null;
60: FtpExecContext context = new FtpExecContext(ftp);
61: while (cmdQueue.size() > 0) {
62: // String cmdKey = (String) iterator.next();
63: // Map<String, String> paramMap = (Map<String, String>) cmdMap.get(cmdKey);
64: // AbstractCommandExpression expression = CommandFacorty.createCommand(cmdKey, paramMap);
65: // expression.execute(ftp);
66: Command command = (Command) cmdQueue.poll();
67: String cmdKey = command.getCmdKey();
68: Map<String, String> paramMap = (Map<String, String>) command
69: .getParamMap();
70: AbstractCommandExpression expression = CommandFactory
71: .createCommand(cmdKey, paramMap);
72: obj = expression.execute(context);
73: if (obj instanceof Exception) {
74: return obj;
75: } else if (obj instanceof Boolean) {
76: if (((Boolean) obj).booleanValue() == false) {
77: return false;
78: }
79: }
80: }
81: return true;
82: }
83: }
|