001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: TypicalProcessManager.java,v 1.3 2007/03/27 21:59:43 mlipp Exp $
021: */
022: package load;
023:
024: import de.danet.an.workflow.omgcore.ProcessData;
025: import de.danet.an.workflow.api.DefaultProcessData;
026:
027: /**
028: * This class supports the generation and initialization of typical processes.
029: *
030: * @author <a href="weidauer@danet.de">Christian Weidauer</a>
031: * @version $Revision: 1.3 $
032: */
033:
034: public class TypicalProcessManager {
035:
036: public static final TypicalProcessManager STARTER = new TypicalProcessManager(
037: true, true);
038: public static final TypicalProcessManager INITIALIZER = new TypicalProcessManager(
039: true, false);
040: public static final TypicalProcessManager PREPARER = new TypicalProcessManager(
041: false, false);
042:
043: private boolean initializeAndCreate = false;
044: private boolean start = false;
045:
046: public TypicalProcessManager(boolean initializeAndCreate,
047: boolean start) {
048: this .initializeAndCreate = initializeAndCreate;
049: this .start = start;
050: }
051:
052: public void generate(TypicalProcess process, int number)
053: throws Exception {
054: for (int i = 0; i < number; i++) {
055: new TypicalProcess(process.initialProcessData(),
056: initializeAndCreate, start);
057: }
058: }
059:
060: public void generate(TypicalProcess process, int number,
061: InitialProcessDataAdapter adapter) throws Exception {
062: ProcessData pd = new DefaultProcessData(process
063: .initialProcessData());
064: int counterForNotStartedProcesses = 0;
065: for (int i = 0; i < number; i++) {
066: adapter.adapt(pd, i, number);
067: try {
068: new TypicalProcess(pd, initializeAndCreate, start);
069: } catch (Exception e) {
070: System.out.println("Error when creating " + i
071: + "th process: " + e);
072: counterForNotStartedProcesses++;
073: }
074: }
075: System.out.println((number - counterForNotStartedProcesses)
076: + " of " + number + " processes generated.");
077: }
078:
079: public static InitialProcessDataAdapter createAdapter(
080: String dataField, int start, int end) {
081: return new InitialProcessDataAdapter(dataField, start, end);
082: }
083:
084: public static class InitialProcessDataAdapter {
085:
086: private String dataField;
087: private int start;
088: private int end;
089: private InitialProcessDataAdapter additionalAdapter = null;
090:
091: public InitialProcessDataAdapter(String dataField, int start,
092: int end) {
093: this .dataField = dataField;
094: this .start = start;
095: this .end = end;
096: }
097:
098: public void adapt(ProcessData pd, int pos, int number) {
099: int value = (int) (start + 1.0 * pos / (number)
100: * (end - start));
101: pd.put(dataField, new Integer(value));
102: if (additionalAdapter != null) {
103: additionalAdapter.adapt(pd, pos, number);
104: }
105: }
106:
107: public InitialProcessDataAdapter add(
108: InitialProcessDataAdapter additionalAdapter) {
109: this.additionalAdapter = additionalAdapter;
110: return this;
111: }
112: }
113:
114: }
|