001 /*--------------------------------------------------------------------------+
002 $Id: SimulinkPortBase.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;
019
020 /**
021 * Base class for Simulink ports.
022 *
023 * @author deissenb
024 * @author $Author: juergens $
025 * @version $Rev: 26285 $
026 * @levd.rating GREEN Hash: F39DDE57EE64721C74C10EA84071D623
027 */
028 public abstract class SimulinkPortBase {
029
030 /** The block this port belongs to. */
031 private SimulinkBlock block;
032
033 /**
034 * The port index. This may be a number or a string like 'enable' indicating
035 * a special port.
036 */
037 private final String index;
038
039 /**
040 * Create Simulink port.
041 *
042 * @param block
043 * The block this port belongs to.
044 * @param index
045 * The port index. This may be a number or a string like 'enable'
046 * indicating a special port.
047 */
048 protected SimulinkPortBase(SimulinkBlock block, String index) {
049 this.block = block;
050 this.index = index;
051 }
052
053 /**
054 * Get the port index. This may be a number or a string like 'enable'
055 * indicating a special port.
056 */
057 public String getIndex() {
058 return index;
059 }
060
061 /** Get the block this port belongs to. */
062 public SimulinkBlock getBlock() {
063 return block;
064 }
065
066 /** Get string representation of this block: <index>@<block_id>. */
067 @Override
068 public String toString() {
069 return index + "@" + block.getId();
070 }
071
072 /**
073 * This only sets the block to <code>null</code>. Acutal remove
074 * implementation is done in the sub classes.
075 */
076 public void remove() {
077 block = null;
078 }
079 }