* the involved cm
*/
public final void copyValues(Iterator<BasicCoupling> couplingIterator,
IBasicCoupledModel model, AM influencees, CM involvedCM) {
while (couplingIterator.hasNext()) {
BasicCoupling coupling = couplingIterator.next();
if (coupling instanceof Coupling) {
// get the next coupling
Coupling currentCoupling = (Coupling) coupling;
// this is an out coupling of the current childModel
// backup a reference to the port
IPort a = currentCoupling.getPort1();
// System.out.println("Copying in "+model.getFullName());
// get the number of elements stored at this out port
int numberOfElements = a.getValuesCount();
// if there are any elements
if (numberOfElements > 0) {
// we want handle only real messages and not empty (null) messages
// backup the target port
// System.out.println("copy to
// "+currentCoupling.getModel2().getFullName());
IPort b = currentCoupling.getPort2();
// copy all elements to the target port, but do not remove them
// from the source port (they may have to copied more than once!!)
copyPortValues(a, b, numberOfElements);
addToInfluenceeSet(model, influencees, involvedCM,
currentCoupling.getModel2());
}
} // if coupling
else if (coupling instanceof ClassCoupling) {
// get the next coupling
ClassCoupling currentCoupling = (ClassCoupling) coupling;
// this is an out coupling of the current childModel
// backup a reference to the port
IPort a = currentCoupling.getPort1();
// get the number of elements stored at this out port
int numberOfElements = a.getValuesCount();
// if there are any elements
if (numberOfElements > 0) {
// retrieve list containing the selected targets of this classcoupling
List<IBasicDEVSModel> targets =
currentCoupling.getSelector().executeSelection(
model.getSubmodelsByClass(currentCoupling.getModel2()));
// create iterator for retrieved elements
for (int j = 0; j < targets.size(); j++) {
// retrieve current targetmodel
BasicDEVSModel targetModel = (BasicDEVSModel) targets.get(j);
// retrieve inputport for the given model
IPort b = targetModel.getInPort(currentCoupling.getPort2());
copyPortValues(a, b, numberOfElements);
// the the target model is an atomic model remember that it got
// an external message
addToInfluenceeSet(model, influencees, involvedCM, targetModel);
}
}
} // if classcoupling
else if (coupling instanceof MultiCoupling) {
// get the next coupling
MultiCoupling currentCoupling = (MultiCoupling) coupling;
// this is an out coupling of the current childModel
// backup a reference to the port
IPort a = currentCoupling.getPort1();
// get the number of elements stored at this out port
int numberOfElements = a.getValuesCount();
// if there are any elements
if (numberOfElements > 0) {
// retrieve vector containing the selected targets of this
// classcoupling
List<IBasicDEVSModel> targets =
currentCoupling.getSelector().executeSelection(
currentCoupling.getTargetsAsArrayList());
// create iterator for retrieved elements
// Iterator targetIterator = targets.iterator();
// System.out.println(currentCoupling.getTargetsAsArrayList().size());
for (int j = 0; j < targets.size(); j++) {
// retrieve current targetmodel
IBasicDEVSModel targetModel = targets.get(j);
// retrieve inputport for the given model
String portname =
(currentCoupling.getTargets().getTarget(targetModel))
.getPortName();
IPort b = targetModel.getInPort(portname);
copyPortValues(a, b, numberOfElements);
// the the target model is an atomic model remember that it got
// an external message
addToInfluenceeSet(model, influencees, involvedCM, targetModel);
}
}
} // if multicoupling
else {
throw new InvalidModelException(
"This coupling class is not yet supported!! ("
+ coupling.getClass().getName() + ")");
}
} // end of while(coupIter.hasNext())
}