use of org.osate.aadl2.ProcessSubcomponent in project osate2 by osate.
the class InstantiateModel method instantiateSubcomponent.
protected void instantiateSubcomponent(final ComponentInstance parent, final ModalElement mm, final Subcomponent sub, Stack<Long> indexStack, int index) throws InterruptedException {
final ComponentInstance newInstance = InstanceFactory.eINSTANCE.createComponentInstance();
final ComponentClassifier cc;
final InstantiatedClassifier ic;
newInstance.setSubcomponent(sub);
// Issue 961: Set the category for real later (below); set it here now in case something goes wrong
newInstance.setCategory(sub.getCategory());
newInstance.setName(sub.getName());
newInstance.getIndices().addAll(indexStack);
newInstance.getIndices().add(Long.valueOf(index));
parent.getComponentInstances().add(newInstance);
ic = getInstantiatedClassifier(newInstance);
if (ic == null) {
cc = null;
} else {
cc = (ComponentClassifier) ic.getClassifier();
}
if (cc == null) {
errManager.warning(newInstance, "Instantiated subcomponent doesn't have a component classifier");
} else {
// if (cc instanceof ComponentType) {
// if (sub instanceof SystemSubcomponent || sub instanceof ProcessSubcomponent
// || sub instanceof ThreadGroupSubcomponent) {
// errManager.warning(newInstance, "Instantiated subcomponent has a component type only");
// }
// }
newInstance.setClassifier(cc);
/*
* From Issue 961:
*
* I think the category can be determined as follows:
*
* If the classifier is not abstract then use its category (and maybe check that the subcomponent either has the same category or is abstract).
* If the classifier is abstract then use the category from the subcomponent.
*
* Only if both are abstract the component instance should be abstract.
* If both are not abstract then they must have the same category. If the categories are different, validation should already have reported an
* error, and we don't instantiate models with errors. It can't hurt if the instantiator checks again, though.
*/
final ComponentCategory classifierCategory = cc.getCategory();
final ComponentCategory subcomponentCategory = sub.getCategory();
if (classifierCategory != ComponentCategory.ABSTRACT) {
newInstance.setCategory(cc.getCategory());
if (subcomponentCategory != ComponentCategory.ABSTRACT && subcomponentCategory != classifierCategory) {
errManager.warning(newInstance, "Subcomponent's category and its classifier's category do not match");
}
} else {
newInstance.setCategory(subcomponentCategory);
}
}
for (Mode mode : mm.getAllInModes()) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
ModeInstance mi = parent.findModeInstance(mode);
if (mi != null) {
newInstance.getInModes().add(mi);
}
}
populateComponentInstance(newInstance, index);
}
Aggregations