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
019import java.io.Serializable;
020
021/**
022 * The class in this SCXML object model that corresponds to the
023 * <initial> SCXML pseudo state element.
024 *
025 */
026public class Initial implements Serializable {
027
028    /**
029     * Serial version UID.
030     */
031    private static final long serialVersionUID = 1L;
032
033    /**
034     * The parent State of this initial
035     */
036    private State parent;
037
038    /**
039     * A conditionless transition that is always enabled and will be taken
040     * as soon as the state is entered. The target of the transition must
041     * be a descendant of the parent state of initial.
042     */
043    private SimpleTransition transition;
044
045    /**
046     * Indicator if this Initial was automatically generated and not loaded from the SCXML Document itself
047     */
048    private boolean generated;
049
050    /**
051     * Constructor.
052     */
053    public Initial() {
054        super();
055    }
056
057    /**
058     * Get the parent State.
059     *
060     * @return Returns the parent state
061     */
062    public final State getParent() {
063        return parent;
064    }
065
066
067    /**
068     * Set the parent TransitionTarget.
069     *
070     * @param parent The parent state to set
071     */
072    public final void setParent(final State parent) {
073        this.parent = parent;
074        if (transition != null) {
075            transition.setParent(parent);
076        }
077    }
078
079    /**
080     * Get the initial transition.
081     *
082     * @return Returns the transition.
083     */
084    public final SimpleTransition getTransition() {
085        return transition;
086    }
087
088    /**
089     * Set the initial transition.
090     *
091     * @param transition The transition to set.
092     */
093    public final void setTransition(final SimpleTransition transition) {
094        this.transition = transition;
095        this.transition.setParent(getParent());
096    }
097
098    /**
099     * @return true if this Initial was automatically generated and not loaded from the SCXML Document itself
100     */
101    public final boolean isGenerated() {
102        return generated;
103    }
104
105    /**
106     * Marks this Initial as automatically generated after loading the SCXML Document
107     */
108    public final void setGenerated() {
109        this.generated = true;
110    }
111}
112