01: package de.schlund.pfixcore.workflow;
02:
03: import java.util.HashMap;
04:
05: import de.schlund.pfixxml.XMLException;
06:
07: /**
08: * Describe class ContextInterceptorFactory here.
09: *
10: *
11: * Created: Wed Apr 20 12:15:15 2005
12: *
13: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
14: * @version 1.0
15: */
16: public class ContextInterceptorFactory {
17: private HashMap<String, ContextInterceptor> icmap = new HashMap<String, ContextInterceptor>();
18: private static ContextInterceptorFactory instance = new ContextInterceptorFactory();
19:
20: /**
21: * Creates a new <code>ContextInterceptorFactory</code> instance.
22: *
23: */
24: private ContextInterceptorFactory() {
25: }
26:
27: public static ContextInterceptorFactory getInstance() {
28: return instance;
29: }
30:
31: public ContextInterceptor getInterceptor(String classname)
32: throws Exception {
33: synchronized (icmap) {
34: ContextInterceptor ic = (ContextInterceptor) icmap
35: .get(classname);
36: if (ic == null) {
37: ic = (ContextInterceptor) icmap.get(classname);
38: try {
39: Class<?> stateclass = Class.forName(classname);
40: ic = (ContextInterceptor) stateclass.newInstance();
41: } catch (InstantiationException e) {
42: throw new XMLException(
43: "unable to instantiate class [" + classname
44: + "] :" + e.getMessage());
45: } catch (IllegalAccessException e) {
46: throw new XMLException("unable access class ["
47: + classname + "] :" + e.getMessage());
48: } catch (ClassNotFoundException e) {
49: throw new XMLException("unable to find class ["
50: + classname + "] :" + e.getMessage());
51: } catch (ClassCastException e) {
52: throw new XMLException(
53: "class ["
54: + classname
55: + "] does not implement the interface ContextInterceptor :"
56: + e.getMessage());
57: }
58: icmap.put(classname, ic);
59: }
60: return ic;
61: }
62: }
63:
64: }
|