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 * <history> SCXML pseudo state element.
022 *
023 */
024public class History extends TransitionTarget {
025
026    /**
027     * Serial version UID.
028     */
029    private static final long serialVersionUID = 1L;
030
031    /**
032     * Whether this is a shallow or deep history, the default is shallow.
033     */
034    private boolean isDeep;
035
036    /**
037     * A conditionless transition representing the default history state
038     * and indicates the state to transition to if the parent state has
039     * never been entered before.
040     */
041    private SimpleTransition transition;
042
043    /**
044     * Default no-args constructor
045     */
046    public History() {
047        super();
048    }
049
050    /**
051     * Get the transition.
052     *
053     * @return Returns the transition.
054     */
055    public final SimpleTransition getTransition() {
056        return transition;
057    }
058
059    /**
060     * Set the transition.
061     *
062     * @param transition The transition to set.
063     */
064    public final void setTransition(final SimpleTransition transition) {
065        if (getParent() == null) {
066            throw new IllegalStateException("History transition cannot be set before setting its parent");
067        }
068        this.transition = transition;
069        this.transition.setParent(getParent());
070    }
071
072    /**
073     * Is this history "deep" (as against "shallow").
074     *
075     * @return Returns whether this is a "deep" history
076     */
077    public final boolean isDeep() {
078        return isDeep;
079    }
080
081    /**
082     * @param type The history type, which can be "shallow" or
083     * "deep"
084     */
085    public final void setType(final String type) {
086        if ("deep".equals(type)) {
087            isDeep = true;
088        }
089        //shallow is by default
090    }
091
092    /**
093     * @return Returns the TransitionalState parent
094     */
095    @Override
096    public TransitionalState getParent() {
097        return (TransitionalState)super.getParent();
098    }
099
100    /**
101     * Set the TransitionalState parent.
102     *
103     * @param parent The parent to set.
104     */
105    public final void setParent(final TransitionalState parent) {
106        super.setParent(parent);
107    }
108}
109