throw new InternalErrorException(
"Could not find port for From interface: " + interfaceFrom);
}
// Determine the From Relation.
Relation relationFrom;
if (interfaceFrom.parameters == null) {
if (_interfaceRelationTable.containsKey(interfaceFrom)) {
// This is a single (non-parameterized) port, and
// the relation already exists, so we reuse it.
Object o = _interfaceRelationTable.get(interfaceFrom);
if (!(o instanceof Relation)) {
throw new InternalErrorException(
"Single port should only be connected to a "
+ "Relation.");
}
relationFrom = (Relation) o;
} else {
// This is a single (non-parameterized) port, and
// the relation does not already exist, so we
// create a new relation, create a link and a
// _Link from the port to the new relation, and
// add the _Link to the list of links.
String relationName = _relations.getNewRelationName();
relationFrom = new IORelation(_compositeActor, relationName);
_interfaceRelationTable.put(interfaceFrom, relationFrom);
portFrom.link(relationFrom);
_Link link = new _Link(portFrom, relationFrom);
_linkList.add(link);
}
} else {
// This is a multi (parameterized) port, so we create
// a new relation, add it to the relation list of the
// interface, create a link and a _Link from the port
// to the new relation, and add the _Link to the list
// of links.
String relationName = _relations.getNewRelationName();
relationFrom = new IORelation(_compositeActor, relationName);
if (_interfaceRelationTable.containsKey(interfaceFrom)) {
// If the interface already has a relation list,
// add the new relation to the list.
Object o = _interfaceRelationTable.get(interfaceFrom);
if (!(o instanceof ArrayList)) {
throw new InternalErrorException(
"Multiport should only be connected to an "
+ "ArrayList of Relation.");
}
ArrayList arrayList = (ArrayList) o;
arrayList.add(relationFrom);
} else {
// If the interface does not already have a
// relation list, create it and add the new
// relation to the list.
ArrayList arrayList = new ArrayList();
arrayList.add(relationFrom);
_interfaceRelationTable.put(interfaceFrom, arrayList);
}
portFrom.link(relationFrom);
_Link link = new _Link(portFrom, relationFrom);
_linkList.add(link);
}
// Determine the To Relation.
Relation relationTo;
if (interfaceTo.parameters == null) {
if (_interfaceRelationTable.containsKey(interfaceTo)) {
// This is a single (non-parameterized) port, and
// the relation already exists, so we reuse it.
Object o = _interfaceRelationTable.get(interfaceTo);