001    /*--------------------------------------------------------------------------+
002    $Id: StateflowElementBase.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.commons.clone.IDeepCloneable;
022    import edu.tum.cs.simulink.model.ParameterizedElement;
023    import edu.tum.cs.simulink.model.SimulinkConstants;
024    
025    /**
026     * Base class for all Stateflow elements.
027     * 
028     * @param
029     * <P>
030     * Type of the parent of this node.
031     * 
032     * @author deissenb
033     * @author $Author: juergens $
034     * @version $Rev: 26285 $
035     * @levd.rating GREEN Hash: EE524303902E85FC1513B53E2E1F42F5
036     */
037    public abstract class StateflowElementBase<P extends IStateflowElement<?>>
038                    extends ParameterizedElement implements IDeepCloneable,
039                    IStateflowElement<P> {
040    
041            /** The parent element. */
042            private P parent;
043    
044            /** Create Stateflow element. */
045            protected StateflowElementBase() {
046                    super();
047            }
048    
049            /** Copy constructor for deep cloning. */
050            protected StateflowElementBase(StateflowElementBase<? extends P> orig) {
051                    super(orig);
052            }
053    
054            /** {@inheritDoc} */
055            public P getParent() {
056                    return parent;
057            }
058    
059            /** {@inheritDoc} */
060            public String getStateflowId() {
061                    return getParameter(SimulinkConstants.PARAM_id);
062            }
063    
064            /** {@inheritDoc} */
065            public abstract void remove();
066    
067            /** Returns Stateflow element type + id. */
068            @Override
069            public String toString() {
070                    return getClass().getSimpleName() + " [" + getStateflowId() + "]";
071            }
072    
073            /** Set parent of this element. */
074            /* package */void setParent(P parent) {
075                    if (parent != null) {
076                            CCSMPre.isTrue(this.parent == null,
077                                            "Cannot set parent for element that already has a parent");
078                    }
079                    this.parent = parent;
080            }
081    }