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.context;
021:
022: import java.util.ArrayList;
023: import java.util.HashMap;
024:
025: import org.apache.log4j.Logger;
026:
027: import de.schlund.pfixcore.workflow.FlowStep;
028: import de.schlund.pfixxml.config.PageFlowConfig;
029: import de.schlund.pfixxml.config.PageFlowStepConfig;
030:
031: /**
032: * @author: jtl
033: *
034: */
035:
036: public class PageFlow {
037: private String flowname;
038: private String rootname;
039: private ArrayList<FlowStep> allsteps = new ArrayList<FlowStep>();
040: private HashMap<String, FlowStep> stepmap = new HashMap<String, FlowStep>();
041: private String finalpage;
042:
043: private final static Logger LOG = Logger.getLogger(PageFlow.class);
044:
045: public PageFlow(PageFlowConfig config) {
046: flowname = config.getFlowName();
047: if (flowname.indexOf("::") > 0) {
048: rootname = flowname.substring(0, flowname.indexOf("::"));
049: } else {
050: rootname = flowname;
051: }
052:
053: finalpage = config.getFinalPage();
054:
055: for (PageFlowStepConfig stepConfig : config.getFlowSteps()) {
056: FlowStep step = new FlowStep(stepConfig);
057: allsteps.add(step);
058: stepmap.put(step.getPageName(), step);
059: }
060:
061: if (LOG.isDebugEnabled()) {
062: for (int i = 0; i < allsteps.size(); i++) {
063: LOG.debug(">>> Workflow '" + config.getFlowName()
064: + "' Step #" + i + " " + allsteps.get(i));
065: }
066: }
067: }
068:
069: public boolean containsPage(String page) {
070: return stepmap.keySet().contains(page);
071: }
072:
073: /**
074: * Return position of page in the PageFlow, starting with 0. Return -1 if
075: * page isn't a member of the PageFlow.
076: *
077: * @param page a <code>String</code> value
078: * @return an <code>int</code> value
079: */
080: public int getIndexOfPage(String page) {
081: FlowStep step = (FlowStep) stepmap.get(page);
082: if (step != null) {
083: return allsteps.indexOf(step);
084: } else {
085: return -1;
086: }
087: }
088:
089: public String getName() {
090: return flowname;
091: }
092:
093: public String getRootName() {
094: return rootname;
095: }
096:
097: public FlowStep[] getAllSteps() {
098: return (FlowStep[]) allsteps.toArray(new FlowStep[] {});
099: }
100:
101: public FlowStep getFlowStepForPage(String page) {
102: return (FlowStep) stepmap.get(page);
103: }
104:
105: public FlowStep getFirstStep() {
106: return (FlowStep) allsteps.get(0);
107: }
108:
109: public String getFinalPage() {
110: return finalpage;
111: }
112:
113: public String toString() {
114: String ret = "";
115: for (int i = 0; i < allsteps.size(); i++) {
116: if (ret.length() > 0) {
117: ret += ", ";
118: } else {
119: ret = flowname + " = ";
120: }
121: ret += "[" + i + ": " + allsteps.get(i) + "]";
122: }
123: if (finalpage != null) {
124: ret += " FINAL: " + finalpage;
125: }
126:
127: return ret;
128: }
129:
130: }
|