01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.workflow;
21:
22: import java.lang.reflect.Constructor;
23: import java.lang.reflect.InvocationTargetException;
24:
25: import org.apache.log4j.Logger;
26:
27: import de.schlund.pfixxml.util.Misc;
28:
29: /**
30: * @author: jtl
31: *
32: */
33:
34: public class FlowStepActionFactory {
35: private final static Logger LOG = Logger
36: .getLogger(FlowStepActionFactory.class);
37: private static FlowStepActionFactory instance = new FlowStepActionFactory();
38: private static String JUMPTO = "jumpto";
39: private static String SETFLOW = "setflow";
40: private static String STOP = "stop";
41:
42: private FlowStepActionFactory() {
43: }
44:
45: public static FlowStepActionFactory getInstance() {
46: return instance;
47: }
48:
49: public FlowStepAction createAction(String action) {
50: FlowStepAction act = null;
51: if (action.equals(JUMPTO)) {
52: act = new FlowStepJumpToAction();
53: } else if (action.equals(SETFLOW)) {
54: act = new FlowStepSetFlowAction();
55: } else if (action.equals(STOP)) {
56: act = new FlowStepForceStopAction();
57: } else {
58: try {
59: Constructor<? extends FlowStepAction> constr = Class
60: .forName(action).asSubclass(
61: FlowStepAction.class).getConstructor(
62: Misc.NO_CLASSES);
63: act = constr.newInstance(Misc.NO_OBJECTS);
64: } catch (InstantiationException e) {
65: LOG.error("unable to instantiate class [" + action
66: + "]", e);
67: } catch (IllegalAccessException e) {
68: LOG.error("unable access class [" + action + "]", e);
69: } catch (ClassNotFoundException e) {
70: LOG.error("unable to find class [" + action + "]", e);
71: } catch (NoSuchMethodException e) {
72: LOG.error("unable to find constructor in [" + action
73: + "]", e);
74: } catch (InvocationTargetException e) {
75: LOG.error("unable to invoke constructor in [" + action
76: + "]", e);
77: } catch (ClassCastException e) {
78: LOG
79: .error(
80: "class ["
81: + action
82: + "] does not implement the interface FlowStepAction",
83: e);
84: }
85: }
86: return act;
87: }
88: }
|