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.model; 018 019/** 020 * The class in this SCXML object model that corresponds to the 021 * <state> SCXML element. 022 * 023 */ 024public class State extends TransitionalState { 025 026 /** 027 * Serial version UID. 028 */ 029 private static final long serialVersionUID = 2L; 030 031 /** 032 * The id of the initial child of this composite, corresponding with the state initial attribute 033 */ 034 private String first; 035 036 /** 037 * A child which identifies initial state for state machines that 038 * have substates. 039 */ 040 private Initial initial; 041 042 /** 043 * Constructor. 044 */ 045 public State() { 046 } 047 048 /** 049 * Get the initial state. 050 * 051 * @return Initial Returns the initial state. 052 */ 053 public final Initial getInitial() { 054 return initial; 055 } 056 057 /** 058 * Set the initial state. 059 * 060 * @param target 061 * The target to set. 062 */ 063 public final void setInitial(final Initial target) { 064 this.first = null; 065 this.initial = target; 066 target.setParent(this); 067 } 068 069 /** 070 * Get the initial state's ID. 071 * 072 * @return The initial state's string ID. 073 */ 074 public final String getFirst() { 075 return first; 076 } 077 078 /** 079 * Set the initial state by its ID string. 080 * 081 * @param target 082 * The initial target's ID to set. 083 */ 084 public final void setFirst(final String target) { 085 this.first = target; 086 SimpleTransition t = new SimpleTransition(); 087 t.setNext(target); 088 Initial ini = new Initial(); 089 ini.setGenerated(); 090 ini.setTransition(t); 091 ini.setParent(this); 092 this.initial = ini; 093 } 094 095 /** 096 * {@inheritDoc} 097 * @return Returns true if this State has no children 098 */ 099 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