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: import java.util.Iterator;
24:
25: import org.apache.log4j.Logger;
26:
27: import de.schlund.pfixxml.config.ContextConfig;
28: import de.schlund.pfixxml.config.PageRequestConfig;
29:
30: public class PageMap {
31:
32: protected HashMap<String, State> pagemap = new HashMap<String, State>();
33: private final static Logger LOG = Logger.getLogger(PageMap.class);
34:
35: public PageMap(ContextConfig config) {
36:
37: for (PageRequestConfig pageConfig : config
38: .getPageRequestConfigs()) {
39: String page = pageConfig.getPageName();
40: Class<? extends State> stateClass = pageConfig.getState();
41: State state = StateFactory.getInstance().getState(
42: stateClass.getName());
43:
44: if (state == null) {
45: LOG
46: .error("***** Skipping page '"
47: + page
48: + "' as it's corresponding class "
49: + stateClass.getName()
50: + "couldn't be initialized by the StateFactory");
51: } else {
52: pagemap.put(page, state);
53: }
54: }
55:
56: }
57:
58: public State getState(PageRequest page) {
59: return getState(page.getName());
60: }
61:
62: public State getState(String pagename) {
63: return (State) pagemap.get(pagename);
64: }
65:
66: @Override
67: public String toString() {
68: String ret = "";
69: for (Iterator<String> i = pagemap.keySet().iterator(); i
70: .hasNext();) {
71: if (ret.length() > 0) {
72: ret += ", ";
73: }
74: String key = i.next();
75: ret += key + " -> " + pagemap.get(key).getClass().getName();
76: }
77: return ret;
78: }
79:
80: }
|