1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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 package org.apache.commons.scxml2.semantics;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25
26 import org.apache.commons.scxml2.TriggerEvent;
27 import org.apache.commons.scxml2.model.EnterableState;
28 import org.apache.commons.scxml2.model.History;
29 import org.apache.commons.scxml2.model.SimpleTransition;
30 import org.apache.commons.scxml2.model.TransitionalState;
31
32 /**
33 * A logical unit of progression in the execution of a SCXML model.
34 *
35 */
36 public class Step {
37
38 /**
39 * The event in this step.
40 */
41 private TriggerEvent event;
42
43 /**
44 * The set of states that were exited during this step.
45 */
46 private Set<EnterableState> exitSet;
47
48 /**
49 * The set of states that were entered during this step.
50 */
51 private Set<EnterableState> entrySet;
52
53 /**
54 * The set of states that were entered during this step by default
55 */
56 private Set<EnterableState> defaultEntrySet;
57
58 /**
59 * The map of default History transitions to be executed as result of entering states in this step.
60 */
61 private Map<TransitionalState, SimpleTransition> defaultHistoryTransitions;
62
63 /**
64 * The map of new History configurations created as result of exiting states in this step
65 */
66 private Map<History, Set<EnterableState>> newHistoryConfigurations;
67
68 /**
69 * The list of Transitions taken during this step.
70 */
71 private List<SimpleTransition> transitList;
72
73 /**
74 * @param event The event received in this unit of progression
75 */
76 public Step(TriggerEvent event) {
77 this.event = event;
78 this.exitSet = new HashSet<EnterableState>();
79 this.entrySet = new HashSet<EnterableState>();
80 this.defaultEntrySet = new HashSet<EnterableState>();
81 this.defaultHistoryTransitions = new HashMap<TransitionalState, SimpleTransition>();
82 this.newHistoryConfigurations = new HashMap<History, Set<EnterableState>>();
83 this.transitList = new ArrayList<SimpleTransition>();
84 }
85
86 /**
87 * Ensure the intermediate state of this step is cleared before start processing the event and/or transitions
88 */
89 public void clearIntermediateState() {
90 exitSet.clear();
91 entrySet.clear();
92 defaultEntrySet.clear();
93 defaultHistoryTransitions.clear();
94 newHistoryConfigurations.clear();
95 }
96
97 /**
98 * @return Returns the entrySet.
99 */
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