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.java;
20:
21: import java.util.List;
22: import org.mactor.framework.MactorException;
23: import org.mactor.framework.ReflectionUtil;
24: import org.mactor.framework.TestContextImpl;
25: import org.mactor.framework.commandexecutors.ValueCommandExecutor;
26: import org.mactor.framework.extensioninterface.ValueCommand;
27:
28: public class JavaValueCommandExecutor implements ValueCommandExecutor {
29: private List<String> params;
30: private String command;
31:
32: public JavaValueCommandExecutor(String command, List<String> params) {
33: this .command = command;
34: this .params = params;
35: }
36:
37: private ValueCommand getCommandImpl() throws MactorException {
38: Object c = ReflectionUtil.createInstance(this .command);
39: if (!(c instanceof ValueCommand))
40: throw new MactorException("The command '" + command
41: + "' does not implement the required interface '"
42: + ValueCommand.class.getName() + "'");
43: return (ValueCommand) c;
44: }
45:
46: public String extractValue(TestContextImpl context)
47: throws MactorException {
48: return getCommandImpl().extractValue(context, params);
49: }
50: }
|