View Javadoc
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.model;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  /**
23   * An abstract base class for state elements in SCXML that can be entered, such as State, Parallel or Final.
24   */
25  public abstract class EnterableState extends TransitionTarget implements DocumentOrder {
26  
27      /**
28       * The document order of this state
29       */
30      private int order;
31  
32      /**
33       * List of optional OnEntry elements holding executable content to be run upon
34       * entering this transition target.
35       */
36      private List<OnEntry> onEntries;
37  
38      /**
39       * List of optional OnExit elements holding executable content to be run upon
40       * exiting this transition target.
41       */
42      private List<OnExit> onExits;
43  
44      public EnterableState() {
45          super();
46          onEntries = new ArrayList<OnEntry>();
47          onExits = new ArrayList<OnExit>();
48      }
49  
50      /**
51       * @return the document order of this state
52       * @see DocumentOrder
53       */
54      @Override
55      public final int getOrder() {
56          return order;
57      }
58  
59      /**
60       * Sets the document order of this state
61       * @param order the document order
62       * @see DocumentOrder
63       */
64      public final void setOrder(int order) {
65          this.order = order;
66      }
67  
68      /**
69       * Get the OnEntry elements.
70       *
71       * @return Returns the onEntry elements
72       */
73      public final List<OnEntry> getOnEntries() {
74          return onEntries;
75      }
76  
77      /**
78       * Adds an OnEntry element
79       *
80       * @param onEntry The onEntry to add.
81       */
82      public final void addOnEntry(final OnEntry onEntry) {
83          onEntry.setParent(this);
84          onEntries.add(onEntry);
85      }
86  
87      /**
88       * Get the OnExit elements
89       *
90       * @return Returns the onExit elements
91       */
92      public final List<OnExit> getOnExits() {
93          return onExits;
94      }
95  
96      /**
97       * Add an OnExit element
98       *
99       * @param onExit The onExit to add.
100      */
101     public final void addOnExit(final OnExit onExit) {
102         onExit.setParent(this);
103         onExits.add(onExit);
104     }
105 
106     /**
107      * Check whether this is an atomic state.
108      * <p>
109      * An atomic state is a state of type Final or of type State without children,
110      * </p>
111      * @return Returns true if this is an atomic state.
112      */
113     public abstract boolean isAtomicState();
114 }