Package de.danet.an.workflow.internalapi

Source Code of de.danet.an.workflow.internalapi.ExtExecutionObjectLocal$RunningState

/*
* 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: ExtExecutionObjectLocal.java 2368 2007-05-03 21:58:25Z mlipp $
*
* $Log$
*/
package de.danet.an.workflow.internalapi;

import java.io.Serializable;


import de.danet.an.workflow.localapi.ExecutionObjectLocal;
import de.danet.an.workflow.omgcore.InvalidPriorityException;
import de.danet.an.workflow.omgcore.WfAuditEvent;
import de.danet.an.workflow.omgcore.WfExecutionObject.NotRunningState;
import de.danet.an.workflow.omgcore.WfExecutionObject.OpenState;
import de.danet.an.workflow.omgcore.WfExecutionObject.State;

/**
* This interface defines some additional methods of
* <code>ExecutionObject</code>s that are only available within the
* implementation (not part of the API).
*
* @author <a href="mailto:lipp@danet.de">Michael Lipp</a>
* @version $Revision: 2368 $
*/

public interface ExtExecutionObjectLocal extends ExecutionObjectLocal {
   
    /**
     * This class defines the sub-states of OpenState.RUNNING
     * of a {@link de.danet.an.workflow.localcoreapi.WfExecutionObjectLocal
     * <code>WfExecutionObject</code>}.
     * These substates are an extention of the predefined omg states.
     */
    public static class RunningState
  extends OpenState implements Serializable {
  /**
   * Provides a state indicating that the process is running.
   */
  public static final RunningState RUNNING
      = new RunningState("running");
  /**
   * Provides a state indicating that the process is about to
   * be terminated.
   */
  public static final RunningState TERMINATING
      = new RunningState("terminating");
  /**
   * Provides a state indicating that an activity is
   * abandoning.
   */
  public static final RunningState ABANDONING
      = new RunningState("abandoning");
  /**
   * Provides a state indicating that an activity is suspended
   * because of a debug "breakpoint".
   */
  public static final RunningState DEBUG
      = new RunningState("debug");
  static {
      registerState(RUNNING);
      registerState(TERMINATING);
      registerState(ABANDONING);
      registerState(DEBUG);
  }
  /**
   * Default constructor.
   * @param text Textual representation of the state
   */
  protected RunningState(String text) {
      super(text);
  }
  /**
   * Returns the parent in the state hierachy if all states
   * defined in this class or <code>null</code>, if this states
   * are at the top level of the hierachy.
   * @return parent in the state hierachy
   */
  public State getParent() {
      // parent is OpenState.RUNNING
      return OpenState.RUNNING;
  }
  /**
   * Returns the workflow state, i.e. the great-grandparent.
   * @return the workflow state.
   */
  public State workflowState () {
      return getParent().getParent();
  }
  /**
   * Returns the workflow substate for open execution objects.
   * @return the open state.
   */
  public State whileOpenState () {
      return getParent();
  }
  /**
   * Returns the workflow substate for open, not running
   * execution objects.
   * @return the why not running state.
   */
  public State whyNotRunningState () {
      throw new IllegalStateException();
  }
  /**
   * Returns the workflow substate for closed
   * execution objects.
   * @return the closed state.
   */
  public State howClosedState () {
      throw new IllegalStateException();
  }

  /**
   * Perform instance substitution during serialization.
   */
  private Object readResolve() {
      String repr = textRepresentation();
      if (repr == null) {
    throw new IllegalArgumentException
        ("Unexpected error in deserialization");
      }
      if (repr.equals(RUNNING.textRepresentation())) {
    return RUNNING;
      }
      if (repr.equals (TERMINATING.textRepresentation())) {
    return TERMINATING;
      }
      if (repr.equals (ABANDONING.textRepresentation())) {
    return ABANDONING;
      }
      if (repr.equals (DEBUG.textRepresentation())) {
    return DEBUG;
      }
      throw new IllegalArgumentException
    ("Unexpected error in serialization");
  }
    }

    /**
     * This class defines the sub-states of NotRunningState.SUSPENDED
     * of a {@link de.danet.an.workflow.localcoreapi.WfExecutionObjectLocal
     * <code>WfExecutionObject</code>}.
     * These substates are an extention of the predefined omg states.
     */
    public static class SuspendedState
  extends NotRunningState implements Serializable {
  /**
   * Provides a state indicating that the process is running.
   */
  public static final SuspendedState SUSPENDED
      = new SuspendedState("suspended");
  /**
   * Provides a state indicating that the process is about to
   * be aborted.
   */
  public static final SuspendedState ABORTING
      = new SuspendedState("aborting");
        /**
         * Provides a state indicating that the activity will be
         * set to abandoned when resumed.
         */
        public static final SuspendedState ABANDONING
            = new SuspendedState("abandoning");
        /**
         * Provides a state indicating that the activity will be
         * set to running when resumed.
         */
        public static final SuspendedState CLEARING_EXCEPTION
            = new SuspendedState("clearing_exception");
        static {
            registerState(SUSPENDED);
            registerState(ABORTING);
            registerState(ABANDONING);
            registerState(CLEARING_EXCEPTION);
        }
  /**
   * Default constructor.
   * @param text Textual representation of the state
   */
  protected SuspendedState(String text) {
      super(text);
  }
  /**
   * Returns the parent in the state hierachy if all states
   * defined in this class or <code>null</code>, if this states
   * are at the top level of the hierachy.
   * @return parent in the state hierachy
   */
  public State getParent() {
      return NotRunningState.SUSPENDED;
  }
  /**
   * Returns the workflow state, i.e. the great-grandparent.
   * @return the workflow state.
   */
  public State workflowState () {
      return getParent().getParent().getParent();
  }
  /**
   * Returns the workflow substate for open execution objects.
   * @return the open state.
   */
  public State whileOpenState () {
      return getParent().getParent();
  }
  /**
   * Returns the workflow substate for open, not running
   * execution objects.
   * @return the why not running state.
   */
  public State whyNotRunningState () {
      throw new IllegalStateException();
  }
  /**
   * Returns the workflow substate for closed
   * execution objects.
   * @return the closed state.
   */
  public State howClosedState () {
      throw new IllegalStateException();
  }

  /**
   * Perform instance substitution during serialization.
   */
  private Object readResolve() {
      String repr = textRepresentation();
      if (repr == null) {
    throw new IllegalArgumentException
        ("Unexpected error in deserialization");
      }
      if (repr.equals (SUSPENDED.textRepresentation())) {
    return SUSPENDED;
      }
      if (repr.equals (ABORTING.textRepresentation())) {
    return ABORTING;
      }
            if (repr.equals (ABANDONING.textRepresentation())) {
                return ABANDONING;
            }
            if (repr.equals (CLEARING_EXCEPTION.textRepresentation())) {
                return CLEARING_EXCEPTION;
            }
      throw new IllegalArgumentException
    ("Unexpected error in serialization");
  }
    }

    /**
     * This class defines the sub-states of RunningState.DEBUG
     * of a {@link de.danet.an.workflow.localcoreapi.WfExecutionObjectLocal
     * <code>WfExecutionObject</code>}.
     * These substates are an extention of the predefined omg states.
     */
    public static class DebugState
  extends RunningState implements Serializable {
  /**
   * Provides a state indicating that the activity is about to
   * be abandoned.
   */
  public static final DebugState ABANDONING
      = new DebugState("abandoning");
  /**
   * Provides a state indicating that the activity is about to
   * be aborted.
   */
  public static final DebugState ABORTING
      = new DebugState("aborting");
  /**
   * Provides a state indicating that the activity is about to
   * be completed.
   */
  public static final DebugState COMPLETING
      = new DebugState("completing");
  /**
   * Provides a state indicating that a tool is about to
   * be invoked.
   */
  public static final DebugState INVOKING
      = new DebugState("invoking");
  /**
   * Provides a state indicating that a tool is to
   * be skipped.
   */
  public static final DebugState SKIPPING
      = new DebugState("skipping");
  /**
   * Provides a state indicating that the activity is about to
   * be terminated.
   */
  public static final DebugState TERMINATING
      = new DebugState("terminating");
  /**
   * Provides a state indicating that the activity expects an
   * exception that is to be forwarded to the process.
   */
  public static final DebugState FORWARDING_EXCEPTION
      = new DebugState("forwarding_exception");
  /**
   * Provides a state indicating that the activity expects an
   * exception that is to be handled as in non-debug mode.
   */
  public static final DebugState AWAITING_EXCEPTION
      = new DebugState("awaiting_exception");
  static {
      registerState(ABANDONING);
      registerState(ABORTING);
      registerState(COMPLETING);
      registerState(INVOKING);
      registerState(SKIPPING);
      registerState(TERMINATING);
      registerState(FORWARDING_EXCEPTION);
      registerState(AWAITING_EXCEPTION);
  }
  /**
   * Default constructor.
   * @param text Textual representation of the state
   */
  protected DebugState(String text) {
      super(text);
  }
  /**
   * Returns the parent in the state hierachy if all states
   * defined in this class or <code>null</code>, if this states
   * are at the top level of the hierachy.
   * @return parent in the state hierachy
   */
  public State getParent() {
      return RunningState.DEBUG;
  }
  /**
   * Returns the workflow state, i.e. the great-grandparent.
   * @return the workflow state.
   */
  public State workflowState () {
      return getParent().getParent().getParent();
  }
  /**
   * Returns the workflow substate for open execution objects.
   * @return the open state.
   */
  public State whileOpenState () {
      return getParent().getParent();
  }
  /**
   * Returns the workflow substate for open, not running
   * execution objects.
   * @return the why not running state.
   */
  public State whyNotRunningState () {
      return getParent().whyNotRunningState();
  }
  /**
   * Returns the workflow substate for closed
   * execution objects.
   * @return the closed state.
   */
  public State howClosedState () {
      throw new IllegalStateException();
  }

  /**
   * Perform instance substitution during serialization.
   */
  private Object readResolve() {
      String repr = textRepresentation();
      if (repr == null) {
    throw new IllegalArgumentException
        ("Unexpected error in deserialization");
      }
      if (repr.equals (ABANDONING.textRepresentation())) {
    return ABANDONING;
      }
      if (repr.equals (ABORTING.textRepresentation())) {
    return ABORTING;
      }
      if (repr.equals (COMPLETING.textRepresentation())) {
    return COMPLETING;
      }
      if (repr.equals (INVOKING.textRepresentation())) {
    return INVOKING;
      }
      if (repr.equals (SKIPPING.textRepresentation())) {
    return SKIPPING;
      }
      if (repr.equals (TERMINATING.textRepresentation())) {
    return TERMINATING;
      }
      if (repr.equals (FORWARDING_EXCEPTION.textRepresentation())) {
    return FORWARDING_EXCEPTION;
      }
      if (repr.equals (AWAITING_EXCEPTION.textRepresentation())) {
    return AWAITING_EXCEPTION;
      }
      throw new IllegalArgumentException
    ("Unexpected error in serialization");
  }
    }

    /**
     * Defines a class for representing priorities in a type save way.
     */
    public static final class Priority implements Serializable {   
  // Low priority
  /** The lowest priority. */
  public static final Priority LOWEST = new Priority(5);
  /** The low priority. */
  public static final Priority LOW = new Priority(4);
  // Normal priority
  /** The normal priority. */
  public static final Priority NORMAL = new Priority(3);
  // High priority
  /** The high priority. */
  public static final Priority HIGH = new Priority(2);
  /** The highest priority. */
  public static final Priority HIGHEST = new Priority(1);
  private static final Priority[] MAP
      = { HIGHEST, HIGH, NORMAL, LOW, LOWEST };
  // priority degree
  private int priority = 0;
  /**
   * Default constructor.
   * @param i int value
   */
  private Priority(int i) {
      priority = i;
  }
  /**
   * Convert to integer.
   * @return the priority as integer.
   */
  public int toInt () {
      return priority;
  }
  /**
   * Restore from integer.
   * @param prio the priority as integer.
   * @return the corresponding priority.
   * @throws InvalidPriorityException if <code>prio</code> is invalid.
   */
  public static Priority fromInt (int prio)
      throws InvalidPriorityException {
      try {
    return MAP[prio - 1];
      } catch (IndexOutOfBoundsException ex) {
    throw new InvalidPriorityException
        ("No valid priority: " + prio);
      }
  }

  /**
   * Perform instance substitution during serialization.
   */
  private Object readResolve() {
      try {
    return MAP[priority - 1];
      } catch (IndexOutOfBoundsException ex) {
    throw new IllegalArgumentException
        ("Unexpected error in serialization");
      }
  }
    }

    /**
     * Handles the given audit event.
     * @param event the event.
     */
    void handleAuditEvent (WfAuditEvent event);

}
TOP

Related Classes of de.danet.an.workflow.internalapi.ExtExecutionObjectLocal$RunningState

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.