Package common

Source Code of common.WrappedExecutionObject

/*
* 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: WrappedExecutionObject.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.1  2003/12/19 13:01:46  drmlipp
* Updated to 1.1rc1
*
* Revision 1.2  2003/10/28 14:06:13  huaiyang
* refactor it.
*
* Revision 1.1  2003/10/27 15:32:20  huaiyang
* initial.
*
*
*
*/
package common;

import java.rmi.RemoteException;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;

import javax.naming.TimeLimitExceededException;

import de.danet.an.workflow.omgcore.AlreadySuspendedException;
import de.danet.an.workflow.omgcore.CannotResumeException;
import de.danet.an.workflow.omgcore.CannotStopException;
import de.danet.an.workflow.omgcore.CannotSuspendException;
import de.danet.an.workflow.omgcore.InvalidStateException;
import de.danet.an.workflow.omgcore.NotRunningException;
import de.danet.an.workflow.omgcore.NotSuspendedException;
import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
import de.danet.an.workflow.omgcore.WfExecutionObject;
import de.danet.an.workflow.omgcore.WfActivity;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.omgcore.WfExecutionObject.State;

import process.EventWatch;

/**
* Describe class <code>WrappedExecutionObject</code> here.
*
* @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
* @version 1.0
*/
public class WrappedExecutionObject {

    /**
     * Describe variable <code>wfeo</code> here.
     *
     */
    protected WfExecutionObject wfeo = null;

    private EventWatch eventWatch;

    private String awaitingState;

    /**
     * Creates a new <code>WrappedExecutionObject</code> instance.
     *
     * @param wfeo a <code>WfExecutionObject</code> value
     */
    public WrappedExecutionObject(WfExecutionObject wfeo)
  throws Exception {
  this.wfeo = wfeo;
  eventWatch = new EventWatch (wfeo.key());
    }

    /**
     * Return the key.
     * @return the key.
     */
    public String key () {
  while(true) {
      try {
    return wfeo.key();
      } catch (RemoteException re) {
      }
  }
    }
 
    /**
     * Describe <code>waitForState</code> method here.
     *
     * @param stateToCheck a <code>String</code> value
     * @exception Exception if an error occurs
     */
    public void setupWaitForState(String stateToCheck)
  throws Exception {
  setupWaitForState(stateToCheck, false);
    }

    /**
     * Describe <code>waitForState</code> method here.
     *
     * @param stateToCheck a <code>String</code> value
     * @exception Exception if an error occurs
     */
    public void setupWaitForState(String stateToCheck, boolean log)
  throws Exception {
  awaitingState = stateToCheck;
  if (this instanceof WrappedProcess) {
      eventWatch.setup (key(), null, null, stateToCheck, log);
  } else {
      eventWatch.setup (null, key(), null, stateToCheck, log);
  }
    }

    public void waitForState () throws Exception {
  try {
      eventWatch.waitForEvent ();
  } catch (TimeLimitExceededException e) {
      throw new Exception(e.getMessage());
  }
    }

    /**
     * Describe <code>state</code> method here.
     *
     * @return a <code>String</code> value
     */
    public String state() {
  String state = "";
  while (true) {
      try {
    state = wfeo.state();
    break;
      } catch (RemoteException re) {
      }
  }
  return state;
    }

    /**
     * Describe <code>hasState</code> method here.
     *
     * @param stateToCheck a <code>String</code> value
     * @return a <code>boolean</code> value
     */
    public boolean hasState(String stateToCheck) {
  return state().startsWith(stateToCheck);
    }

    /**
     * Describe <code>name</code> method here.
     *
     * @return a <code>String</code> value
     */
    public String name() {
  String name = "";
  while (true) {
      try {
    name = wfeo.name();
    break;
      } catch (RemoteException re) {
      }
  }
  return name;
    }

    /**
     * Describe <code>description</code> method here.
     *
     * @return a <code>String</code> value
     */
    public String description() {
  String description = "";
  while (true) {
      try {
    description = wfeo.description();
    break;
      } catch (RemoteException re) {
      }
  }
  return description;
    }

    /**
     * Describe <code>priority</code> method here.
     *
     * @return a <code>int</code> value
     */
    public int priority() throws RemoteException {
  return wfeo.priority();
    }

    /**
     * Describe <code>priority</code> method here.
     *
     * @return a <code>int</code> value
     */
    public void setPriority(int priority) throws Exception {
  while (true) {
      try {
    wfeo.setPriority(priority);
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Sets the state of a WfExecutionObject by calling 
     * suspend().
     * The intended transition is from open.running to
     * open.not_running.suspended.
     * @exception RemoteException if an error occurs
     * @exception CannotSuspendException if an error occurs
     * @exception NotRunningException if an error occurs
     * @exception AlreadySuspendedException if an error occurs
     * @exception InvalidStateException if an error occurs
     * @exception TransitionNotAllowedException if an error occurs
     */
    public void suspend()
  throws RemoteException, CannotSuspendException,
         NotRunningException, AlreadySuspendedException, 
         InvalidStateException, TransitionNotAllowedException {
  while (true) {
      try {
    wfeo.suspend();
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Sets the state of a WfExecutionObject by calling 
     * resume().
     * The intended transition is from open.not_running.suspended to
     * open.running.
     * @exception RemoteException if an error occurs
     * @exception CannotResumeException if an error occurs
     * @exception NotRunningException if an error occurs
     * @exception NotSuspendedException if an error occurs
     * @exception InvalidStateException if an error occurs
     * @exception TransitionNotAllowedException if an error occurs
     */
    public void resume()
  throws RemoteException,  CannotResumeException,
         NotRunningException, NotSuspendedException, 
         InvalidStateException, TransitionNotAllowedException {
  while (true) {
      try {
    wfeo.resume();
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Sets the state of a WfExecutionObject by calling 
     * abort() (setStateDirectly == false) or by calling 
     * setState() (setStateDirectly == true).
     * The intended transition is from open.not_running.suspended to
     * closed.aborted.
     * @exception RemoteException if an error occurs
     * @exception NotRunningException if an error occurs
     * @exception NotSuspendedException if an error occurs
     * @exception InvalidStateException if an error occurs
     * @exception TransitionNotAllowedException if an error occurs
     * @exception CannotStopException if an error occurs
     */
    public void abort()
  throws RemoteException, NotRunningException, NotSuspendedException, 
         InvalidStateException, TransitionNotAllowedException,
         CannotStopException {
  while (true) {
      try {
    wfeo.abort();
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Sets the state of a WfExecutionObject by calling 
     * terminate().
     * The intended transition is to
     * closed.terminate.
     * @exception RemoteException if an error occurs
     * @exception CannotStopException if an error occurs
     * @exception InvalidStateException if an error occurs
     * @exception NotRunningException if an error occurs
     * @exception TransitionNotAllowedException if an error occurs
     */
    public void terminate()
  throws RemoteException,  CannotStopException, InvalidStateException,
         NotRunningException, TransitionNotAllowedException {
  while (true) {
      try {
    wfeo.terminate();
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Describe <code>changeState</code> method here.
     *
     * @param state a <code>String</code> value
     * @exception RemoteException if an error occurs
     * @exception TransitionNotAllowedException if an error occurs
     * @exception InvalidStateException if an error occurs
     */
    public void changeState(String state)
  throws RemoteException, TransitionNotAllowedException,
         InvalidStateException {
  while (true) {
      try {
    wfeo.changeState(state);
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Set the name of this <code>WfExecutionObject</code>.
     * @param newValue the description of this <code>WfExecutionObject</code>.
     * @throws RemoteException If a communication error occurred.
     */
    public void setName (String newValue) {
  while (true) {
      try {
    wfeo.setName(newValue);
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Set the description of this <code>WfExecutionObject</code>.
     * @param newValue the description of this <code>WfExecutionObject</code>.
     * @throws RemoteException If a communication error occurred.
     */
    public void setDescription (String newValue) {
  while (true) {
      try {
    wfeo.setDescription(newValue);
    break;
      } catch (RemoteException re) {
      }
  }
    }

    /**
     * Return the current state.
     *
     * @return the current <code>state</code>.
     * @throws RemoteException if a system-level error occurs.
     */
    public State workflowState () {
  while (true) {
      try {
    return wfeo.workflowState();
      } catch (RemoteException re) {
    // try again
      }
  }
    }

    /**
     * Return the context of this <code>WfExecutionObject</code>.
     * @return the process relevant data that define the context of the
     * execution object.
     * @throws RemoteException If a communication error occurred.
     */
    public ProcessData processContext () {
  while (true) {
      try {
    return wfeo.processContext();
      } catch (RemoteException re) {
    // try again
      }
  }
    }

    public String toString () {
  return name() + "[key=" + key() + "]";
    }

    /**
     * Describe <code>wrapActivities</code> method here.
     *
     * @param activityCollection a <code>Collection</code> value
     * @return a <code>Collection</code> value
     */
    protected Collection wrapActivities(Collection activityCollection)
  throws Exception {
  Collection newCollection = new ArrayList();
  Iterator it = activityCollection.iterator();
  while (it.hasNext()) {
      WfActivity activity = (WfActivity)it.next();
      newCollection.add(new WrappedActivity(activity));
  }
  return newCollection;
    }
}
TOP

Related Classes of common.WrappedExecutionObject

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.