01: package com.jat.presentation.controller;
02:
03: import java.util.Hashtable;
04:
05: import com.jat.core.config.Config;
06: import com.jat.core.init.Initable;
07: import com.jat.core.log.LogManager;
08: import java.util.Enumeration;
09:
10: /**
11: * <p>Title: JAT</p>
12: * <p>Description: </p>
13: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
14: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
15: * @author stf
16: * @version 1.0
17: * @since 1.2
18: */
19:
20: public class ActionFactory implements Initable {
21:
22: public void init() throws Exception {
23: LogManager.sendDebug(this .getClass().getName()
24: + "::init: start");
25: String loaderName = Config.getCurrent().getValue(
26: ActionLoader.SECTION, ActionLoader.LOADER_NAME);
27: loader = (ActionLoader) Class.forName(loaderName).newInstance();
28: this .actions = loader.getActionList();
29: manager = this ;
30: LogManager.sendDebug(this .getClass().getName() + "::init: end");
31: }
32:
33: public Enumeration names() {
34: return this .actions.keys();
35: }
36:
37: public Action getAction(String name) {
38: return (Action) actions.get(name);
39: }
40:
41: public Action removeAction(String name) throws Exception {
42: Action action = this .getAction(name);
43: if (action != null) {
44: this .loader.remove(action);
45: return (Action) this .actions.remove(name);
46: }
47: return null;
48: }
49:
50: public Action modifyAction(String name, Action action)
51: throws Exception {
52: Action act = this .getAction(name);
53: if (act != null) {
54: this .loader.modify(name, action);
55: return (Action) this .actions.put(action.getName(), action);
56: }
57: return null;
58: }
59:
60: public void addAction(Action action) throws Exception {
61: if (this .getAction(action.getName()) != null)
62: throw new Exception("Action '" + action.getName()
63: + "' already exists");
64: this .loader.add(action);
65: this .actions.put(action.getName(), action);
66: }
67:
68: public void persist() throws Exception {
69: this .loader.persist();
70: }
71:
72: public static ActionFactory getDefault() {
73: return manager;
74: }
75:
76: private ActionLoader loader;
77: private Hashtable actions;
78: private static ActionFactory manager;
79:
80: /** @link dependency
81: * @stereotype use*/
82: /*# ActionLoader lnkActionLoader; */
83: }
|