001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.scxml2.semantics;
018
019import java.util.ArrayList;
020import java.util.HashMap;
021import java.util.HashSet;
022import java.util.List;
023import java.util.Map;
024import java.util.Set;
025
026import org.apache.commons.scxml2.TriggerEvent;
027import org.apache.commons.scxml2.model.EnterableState;
028import org.apache.commons.scxml2.model.History;
029import org.apache.commons.scxml2.model.SimpleTransition;
030import org.apache.commons.scxml2.model.TransitionalState;
031
032/**
033 * A logical unit of progression in the execution of a SCXML model.
034 *
035 */
036public class Step {
037
038    /**
039     * The event in this step.
040     */
041    private TriggerEvent event;
042
043    /**
044     * The set of states that were exited during this step.
045     */
046    private Set<EnterableState> exitSet;
047
048    /**
049     * The set of states that were entered during this step.
050     */
051    private Set<EnterableState> entrySet;
052
053    /**
054     * The set of states that were entered during this step by default
055     */
056    private Set<EnterableState> defaultEntrySet;
057
058    /**
059     * The map of default History transitions to be executed as result of entering states in this step.
060     */
061    private Map<TransitionalState, SimpleTransition> defaultHistoryTransitions;
062
063    /**
064     * The map of new History configurations created as result of exiting states in this step
065     */
066    private Map<History, Set<EnterableState>> newHistoryConfigurations;
067
068    /**
069     * The list of Transitions taken during this step.
070     */
071    private List<SimpleTransition> transitList;
072
073    /**
074     * @param event The event received in this unit of progression
075     */
076    public Step(TriggerEvent event) {
077        this.event = event;
078        this.exitSet = new HashSet<EnterableState>();
079        this.entrySet = new HashSet<EnterableState>();
080        this.defaultEntrySet = new HashSet<EnterableState>();
081        this.defaultHistoryTransitions = new HashMap<TransitionalState, SimpleTransition>();
082        this.newHistoryConfigurations = new HashMap<History, Set<EnterableState>>();
083        this.transitList = new ArrayList<SimpleTransition>();
084    }
085
086    /**
087     * Ensure the intermediate state of this step is cleared before start processing the event and/or transitions
088     */
089    public void clearIntermediateState() {
090        exitSet.clear();
091        entrySet.clear();
092        defaultEntrySet.clear();
093        defaultHistoryTransitions.clear();
094        newHistoryConfigurations.clear();
095    }
096
097    /**
098     * @return Returns the entrySet.
099     */
100    public Set<EnterableState> getEntrySet() {
101        return entrySet;
102    }
103
104    /**
105     * @return Returns the defaultEntrySet.
106     */
107    public Set<EnterableState> getDefaultEntrySet() {
108        return defaultEntrySet;
109    }
110
111    /**
112     * @return Returns the map of default History transitions to be executed as result of entering states in this step
113     */
114    public Map<TransitionalState, SimpleTransition> getDefaultHistoryTransitions() {
115        return defaultHistoryTransitions;
116    }
117
118    /**
119     * @return Returns the map of new History configurations created as result of exiting states in this step
120     */
121    public Map<History, Set<EnterableState>> getNewHistoryConfigurations() {
122        return newHistoryConfigurations;
123    }
124
125    /**
126     * @return Returns the exitSet.
127     */
128    public Set<EnterableState> getExitSet() {
129        return exitSet;
130    }
131
132    /**
133     * @return Returns the current event.
134     */
135    public TriggerEvent getEvent() {
136        return event;
137    }
138
139    /**
140     * @return Returns the transitList.
141     */
142    public List<SimpleTransition> getTransitList() {
143        return transitList;
144    }
145}
146