View Javadoc

    1   /*
    2    *
    3    *   Copyright 2005 The Apache Software Foundation.
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   *  Unless required by applicable law or agreed to in writing, software
    12   *  distributed under the License is distributed on an "AS IS" BASIS,
    13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   *  See the License for the specific language governing permissions and
    15   *  limitations under the License.
    16   *
    17   */
    18  package org.apache.commons.scxml.model;
    19
    20  import java.util.Collection;
    21
    22  import org.apache.commons.logging.Log;
    23  import org.apache.commons.scxml.ErrorReporter;
    24  import org.apache.commons.scxml.EventDispatcher;
    25  import org.apache.commons.scxml.SCInstance;
    26  import org.apache.commons.scxml.SCXMLExpressionException;
    27
    28  /***
    29   * An abstract base class for executable elements in SCXML,
    30   * such as &lt;assign&gt;, &lt;log&gt; etc.
    31   *
    32   */
    33  public abstract class Action {
    34
    35      /***
    36       * Link to its parent or container.
    37       */
    38      private Executable parent;
    39
    40      /***
    41       * Constructor.
    42       */
    43      public Action() {
    44          super();
    45          this.parent = null;
    46      }
    47
    48      /***
    49       * Get the Executable parent.
    50       *
    51       * @return Returns the parent.
    52       */
    53      public final Executable getParent() {
    54          return parent;
    55      }
    56
    57      /***
    58       * Set the Executable parent.
    59       *
    60       * @param parent The parent to set.
    61       */
    62      public final void setParent(final Executable parent) {
    63          this.parent = parent;
    64      }
    65
    66      /***
    67       * Return the parent state.
    68       *
    69       * @return The parent State
    70       * @throws ModelException For an unknown TransitionTarget subclass
    71       */
    72      public final State getParentState() throws ModelException {
    73          TransitionTarget tt = parent.getParent();
    74          if (tt instanceof State) {
    75              State st = (State) tt;
    76              return st;
    77          } else if (tt instanceof Parallel || tt instanceof History) {
    78              State st = (State) tt.getParent();
    79              return st;
    80          } else {
    81              throw new ModelException("Unknown TransitionTarget subclass:"
    82                      + tt.getClass().getName());
    83          }
    84      }
    85
    86      /***
    87       * Execute this action instance.
    88       *
    89       * @param evtDispatcher The EventDispatcher for this execution instance
    90       * @param errRep        The ErrorReporter to broadcast any errors
    91       *                      during execution.
    92       * @param scInstance    The state machine execution instance information.
    93       * @param appLog        The application Log.
    94       * @param derivedEvents The collection to which any internal events
    95       *                      arising from the execution of this action
    96       *                      must be added.
    97       *
    98       * @throws ModelException If the execution causes the model to enter
    99       *                        a non-deterministic state.
    100      * @throws SCXMLExpressionException If the execution involves trying
    101      *                        to evaluate an expression which is malformed.
    102      */
    103     public abstract void execute(final EventDispatcher evtDispatcher,
    104         final ErrorReporter errRep, final SCInstance scInstance,
    105         final Log appLog, final Collection derivedEvents)
    106     throws ModelException, SCXMLExpressionException;
    107
    108 }
    109