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  /**
20   * The class in this SCXML object model that corresponds to the
21   * <state> SCXML element.
22   *
23   */
24  public class State extends TransitionalState {
25  
26      /**
27       * Serial version UID.
28       */
29      private static final long serialVersionUID = 2L;
30  
31      /**
32       * The id of the initial child of this composite, corresponding with the state initial attribute
33       */
34      private String first;
35  
36      /**
37       * A child which identifies initial state for state machines that
38       * have substates.
39       */
40      private Initial initial;
41  
42      /**
43       * Constructor.
44       */
45      public State() {
46      }
47  
48      /**
49       * Get the initial state.
50       *
51       * @return Initial Returns the initial state.
52       */
53      public final Initial getInitial() {
54          return initial;
55      }
56  
57      /**
58       * Set the initial state.
59       *
60       * @param target
61       *            The target to set.
62       */
63      public final void setInitial(final Initial target) {
64          this.first = null;
65          this.initial = target;
66          target.setParent(this);
67      }
68  
69      /**
70       * Get the initial state's ID.
71       *
72       * @return The initial state's string ID.
73       */
74      public final String getFirst() {
75          return first;
76      }
77  
78      /**
79       * Set the initial state by its ID string.
80       *
81       * @param target
82       *            The initial target's ID to set.
83       */
84      public final void setFirst(final String target) {
85          this.first = target;
86          SimpleTransition t = new SimpleTransition();
87          t.setNext(target);
88          Initial ini = new Initial();
89          ini.setGenerated();
90          ini.setTransition(t);
91          ini.setParent(this);
92          this.initial = ini;
93      }
94  
95      /**
96       * {@inheritDoc}
97       * @return Returns true if this State has no children
98       */
99      public final boolean isAtomicState() {
100         return getChildren().isEmpty();
101     }
102 
103     /**
104      * Check whether this is a simple (leaf) state (UML terminology).
105      *
106      * @return true if this is a simple state, otherwise false
107      */
108     public final boolean isSimple() {
109         return isAtomicState();
110     }
111 
112     /**
113      * Check whether this is a composite state (UML terminology).
114      *
115      * @return true if this is a composite state, otherwise false
116      */
117     public final boolean isComposite() {
118         return !isSimple();
119     }
120 
121     /**
122      * Checks whether it is a region state (directly nested to parallel - UML
123      * terminology).
124      *
125      * @return true if this is a region state, otherwise false
126      * @see Parallel
127      */
128     public final boolean isRegion() {
129         return getParent() instanceof  Parallel;
130     }
131 
132     /**
133      * Adds an EnterableState (State, Final or Parallel) child
134      * @param es the child to add
135      */
136     @Override
137     public final void addChild(final EnterableState es) {
138         super.addChild(es);
139     }
140 }
141