001    /*--------------------------------------------------------------------------+
002    $Id: StateflowTransition.java 26285 2010-02-18 11:22:54Z juergens $
003    |                                                                          |
004    | Copyright 2005-2010 Technische Universitaet Muenchen                     |
005    |                                                                          |
006    | Licensed under the Apache License, Version 2.0 (the "License");          |
007    | you may not use this file except in compliance with the License.         |
008    | You may obtain a copy of the License at                                  |
009    |                                                                          |
010    |    http://www.apache.org/licenses/LICENSE-2.0                            |
011    |                                                                          |
012    | Unless required by applicable law or agreed to in writing, software      |
013    | distributed under the License is distributed on an "AS IS" BASIS,        |
014    | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
015    | See the License for the specific language governing permissions and      |
016    | limitations under the License.                                           |
017    +--------------------------------------------------------------------------*/
018    package edu.tum.cs.simulink.model.stateflow;
019    
020    import edu.tum.cs.commons.assertion.CCSMPre;
021    import edu.tum.cs.simulink.model.ParameterizedElement;
022    import edu.tum.cs.simulink.model.SimulinkConstants;
023    
024    /**
025     * A Stateflow transition.
026     * 
027     * @author deissenb
028     * @author $Author: juergens $
029     * @version $Rev: 26285 $
030     * @levd.rating GREEN Hash: 86F9B984B1E2B5D1C3582C094915E554
031     */
032    public class StateflowTransition extends ParameterizedElement {
033    
034            /** Source node. */
035            private StateflowNodeBase src;
036    
037            /** Destination node. */
038            private StateflowNodeBase dst;
039    
040            /** Create new default transition. */
041            public StateflowTransition(StateflowNodeBase dst) {
042                    CCSMPre.isTrue(dst != null, "Destination may not be null.");
043                    this.dst = dst;
044                    src = null;
045                    this.dst.addInTransition(this);
046            }
047    
048            /** Create new transition. */
049            public StateflowTransition(StateflowNodeBase src, StateflowNodeBase dst) {
050                    CCSMPre.isTrue(src != null && dst != null,
051                                    "Neither src nor dst may be null.");
052                    this.src = src;
053                    this.dst = dst;
054                    this.src.addOutTransition(this);
055                    this.dst.addInTransition(this);
056            }
057    
058            /** Get destination node. */
059            public StateflowNodeBase getDst() {
060                    return dst;
061            }
062    
063            /** Get label. */
064            public String getLabel() {
065                    return getParameter(SimulinkConstants.PARAM_labelString);
066            }
067    
068            /** Get source node. This may be null to indicate default transitions. */
069            public StateflowNodeBase getSrc() {
070                    return src;
071            }
072    
073            /** Remove this transition from the model. */
074            public void remove() {
075                    if (src != null) {
076                            src.removeOutTransition(this);
077                            src = null;
078                    }
079                    dst.removeInTransition(this);
080                    dst = null;
081            }
082    
083            /** toString() includes source and destination. */
084            @Override
085            public String toString() {
086                    if (src == null) {
087                            return "-> " + dst;
088                    }
089                    return src + " -> " + dst;
090            }
091    }