// Iterator it2 = amchgs.iterator();
for (int i = 0; i < amchgs.length; i++)
/* while (it2.hasNext()) */{
// ChangeRequest cr = (ChangeRequest) it2.next();
ChangeRequest cr = amchgs[i];
if (cr instanceof BasicCouplingChangeRequest) {
entry = ((BasicCouplingChangeRequest) cr).getContext();
// It may be that the context is a model that needs to be added before
// (has to be looked up in the hash map)
if (entry == null) {
// try to fix the context
// System.out.println("Need to fix the context!!");
ModelChangeRequest cr2 =
(ModelChangeRequest) modelsToAdd
.get(((BasicCouplingChangeRequest) cr).getModel1());
if (cr2 != null) {
entry = cr2.getContext();
}
if (entry == null) {
throw new InvalidChangeRequestException(
"Coupling change request from model ["
+ ((BasicCouplingChangeRequest) cr).getModel1()
.getFullName()
+ "] and port ["
+ ((BasicCouplingChangeRequest) cr).getPort1().getName()
+ "]. There is no valid context in which this change can take place");
}
}
// System.out.println("CR in context "+entry.REMOTEgetFullName()+" type
// "+cr.getClass().getName()+" \n "+cr.toString());
List<ChangeRequest<?>> schg = strucChangesPerModel.get(entry);
if (schg == null) {
schg = new ArrayList<>();
schg.add(cr);
strucChangesPerModel.put(entry, schg);
} else {
schg.add(cr);
}
} else if (cr instanceof ModelChangeRequest) {
entry = ((ModelChangeRequest) cr).getContext();
if (entry == null) {
throw new InvalidChangeRequestException("Model change request for "
+ ((ModelChangeRequest) cr).getModelName()
+ " But this model has no context model to be inserted in!!");
}
List<ChangeRequest<?>> schg = strucChangesPerModel.get(entry);
if (schg == null) {
schg = new ArrayList<>();
schg.add(cr);
strucChangesPerModel.put(entry, schg);
} else {
schg.add(cr);
}
} else if (cr instanceof PortChangeRequest) {
// Test whether model already exists
entry = ((PortChangeRequest) cr).getModel();
// It may be that the model whose ports should be changed needs to be
// added before (has to be looked up in the hash map)
if (entry == null) {
ModelChangeRequest cr2 =
(ModelChangeRequest) modelsToAdd.get(((PortChangeRequest) cr)
.getModel());
if (cr2 != null) {
entry = cr2.getContext();
}
if (entry == null) {
throw new InvalidChangeRequestException(
"Port change request from model ["
+ cr.getSource().getFullName()
+ "] for model ["
+ ((PortChangeRequest) cr).getModel().getFullName()
+ "] and port ["
+ ((PortChangeRequest) cr).getPort().getName()
+ "]. There is no valid context in which this change can take place");