/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: TypicalProcessManager.java 2548 2007-10-22 14:00:52Z $
*/
package load;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.api.DefaultProcessData;
/**
* This class supports the generation and initialization of typical processes.
*
* @author <a href="weidauer@danet.de">Christian Weidauer</a>
* @version $Revision: 2548 $
*/
public class TypicalProcessManager {
public static final TypicalProcessManager STARTER
= new TypicalProcessManager(true, true);
public static final TypicalProcessManager INITIALIZER
= new TypicalProcessManager(true, false);
public static final TypicalProcessManager PREPARER
= new TypicalProcessManager(false, false);
private boolean initializeAndCreate = false;
private boolean start = false;
public TypicalProcessManager(boolean initializeAndCreate, boolean start) {
this.initializeAndCreate = initializeAndCreate;
this.start = start;
}
public void generate(TypicalProcess process, int number)
throws Exception {
for (int i = 0; i < number; i++) {
new TypicalProcess(process.initialProcessData(),
initializeAndCreate, start);
}
}
public void generate(TypicalProcess process, int number,
InitialProcessDataAdapter adapter)
throws Exception {
ProcessData pd = new DefaultProcessData(process.initialProcessData());
int counterForNotStartedProcesses = 0;
for (int i = 0; i < number; i++) {
adapter.adapt(pd, i, number);
try {
new TypicalProcess(pd, initializeAndCreate, start);
} catch (Exception e) {
System.out.println
("Error when creating " + i + "th process: " + e);
counterForNotStartedProcesses++;
}
}
System.out.println((number - counterForNotStartedProcesses)
+ " of " + number + " processes generated.");
}
public static InitialProcessDataAdapter createAdapter(String dataField,
int start, int end) {
return new InitialProcessDataAdapter(dataField, start, end);
}
public static class InitialProcessDataAdapter {
private String dataField;
private int start;
private int end;
private InitialProcessDataAdapter additionalAdapter = null;
public InitialProcessDataAdapter(String dataField, int start, int end) {
this.dataField = dataField;
this.start = start;
this.end = end;
}
public void adapt(ProcessData pd, int pos, int number) {
int value = (int) (start + 1.0 * pos / (number) * (end - start));
pd.put(dataField, new Integer(value));
if (additionalAdapter != null) {
additionalAdapter.adapt(pd, pos, number);
}
}
public InitialProcessDataAdapter add
(InitialProcessDataAdapter additionalAdapter) {
this.additionalAdapter = additionalAdapter;
return this;
}
}
}