ProcessMgrStub.java :  » Workflow-Engines » wfmopen-2.1.1 » de » danet » an » workflow » ejbs » admin » Java Open Source

Java Open Source » Workflow Engines » wfmopen 2.1.1 
wfmopen 2.1.1 » de » danet » an » workflow » ejbs » admin » ProcessMgrStub.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: ProcessMgrStub.java,v 1.3 2007/05/03 21:58:25 mlipp Exp $
 *
 * $Log: ProcessMgrStub.java,v $
 * Revision 1.3  2007/05/03 21:58:25  mlipp
 * Internal refactoring for making better use of local EJBs.
 *
 * Revision 1.2  2006/09/29 12:32:10  drmlipp
 * Consistently using WfMOpen as projct name now.
 *
 * Revision 1.1.1.2  2004/08/18 15:17:38  drmlipp
 * Update to 1.2
 *
 * Revision 1.23  2004/02/21 21:52:11  lipp
 * Moved ActivityFinder and ProcessMgrStub back to admin package.
 *
 * Revision 1.1  2004/02/21 21:31:00  lipp
 * Some more refactoring to resolve cyclic dependencies.
 *
 * Revision 1.21  2004/02/12 16:13:53  lipp
 * Renamed method for finding processes by data item value.
 *
 * Revision 1.20  2004/02/09 15:15:29  lipp
 * Support for looking up processes by the value of a data item.
 *
 * Revision 1.19  2003/06/27 08:51:45  lipp
 * Fixed copyright/license information.
 *
 * Revision 1.18  2003/04/26 16:11:14  lipp
 * Moved some classes to reduce package dependencies.
 *
 * Revision 1.17  2003/04/23 14:27:35  lipp
 * Improved modelling of header data.
 *
 * Revision 1.16  2003/04/19 18:33:29  lipp
 * Improved handling of info.
 *
 * Revision 1.15  2003/04/08 12:30:24  lipp
 * Implemented veriosn and category.
 *
 * Revision 1.14  2003/04/08 11:53:17  lipp
 * ResultSignature implemented.
 *
 * Revision 1.13  2003/04/08 11:49:05  lipp
 * ResultSignature implemented.
 *
 * Revision 1.12  2003/03/31 16:50:28  huaiyang
 * Logging using common-logging.
 *
 * Revision 1.11  2003/03/04 13:46:09  lipp
 * Renamed processCOntext to contextSignature for ProcessDefinition.
 *
 * Revision 1.10  2002/11/26 11:23:30  lipp
 * Modified RemoteException comment.
 *
 * Revision 1.9  2002/11/06 13:30:36  huaiyang
 * constructor of processMgrStub changed, modified the contextSignature.
 *
 * Revision 1.8  2002/11/04 14:35:47  huaiyang
 * Implements the method of contextSignature.
 *
 * Revision 1.7  2002/09/30 14:27:03  lipp
 * Fixed problem with unsupported version().
 *
 * Revision 1.6  2002/09/08 19:19:18  lipp
 * Replaced process type with process manager.
 *
 * Revision 1.5  2002/09/08 18:49:18  lipp
 * Proper use of packageId and processId.
 *
 * Revision 1.4  2002/08/30 13:37:05  lipp
 * Using Workflow engine facade now.
 *
 * Revision 1.3  2002/08/26 14:17:07  lipp
 * JavaDoc fixes.
 *
 * Revision 1.2  2002/08/22 08:47:29  lipp
 * Some minor optimizations.
 *
 * Revision 1.1  2002/08/21 22:06:47  lipp
 * Finished transition to ProcessMgrStub.
 *
 */
package de.danet.an.workflow.ejbs.admin;

import java.io.IOException;
import java.io.Serializable;

import java.util.Collection;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.ObjectNotFoundException;

import de.danet.an.util.EJBUtil;

import de.danet.an.workflow.omgcore.InvalidRequesterException;
import de.danet.an.workflow.omgcore.NotEnabledException;
import de.danet.an.workflow.omgcore.ProcessDataInfo;
import de.danet.an.workflow.omgcore.RequesterRequiredException;
import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.omgcore.WfProcessMgr;
import de.danet.an.workflow.omgcore.WfRequester;

import de.danet.an.workflow.api.InvalidKeyException;
import de.danet.an.workflow.api.Process;
import de.danet.an.workflow.api.ProcessDefinition;
import de.danet.an.workflow.api.ProcessMgr;

import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectory;
import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;
import de.danet.an.workflow.ejbs.core.WfProcessHome;

/**
 * This class provides a client side representation of a 
 * <code>WfProcessMgr</code>. It acts as a mixture of intelligent proxy
 * and stub. As stub, however, it has no directly corresponding server.
 * It uses methods provided by other remote objects (notably
 * <code>ProcessDirectory</code> and <code>ProcessDefinitionDirectory</code>
 * to fulfill its tasks.
 *
 * @author <a href="mailto:lipp@danet.de"></a>
 * @version $Revision: 1.3 $
 */

public class ProcessMgrStub implements ProcessMgr, Serializable {

    private static final org.apache.commons.logging.Log logger
  = org.apache.commons.logging.LogFactory.getLog(ProcessMgrStub.class);

    /** The package id of the process the mgr represents. */
    private String packageId = null;

    /** The process id of the process the mgr represents. */
    private String processId = null;

    /** The process type the mgr represents. */
    private String mgrName = null;

    /** The process key of the process the mgr represents. */
    private String processKey = null;

    // The home interface of the process definition directory
    private ProcessDefinitionDirectoryHome pddHome = null;

    // The home interface of the process EJB
    private WfProcessHome processHome = null;

    
    /**
     * Creates an instance of <code>ProcessMgrStub</code>
     * for the given process type.
     *
     * @param pkgId Id attribute of the process package.
     * @param prcId Id attribute of the process.
     * @param mgr the name of the process manager.
     * @param prcKey the key of the given process. It can be null.
     * @param pdh the process definition directory home interface.
     * @param ph the process home interface.
     */
    public ProcessMgrStub 
  (String pkgId, String prcId, String mgr, String prcKey,
   ProcessDefinitionDirectoryHome pdh, WfProcessHome ph) {
  packageId = pkgId;
  processId = prcId;
  mgrName = mgr;
  processKey = prcKey;
  pddHome = pdh;
  processHome = ph;
    }
    
    /**
     * This method delivers the type(name) of the process.
     * @return the name
     * @throws RemoteException if a system-level error occurs.
     */
    public String name () throws RemoteException {
  return mgrName;
    }

    private ProcessDefinition procDef () throws RemoteException {
  ProcessDefinitionDirectory pdd = null;
  try {
      if (processKey == null) {
    pdd = pddHome.create();
    return pdd.lookupProcessDefinition(packageId, processId);
      } else {
    Process proc = processHome.findByProcessKey(processKey);
    return proc.processDefinition();
      }
  } catch (InvalidKeyException ivke) {
      throw new IllegalStateException 
    ("Key " + packageId + "/" + processId + " is invalid: " 
     + ivke.getMessage());
  } catch (FinderException fe) {
      throw new RemoteException(fe.getMessage());
  } catch (CreateException ce) {
      logger.error (ce.getMessage(), ce);
      throw new RemoteException(ce.getMessage());
  } finally {
      EJBUtil.removeSession (pdd);
  }
    }

    /**
     * Returns a category. The category is the package name from the
     * XPDL description.
     * @return the category
     * @throws RemoteException if a system-level error occurs.
     */
    public String category () throws RemoteException {
  return procDef().packageName();
    }

    /**
     * Returns the creation date of the process from the XPDL description.
     * @return the creation date.
     * @throws RemoteException if a system-level error occurs.
     */
    public String version () throws RemoteException {
  return procDef().version ();
    }

    /**
     * Returns a collection with WfProcess objects from this process manager.
     * @return a Collection object with remote interface of WfProcess.
     * @throws RemoteException if a system-level error occurs.
     */
    public Collection processes () throws RemoteException {
  Collection processes = null;
  try {
      processes = processHome.findByProcessMgrName(name());
  } catch (FinderException fe) {
      logger.error (fe.getMessage(), fe);
      throw new RemoteException(fe.getMessage());
  }
  return processes;
    }

    /**
     * Returns the state of the <code>WfProcessMgr</code>.
     * @return ENABLED if creation of workflow processes is enabled,
     * otherwise DISABLED.
     * @throws RemoteException if a system-level error occurs.
     */
    public int processMgrState () throws RemoteException {
  ProcessDefinitionDirectory pdd = null;
  try {
      pdd = pddHome.create();
      if (pdd.isEnabled(packageId, processId)) {
    return WfProcessMgr.ENABLED;
      } else {
    return WfProcessMgr.DISABLED;
      }
  } catch (InvalidKeyException ivke) {
      return WfProcessMgr.DISABLED;
  } catch (CreateException ce) {
      logger.error (ce.getMessage(), ce);
      throw new RemoteException(ce.getMessage());
  } finally {
      EJBUtil.removeSession (pdd);
  }
    }

    /**
     * Set the new state of this process manager.
     * @param newState the new state.
     * @throws TransitionNotAllowedException if the transition is not allowed
     * @throws RemoteException if a system-level error occurs.
     */
    public void setProcessMgrState (int newState) throws RemoteException,
  TransitionNotAllowedException {
  ProcessDefinitionDirectory pdd = null;
  try {
      pdd = pddHome.create();
      pdd.setEnabled 
    (packageId, processId, newState == WfProcessMgr.ENABLED);
  } catch (InvalidKeyException ivke) {
      throw new TransitionNotAllowedException(ivke.getMessage());
  } catch (CreateException ce) {
      logger.error (ce.getMessage(), ce);
      throw new RemoteException(ce.getMessage());
  } finally {
      EJBUtil.removeSession (pdd);
  }
    }

    /**
     * Unsupported method in this iteration of WfMOpen.
     * @return the description
     * @throws RemoteException if a system-level error occurs.
     */
    public String description () throws RemoteException {
  return procDef().processHeader().description();
    }

    /**
     * Return the context signature of the process. If this process key is 
     * given, then find out its process definition through process; otherwise, 
     * through process definition directory.
     * @return a ProcessDataInfo object
     * @throws RemoteException if a system-level error occurs.
     */
    public ProcessDataInfo contextSignature () throws RemoteException {
  return procDef().contextSignature();
    }

    /**
     * Unsupported method in this iteration of WfMOpen.
     * @return a ProcessDataInfo object
     * @throws RemoteException if a system-level error occurs.
     */
    public ProcessDataInfo resultSignature () throws RemoteException {
  return procDef().resultSignature();
    }

    /**
     * Create a new process.
     * Accept any requester object with is not <code>null</code>.
     * @param requester WfRequester
     * @throws NotEnabledException if create of 
     * {@link de.danet.an.workflow.omgcore.WfProcess <code>WfProcess</code>} 
     * using a {@link de.danet.an.workflow.omgcore.WfProcessMgr <code>
     * WfProcessMgr</code>} that is disabled.
     * @throws InvalidRequesterException if requester is not validate. 
     * @throws RequesterRequiredException if requester is <code>null</code>
     * @throws RemoteException if a system-level error occurs.
     * @return a WfProcess object
     */
    public WfProcess createProcess (WfRequester requester) 
  throws RemoteException, NotEnabledException, 
  InvalidRequesterException, RequesterRequiredException {
  ProcessDefinitionDirectory pdd = null;
  try {
      pdd = pddHome.create();  
      return pdd.createProcess(packageId, processId, requester);
  } catch (InvalidKeyException ce) {
      throw new NotEnabledException(ce.getMessage());
  } catch (CreateException ce) {
      logger.error (ce.getMessage(), ce);
      throw new RemoteException(ce.getMessage());
  } finally {
      EJBUtil.removeSession (pdd);
  }
    }
    
    /**
     * Returns the {@link Process <code>Process</code>} with the given key.
     * @param key the 
     * {@link de.danet.an.workflow.omgcore.WfProcess#key key} of the process.
     * @return the process associated with the key.
     * @throws InvalidKeyException if no process with the given key
     * exists.
     * @throws RemoteException if a system-level error occurs.
     */
    public Process processByKey (String key) 
  throws InvalidKeyException, RemoteException {
  try {
      return (Process)processHome.findByProcessKey (key);
  } catch (ObjectNotFoundException onfx) {
      throw new InvalidKeyException
    ("Key " + key + " is invalid: " + onfx.getMessage());
  } catch (FinderException fex) {
      logger.error (fex.getMessage(), fex);
      throw new RemoteException (fex.getMessage());
  }
    }

    /**
     * Returns all {@link Process <code>Process</code>}es that have a
     * given value in a particular process data item. Note that this
     * method may only be used for data items of type string.
     *
     * @param itemName the name of the process data item
     * @param itemValue the value of the process data item
     * @return the collection of processes
     * @throws RemoteException if a system-level error occurs
     */
    public Collection findByDataItem 
  (String itemName, String itemValue) throws RemoteException {
  try {
      return processHome
    .findByProcessTypeAndDataItem (mgrName, itemName, itemValue);
  } catch (FinderException fex) {
      logger.error (fex.getMessage(), fex);
      throw new RemoteException (fex.getMessage());
  }
  
    }
}
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.