001 /*--------------------------------------------------------------------------+ 002 $Id: SimulinkLine.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 import java.util.Set; 021 022 import edu.tum.cs.commons.assertion.CCSMPre; 023 024 /** 025 * A Simulink line. 026 * 027 * @author hummelb 028 * @author $Author: juergens $ 029 * @version $Rev: 26285 $ 030 * @levd.rating GREEN Hash: D945508F614C0D24A7CBFADCEA38A6AE 031 */ 032 public class SimulinkLine extends ParameterizedElement { 033 034 /** The source port of this line. */ 035 private SimulinkOutPort srcPort; 036 037 /** The target port of this line. */ 038 private SimulinkInPort dstPort; 039 040 /** Creates a new line. This adds the line to the ports. */ 041 @SuppressWarnings("null") 042 public SimulinkLine(SimulinkOutPort srcPort, SimulinkInPort dstPort) { 043 044 CCSMPre.isFalse(srcPort == null || dstPort == null, 045 "Ports may not be null!"); 046 047 this.srcPort = srcPort; 048 this.dstPort = dstPort; 049 050 srcPort.addLine(this); 051 dstPort.setLine(this); 052 } 053 054 /** Returns target port. */ 055 public SimulinkInPort getDstPort() { 056 return dstPort; 057 } 058 059 /** Get model this line belongs to. */ 060 public SimulinkModel getModel() { 061 return srcPort.getBlock().getModel(); 062 } 063 064 /** Returns source port. */ 065 public SimulinkOutPort getSrcPort() { 066 return srcPort; 067 } 068 069 /** Remove the line from the ports. */ 070 public void remove() { 071 CCSMPre.isFalse(srcPort == null || dstPort == null, 072 "May not remove lines twice!"); 073 074 srcPort.removeLine(this); 075 dstPort.removeLine(this); 076 srcPort = null; 077 dstPort = null; 078 } 079 080 /** Get string representation of the line. */ 081 @Override 082 public String toString() { 083 return srcPort + " -> " + dstPort; 084 } 085 086 /** 087 * Get line default parameter. 088 */ 089 @Override 090 /* package */String getDefaultParameter(String name) { 091 return getModel().getLineDefaultParameter(name); 092 } 093 094 /** 095 * Get line default parameter names. 096 */ 097 @Override 098 /* package */Set<String> getDefaultParameterNames() { 099 return getModel().getLineDefaultParameterNames(); 100 } 101 }