TypicalProcess.java :  » Workflow-Engines » wfmopen-2.1.1 » load » Java Open Source

Java Open Source » Workflow Engines » wfmopen 2.1.1 
wfmopen 2.1.1 » load » TypicalProcess.java
/*
 * 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: TypicalProcess.java,v 1.2 2006/09/29 12:32:07 drmlipp Exp $
 */
package load;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.RemoteException;

import javax.security.auth.login.LoginException;

import de.danet.an.workflow.api.DefaultRequester;
import de.danet.an.workflow.api.FactoryConfigurationError;
import de.danet.an.workflow.api.Process;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.ProcessMgr;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.WorkflowServiceFactory;
import de.danet.an.workflow.omgcore.WfRequester;
import de.danet.an.workflow.omgcore.ProcessData; 
import de.danet.an.workflow.api.DefaultProcessData;

import common.STProjectLoginContext;

import junit.framework.TestCase;

/**
 * This class creates, initializes and starts the process P0 of package 
 * TypicalProcess in file TypicalProcess.xml. Furthermore it delives a 
 * corresponding test case for such a process.
 *
 * @author <a href="weidauer@danet.de">Christian Weidauer</a>
 * @version $Revision: 1.2 $
 */

public class TypicalProcess {
    
    private static STProjectLoginContext plc = null;
    static {
  try {
      plc = new STProjectLoginContext();
      plc.login();
  } catch (LoginException e) {
      throw new IllegalStateException (e.getMessage ());
  }
  try {
      prepareForCreateProcess();
  } catch (Exception e) {
      throw new IllegalStateException (e.getMessage ());
  }
    }

    private static WorkflowService wfsCache = null;

    protected static WorkflowService workflowService() {
  if (wfsCache == null) {
      try {
    WorkflowServiceFactory wfsf 
        = WorkflowServiceFactory.newInstance ();
    wfsCache = wfsf.newWorkflowService();
      } catch (FactoryConfigurationError e) {
    throw new IllegalStateException (e.getMessage());
      }
  }
  return wfsCache;
    } 

    private static WfRequester defReqCache = null;

    protected static WfRequester defaultRequester ()
  throws RemoteException {
  if (defReqCache == null) {
      defReqCache = new DefaultRequester (workflowService());
  }
  return defReqCache;
    }

    private static ProcessMgr processManager = null;

    public static final String PACKAGE_ID = "TypicalProcess";
    public static final String IRRELEVANT = "irrelvant";
    public static final String PATH1 = "Path 1";
    public static final String PATH2 = "Path 2";
    private static final String PATH3 = "Path 3";

    private ProcessData initialProcessData = new DefaultProcessData();
    private Process process = null;

    public TypicalProcess(int durationBE1_3) throws Exception {
  this (PATH1, IRRELEVANT, durationBE1_3, 0, 0, 0, 0, 0, 0);
    }

    public TypicalProcess(String decision2, 
        int durationBE2_1, int durationBE2_3_1, 
        int initialLoopCounter2) 
  throws Exception {
  this (PATH2, decision2, 0, durationBE2_1, durationBE2_3_1, 0, 0,
        initialLoopCounter2, 0);
    }

    public TypicalProcess(int durationBE2_1, int initialLoopCounter2) 
  throws Exception {
  this (PATH2, PATH2, 0, durationBE2_1, 0, 0, 0,
        initialLoopCounter2, 0);
    }

    public TypicalProcess(int durationBE3_2_1, int durationBE3_2_2, 
        int initialLoopCounter3)
  throws Exception {
  this (PATH3, IRRELEVANT, 0, 0, 0, durationBE3_2_2, durationBE3_2_2,
        0, initialLoopCounter3);
    }

    public TypicalProcess(int durationBE1_3, 
        boolean initializeAndCreate, boolean start) 
  throws Exception {
  this (PATH1, IRRELEVANT, durationBE1_3, 0, 0, 0, 0, 0, 0, 
        initializeAndCreate, start);
    }

    public TypicalProcess(String decision2, 
        int durationBE2_1, int durationBE2_3_1, 
        int initialLoopCounter2, 
        boolean initializeAndCreate, boolean start) 
  throws Exception {
  this (PATH2, decision2, 0, durationBE2_1, durationBE2_3_1, 0, 0,
        initialLoopCounter2, 0, initializeAndCreate, start);
    }

    public TypicalProcess(int durationBE2_1, int initialLoopCounter2,
        boolean initializeAndCreate, boolean start) 
  throws Exception { 
  this (PATH2, PATH2, 0, durationBE2_1, 0, 0, 0,
        initialLoopCounter2, 0, initializeAndCreate, start);
    }

    public TypicalProcess(int durationBE3_2_1, int durationBE3_2_2, 
        int initialLoopCounter3,
        boolean initializeAndCreate, boolean start) 
  throws Exception {
  this (PATH3, IRRELEVANT, 0, 0, 0, durationBE3_2_2, durationBE3_2_2,
        0, initialLoopCounter3, initializeAndCreate, start);
    }

    public TypicalProcess(String decision0, String decision2, 
        int durationBE1_3, 
        int durationBE2_1, int durationBE2_3_1,
        int durationBE3_2_1, int durationBE3_2_2, 
        int initialLoopCounter2, int initialLoopCounter3 ) 
  throws Exception {
  this(decision0, decision2, durationBE1_3, durationBE2_1, 
       durationBE2_3_1, durationBE3_2_1, durationBE3_2_2, 
       initialLoopCounter2, initialLoopCounter3, false, false);
    }

    public TypicalProcess(String decision0, String decision2, 
        int durationBE1_3, 
        int durationBE2_1, int durationBE2_3_1,
        int durationBE3_2_1, int durationBE3_2_2, 
        int initialLoopCounter2, int initialLoopCounter3, 
        boolean initializeAndCreate, boolean start) 
  throws Exception {
  initialProcessData.put("BE1_3_Duration", new Integer(durationBE1_3));
  initialProcessData.put("BE2_1_Duration", new Integer(durationBE2_1));
  initialProcessData.put("BE2_3_1_Duration", new Integer(durationBE2_3_1));
  initialProcessData.put("BE3_2_1_Duration", new Integer(durationBE3_2_1));
  initialProcessData.put("BE3_2_2_Duration", new Integer(durationBE3_2_2));
  initialProcessData.put("counterLoop2", new Integer(initialLoopCounter2));
  initialProcessData.put("counterLoop3", new Integer(initialLoopCounter3));
  initialProcessData.put("decision0", decision0);
  initialProcessData.put("decision2", decision2);
  if (initializeAndCreate) {
      process = createAndInitialize();
      if (start) {
    process.start();
      }
  } 
    }

    public TypicalProcess(ProcessData initialProcessData, 
        boolean initializeAndCreate, boolean start) 
  throws Exception {
  this.initialProcessData = initialProcessData;
  //System.out.println("Typical Process init: " + initialProcessData);
  if (initializeAndCreate) {
      process = createAndInitialize();
      if (start) {
    process.start();
      }
  } 
    }

    /**
     * Prepare for creating a process.
     * @exception Exception if an error occurs
     */
    public static void prepareForCreateProcess() throws Exception {

  // import the process definitions from the XPDL file
  ProcessDefinitionDirectory pdd 
      = workflowService().processDefinitionDirectory();
  InputStream is 
      = TypicalProcess.class.getResourceAsStream("/load/" + PACKAGE_ID 
                   + ".xml");
  BufferedReader br = new BufferedReader
      (new InputStreamReader(is, "ISO-8859-1"));
  StringBuffer sb = new StringBuffer();
  String st;
  while ((st = br.readLine()) != null) {
      sb.append(st + "\n");
  }
  pdd.importProcessDefinitions(sb.toString()); 

  // prepare the creation of process packageID/"P0"
  try {
      processManager = pdd.processMgr(PACKAGE_ID, "P0");
      defReqCache = defaultRequester();
  } catch (Exception e) {
      e.printStackTrace();
  }
    }

    /**
     * Create and start the process of id="P0".
     * @return created process
     * @exception Exception if an error occurs
     */
    public Process createAndInitialize() throws Exception {
  process = createProcess(PACKAGE_ID, "P0");
  process.setProcessContext(initialProcessData);
  return process;
    }

    /**
     * Describe <code>createProcess</code> method here.
     *
     * @param pkgId a <code>String</code> value
     * @param prcId a <code>String</code> value
     * @return a <code>Process</code> value
     * @exception Exception if an error occurs
     */
    protected Process createProcess (String pkgId, String prcId)
        throws Exception {
  ProcessDefinitionDirectory pdd 
      = workflowService().processDefinitionDirectory();
  ProcessMgr pmgr = pdd.processMgr(pkgId, prcId);
  Process process = (Process) pmgr.createProcess (defaultRequester());
  return process;
    }

    public void start() throws Exception {
  process.start();
    }

    public ProcessData initialProcessData() {
  return initialProcessData;
    }

    public static String packageId() {
  return PACKAGE_ID;
    }
    
    public TestCase createInitStartTest() {
  return new GenericTest("createStartAndInitializeProcess", PACKAGE_ID, 
             initialProcessData);
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.