001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.workflow;
021:
022: import java.util.HashMap;
023: import java.util.Iterator;
024:
025: import org.apache.log4j.Logger;
026:
027: import de.schlund.pfixxml.ConfigurableObject;
028: import de.schlund.pfixxml.config.DirectOutputPageRequestConfig;
029: import de.schlund.pfixxml.config.DirectOutputServletConfig;
030:
031: /**
032: * <code>DirectOutputPageMap</code> holds a mapping of PageRequests to DirectOutputStates. It
033: * implements the PropertyObject interface and is created and initialized by a PropertyObjectManager. This
034: * ensures that the the DirectOutputPageMap will be recreated every time the properties change.
035: *
036: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
037: */
038: public class DirectOutputPageMap implements ConfigurableObject {
039: protected HashMap<String, DirectOutputState> pagemap = new HashMap<String, DirectOutputState>();
040: private final static Logger LOG = Logger
041: .getLogger(DirectOutputPageMap.class);
042:
043: /**
044: * The <code>init</code> method initializes a mapping from {@link PageRequest}s to {@link DirectOutputState}s.
045: *
046: * @param confObj a {@link de.schlund.pfixxml.config.DirectOutputServletConfig} object
047: * @exception Exception if an error occurs
048: */
049: public void init(Object confObj) throws Exception {
050: DirectOutputServletConfig config = (DirectOutputServletConfig) confObj;
051:
052: for (DirectOutputPageRequestConfig pConfig : config
053: .getPageRequests()) {
054: Class<? extends DirectOutputState> clazz = pConfig
055: .getState();
056: DirectOutputState state = DirectOutputStateFactory
057: .getInstance()
058: .getDirectOutputState(clazz.getName());
059: if (state == null) {
060: LOG
061: .error("***** Skipping page '"
062: + pConfig.getPageName()
063: + "' as it's corresponding class "
064: + clazz.getName()
065: + " couldn't be initialized by the DirectOutputStateFactory");
066: } else {
067: pagemap.put(pConfig.getPageName(), state);
068: }
069: }
070:
071: }
072:
073: /**
074: * The <code>getDirectOutputState</code> method returns the DirectOutputState that is
075: * associated with the <code>page</code> parameter
076: *
077: * @param page a <code>PageRequest</code> value
078: * @return a <code>DirectOutputState</code> value
079: */
080: public DirectOutputState getDirectOutputState(PageRequest page) {
081: return getDirectOutputState(page.getName());
082: }
083:
084: public DirectOutputState getDirectOutputState(String pagename) {
085: return (DirectOutputState) pagemap.get(pagename);
086: }
087:
088: @Override
089: public String toString() {
090: String ret = "";
091: for (Iterator<String> i = pagemap.keySet().iterator(); i
092: .hasNext();) {
093: if (ret.length() > 0) {
094: ret += ", ";
095: }
096: String key = i.next();
097: ret += key + " -> "
098: + (pagemap.get(key)).getClass().getName();
099: }
100: return ret;
101: }
102:
103: }
|