001/* Abstract base class of transition action. 002 003 Copyright (c) 1999-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 */ 027package ptolemy.domains.modal.kernel; 028 029import java.util.List; 030 031import ptolemy.kernel.util.IllegalActionException; 032import ptolemy.kernel.util.NameDuplicationException; 033import ptolemy.kernel.util.NamedObj; 034import ptolemy.kernel.util.StringAttribute; 035import ptolemy.kernel.util.Workspace; 036 037/////////////////////////////////////////////////////////////////// 038//// Action 039 040/** 041 An Action is contained by a Transition in an FSMActor or an Event in an 042 ERGController. 043 <p> 044 When the FSMActor is fired, an enabled transition among the outgoing 045 transitions of the current state is chosen. The choice actions 046 contained by the chosen transition are executed. An action is a choice 047 action if it implements the ChoiceAction marker interface. A choice 048 action may be executed more than once during an iteration in domains 049 with fixed-point semantics. 050 <p> 051 When the FSMActor is postfired, the chosen transition of the latest firing 052 of the actor is committed. The commit actions contained by the transition 053 are executed and the current state of the actor is set to the destination 054 state of the transition. An action is a commit action if it implements the 055 CommitAction marker interface. 056 057 @author Xiaojun Liu 058 @version $Id$ 059 @since Ptolemy II 8.0 060 @Pt.ProposedRating Yellow (liuxj) 061 @Pt.AcceptedRating Yellow (liuxj) 062 @see ChoiceAction 063 @see CommitAction 064 @see Transition 065 @see FSMActor 066 @see ptolemy.data.expr.Variable 067 */ 068public abstract class Action extends StringAttribute { 069 /** Construct an action in the specified workspace with an empty 070 * string as a name. 071 * The object is added to the directory of the workspace. 072 * Increment the version number of the workspace. 073 * @param workspace The workspace that will list the attribute. 074 */ 075 public Action(Workspace workspace) { 076 super(workspace); 077 } 078 079 /** Construct an action with the given name contained by the 080 * specified container. The container argument must not be 081 * null, or a NullPointerException will be thrown. This action 082 * will use the workspace of the container for synchronization 083 * and version counts. If the name argument is null, then the 084 * name is set to the empty string. 085 * Increment the version of the workspace. 086 * @param container The container. 087 * @param name The name of this action. 088 * @exception IllegalActionException If the action is not of an 089 * acceptable class for the container, or if the name contains 090 * a period. 091 * @exception NameDuplicationException If the container already 092 * has an attribute with the name. 093 */ 094 public Action(NamedObj container, String name) 095 throws IllegalActionException, NameDuplicationException { 096 super(container, name); 097 } 098 099 /////////////////////////////////////////////////////////////////// 100 //// public methods //// 101 102 /** Execute the action. 103 * @exception IllegalActionException If the action cannot be 104 * successfully completed. 105 */ 106 abstract public void execute() throws IllegalActionException; 107 108 /** Return the list of destinations of assignments in this action. 109 * @return A list of IOPort for output actions, and a list of parameters 110 * for set actions. 111 * @exception IllegalActionException If the destination list cannot be 112 * constructed. 113 */ 114 abstract public List getDestinations() throws IllegalActionException; 115 116 /** Set the container of this action. The proposed container must 117 * be an instance of Transition or Event or null, otherwise an 118 * IllegalActionException will be thrown. A null argument will 119 * remove the action from its container. 120 * 121 * @param container The proposed container. 122 * @exception IllegalActionException If setting the container 123 * would result in a recursive containment structure, or if this 124 * action and container are not in the same workspace, or if the 125 * argument is not an instance of Transition or null. 126 * @exception NameDuplicationException If the container already has 127 * an attribute with the name of this action. 128 */ 129 @Override 130 public void setContainer(NamedObj container) 131 throws IllegalActionException, NameDuplicationException { 132 // An Action is used in a Transition in the FSM domain, or an Event in 133 // the Ptera domain. 134 135 // FSM should not depend on Ptera, so this check is removed. 136 // In fact, this check is not necessary, because all instantiable 137 // classes in FSM declares container to have type Transition. 138 139 /*if (!(container instanceof Transition) && !(container instanceof Event) 140 && (container != null)) { 141 throw new IllegalActionException(container, this, "Action can only " 142 + "be contained by instances of Transition or Event."); 143 }*/ 144 145 super.setContainer(container); 146 } 147}