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.util.ArrayList;
020import java.util.List;
021
022/**
023 * An abstract base class for state elements in SCXML that can be entered, such as State, Parallel or Final.
024 */
025public abstract class EnterableState extends TransitionTarget implements DocumentOrder {
026
027    /**
028     * The document order of this state
029     */
030    private int order;
031
032    /**
033     * List of optional OnEntry elements holding executable content to be run upon
034     * entering this transition target.
035     */
036    private List<OnEntry> onEntries;
037
038    /**
039     * List of optional OnExit elements holding executable content to be run upon
040     * exiting this transition target.
041     */
042    private List<OnExit> onExits;
043
044    public EnterableState() {
045        super();
046        onEntries = new ArrayList<OnEntry>();
047        onExits = new ArrayList<OnExit>();
048    }
049
050    /**
051     * @return the document order of this state
052     * @see DocumentOrder
053     */
054    @Override
055    public final int getOrder() {
056        return order;
057    }
058
059    /**
060     * Sets the document order of this state
061     * @param order the document order
062     * @see DocumentOrder
063     */
064    public final void setOrder(int order) {
065        this.order = order;
066    }
067
068    /**
069     * Get the OnEntry elements.
070     *
071     * @return Returns the onEntry elements
072     */
073    public final List<OnEntry> getOnEntries() {
074        return onEntries;
075    }
076
077    /**
078     * Adds an OnEntry element
079     *
080     * @param onEntry The onEntry to add.
081     */
082    public final void addOnEntry(final OnEntry onEntry) {
083        onEntry.setParent(this);
084        onEntries.add(onEntry);
085    }
086
087    /**
088     * Get the OnExit elements
089     *
090     * @return Returns the onExit elements
091     */
092    public final List<OnExit> getOnExits() {
093        return onExits;
094    }
095
096    /**
097     * Add an OnExit element
098     *
099     * @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}