use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.
the class CreateConnectionsSwitch method fillInModes.
/**
* For the given connection instance, identify all connection declarations
* with "in modes." For all possible mode combinations of those "in modes,"
* add those SOMs that contain the mode instance combinations.
*
* @param conni
* the connection instance
*/
private void fillInModes(ConnectionInstance conni) {
ListIterator<ConnectionReference> refIter = conni.getConnectionReferences().listIterator();
while (refIter.hasNext()) {
ConnectionReference connRef = refIter.next();
Connection conn = connRef.getConnection();
ComponentInstance ci = connRef.getContext();
List<ModeInstance> mis = null;
// source modal
mis = getComponentModes(conni.getSource().getComponentInstance());
// conns modal
if (mis == null) {
var connModes = conn.getAllInModes();
if (connModes.isEmpty()) {
mis = getComponentModes(ci);
} else {
mis = connModes.stream().map(ci::findModeInstance).collect(Collectors.toList());
}
}
// destination modal
if (mis == null) {
mis = getComponentModes(conni.getDestination().getComponentInstance());
}
if (mis != null) {
for (ModeInstance mi : mis) {
generateModeCombinations(conni, refIter, new ArrayList<>(Collections.singletonList(mi)));
}
if (conni.getInSystemOperationModes().isEmpty()) {
warning(conni.getContainingComponentInstance(), "Connection " + conni.getName() + " was removed because it is not active in any system operation mode");
EcoreUtil.delete(conni);
}
break;
}
}
}
use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.
the class CachePropertyAssociationsSwitch method fillPropertyValue.
private void fillPropertyValue(InstanceObject io, PropertyAssociation pa, List<EvaluatedProperty> values) {
PropertyExpression lexp;
List<PropertyExpression> elems;
final Iterator<EvaluatedProperty> valueIter = values.iterator();
final EvaluatedProperty value = valueIter.next();
final List<MpvProxy> proxies = value.getProxies();
for (MpvProxy proxy : proxies) {
ModalPropertyValue newVal = Aadl2Factory.eINSTANCE.createModalPropertyValue();
List<SystemOperationMode> inSOMs = new ArrayList<SystemOperationMode>();
newVal.setOwnedValue(EcoreUtil.copy(proxy.getValue()));
// process list appends
while (valueIter.hasNext()) {
MpvProxy prx = valueIter.next().getProxies().get(0);
if (prx.isModal()) {
throw new InvalidModelException(pa, "Trying to append to a modal list value");
}
lexp = EcoreUtil.copy(prx.getValue());
elems = ((ListValue) lexp).getOwnedListElements();
((ListValue) newVal.getOwnedValue()).getOwnedListElements().addAll(0, elems);
}
boolean valueIsUsed = false;
if (!proxy.isModal()) {
valueIsUsed = true;
pa.getOwnedValues().add(newVal);
} else {
List<Mode> modes = proxy.getModes();
for (Mode mode : modes) {
if (mode instanceof SystemOperationMode) {
inSOMs.add((SystemOperationMode) mode);
} else {
if (io instanceof ConnectionReference) {
List<SystemOperationMode> conniModes = ((ConnectionInstance) io.eContainer()).getInSystemOperationModes();
if (conniModes.isEmpty()) {
conniModes = io.getSystemInstance().getSystemOperationModes();
}
List<ModeInstance> holderModes = ((ConnectionReference) io).getContext().getModeInstances();
for (ModeInstance mi : holderModes) {
if (mi.getMode() == mode) {
for (SystemOperationMode som : conniModes) {
if (som.getCurrentModes().contains(mi)) {
inSOMs.add(som);
}
}
break;
}
}
} else {
List<ModeInstance> holderModes = (io instanceof ComponentInstance) ? ((ComponentInstance) io).getModeInstances() : io.getContainingComponentInstance().getModeInstances();
for (ModeInstance mi : holderModes) {
if (mi.getMode() == mode) {
if (mode2som.containsKey(mi)) {
inSOMs.addAll(mode2som.get(mi));
break;
}
}
}
}
}
}
for (SystemOperationMode som : inSOMs) {
if (io.isActive(som)) {
newVal.getInModes().add(som);
}
}
if (!newVal.getInModes().isEmpty()) {
valueIsUsed = true;
pa.getOwnedValues().add(newVal);
}
}
if (valueIsUsed) {
// replace reference values in the context of the contained PA's owner
for (Iterator<Element> content = EcoreUtil.getAllProperContents(newVal, false); content.hasNext(); ) {
Element elem = content.next();
if (elem instanceof ReferenceValue) {
try {
PropertyExpression irv = ((ReferenceValue) elem).instantiate(io);
if (irv != null) {
EcoreUtil.replace(elem, irv);
}
} catch (InvalidModelException e) {
error(io, e.getMessage());
}
}
}
}
}
}
use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.
the class CreateConnectionsSwitch method generateModeCombinations.
private void generateModeCombinations(ConnectionInstance conni, ListIterator<ConnectionReference> refIter, List<ModeInstance> mis) {
if (!refIter.hasNext()) {
// add SOMs based on mis
SystemInstance si = (SystemInstance) conni.getElementRoot();
List<SystemOperationMode> somList = si.getSystemOperationModesFor(mis);
// check if all parts of the connection exist
outer: for (SystemOperationMode som : somList) {
if (conni.getSource().isActive(som) && conni.getDestination().isActive(som)) {
for (ConnectionReference cr : conni.getConnectionReferences()) {
if (!cr.getContext().isActive(som)) {
continue outer;
}
}
conni.getInSystemOperationModes().add(som);
}
}
} else {
ConnectionReference connRef = refIter.next();
Connection conn = connRef.getConnection();
ComponentInstance ci = connRef.getContext();
EList<Mode> connModes = conn.getAllInModes();
List<ModeInstance> nextMis = null;
if (connModes.isEmpty()) {
nextMis = getComponentModes(ci);
} else {
nextMis = connModes.stream().map(ci::findModeInstance).collect(Collectors.toList());
}
if (nextMis != null) {
for (ModeInstance mi : nextMis) {
mis.add(mi);
generateModeCombinations(conni, refIter, mis);
mis.remove(mi);
}
} else {
generateModeCombinations(conni, refIter, mis);
}
refIter.previous();
}
}
use of org.osate.aadl2.instance.ModeInstance 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);
}
use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.
the class CreateEndToEndFlowsSwitch method instantiateEndToEndFlow.
protected void instantiateEndToEndFlow(ComponentInstance ci, EndToEndFlow ete, HashMap<EndToEndFlow, List<ETEInfo>> ete2info) {
EndToEndFlowInstance etei = InstanceFactory.eINSTANCE.createEndToEndFlowInstance();
resetETECloneCount();
created = new ArrayList<ETEInfo>();
ete2info.put(ete, created);
this.ete2info = ete2info;
etei.setName(ete.getName());
etei.setEndToEndFlow(ete);
ci.getEndToEndFlows().add(etei);
addETEI.add(etei);
created.add(myInfo = new ETEInfo(etei));
EList<EList<ModeInstance>> ml = etei.getModesList();
ml.clear();
ml.add(getModeInstances(ci, ete));
processETE(ci, etei, ete);
ml.clear();
}
Aggregations