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.util.HashMap;
23:
24: import org.apache.log4j.Logger;
25:
26: /**
27: * The <code>DirectOutputStateFactory</code> class is a singleton that manages and creates
28: * one instance of each requested DirectOutputState.
29: *
30: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
31: */
32: public class DirectOutputStateFactory {
33: private static HashMap<String, DirectOutputState> knownstates = new HashMap<String, DirectOutputState>();
34: private final static Logger LOG = Logger
35: .getLogger(StateFactory.class);
36: private static DirectOutputStateFactory instance = new DirectOutputStateFactory();
37:
38: private DirectOutputStateFactory() {
39: }
40:
41: /**
42: * The singleton's <code>getInstance</code> method.
43: *
44: * @return The <code>DirectOutputStateFactory</code> instance.
45: */
46: public static DirectOutputStateFactory getInstance() {
47: return instance;
48: }
49:
50: /**
51: *<code>getDirectOutputState</code> returns the matching DirectOutputState for <code>classname</code>.
52: *
53: * @param classname a <code>String</code> value
54: * @return a <code>DirectOutputState</code> value
55: */
56: public DirectOutputState getDirectOutputState(String classname) {
57: synchronized (knownstates) {
58: DirectOutputState retval = (DirectOutputState) knownstates
59: .get(classname);
60: if (retval == null) {
61: try {
62: Class<?> stateclass = Class.forName(classname);
63: retval = (DirectOutputState) stateclass
64: .newInstance();
65: } catch (InstantiationException e) {
66: LOG.error("unable to instantiate class ["
67: + classname + "]", e);
68: } catch (IllegalAccessException e) {
69: LOG.error(
70: "unable access class [" + classname + "]",
71: e);
72: } catch (ClassNotFoundException e) {
73: LOG.error("unable to find class [" + classname
74: + "]", e);
75: } catch (ClassCastException e) {
76: LOG
77: .error(
78: "class ["
79: + classname
80: + "] does not implement the interface DirectOutputState",
81: e);
82: }
83: knownstates.put(classname, retval);
84: }
85: return retval;
86: }
87: }
88: }
|