01: /******************************************************************************
02: * Copyright (C) Lars Ivar Almli. All rights reserved. *
03: * ---------------------------------------------------------------------------*
04: * This file is part of MActor. *
05: * *
06: * MActor is free software; you can redistribute it and/or modify *
07: * it under the terms of the GNU General Public License as published by *
08: * the Free Software Foundation; either version 2 of the License, or *
09: * (at your option) any later version. *
10: * *
11: * MActor is distributed in the hope that it will be useful, *
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14: * GNU General Public License for more details. *
15: * *
16: * You should have received a copy of the GNU General Public License *
17: * along with MActor; if not, write to the Free Software *
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19: ******************************************************************************/package org.mactor.framework.commandexecutors;
20:
21: import java.util.List;
22: import org.mactor.framework.MactorException;
23: import org.mactor.framework.TestContextImpl;
24: import org.mactor.framework.commandexecutors.java.JavaCommandExecutor;
25: import org.mactor.framework.commandexecutors.shell.ShellActionCommandExecutor;
26: import org.mactor.framework.commandexecutors.sql.SqlActionCommandExecutor;
27: import org.mactor.framework.spec.ActionSpec;
28:
29: public class ActionCommandExecutorFactory {
30: public static ActionCommandExecutor createExecutor(
31: TestContextImpl context, ActionSpec spec)
32: throws MactorException {
33: String[] parsed = FactoryUtil.parseCommand(context
34: .substitute(spec.getCommand()));
35: List<String> params = context.substitute(spec.getParams());
36: ActionCommandExecutor c = null;
37: if (FactoryUtil.JAVA.equalsIgnoreCase(parsed[0])) {
38: c = new JavaCommandExecutor(parsed[1], params);
39: } else if (FactoryUtil.SHELL.equalsIgnoreCase(parsed[0])) {
40: c = new ShellActionCommandExecutor(parsed[1], params);
41: } else if (FactoryUtil.SQL.equalsIgnoreCase(parsed[0])) {
42: c = new SqlActionCommandExecutor(parsed[1], params);
43: } else {
44: throw new MactorException("Unsupported command type '"
45: + parsed[0] + "'");
46: }
47: return c;
48: }
49: }
|