use of org.osate.aadl2.impl.AadlPackageImpl in project AMASE by loonwerks.
the class SafetyValidator method collectFaultsFromPackages.
/**
* Get packages defined in this component impl and collect all faults from
* all included packages.
* @param compImpl
* @return Map<String, List<String>> mapping from component instance name
* to a list of associated faults.
*/
private Map<String, List<String>> collectFaultsFromPackages(ComponentImplementation compImpl) {
Map<String, List<String>> mapCompNameToFaultNames = new HashMap<String, List<String>>();
List<AadlPackageImpl> packages = new ArrayList<AadlPackageImpl>();
AadlPackageImpl aadlPackage = getAadlPackageImpl(compImpl);
packages.add(aadlPackage);
PublicPackageSection pps = aadlPackage.getOwnedPublicSection();
// Collect all imported packages and iterate through
// annexes to find safety annexes with faults.
List<ModelUnit> imports = pps.getImportedUnits();
for (ModelUnit imp : imports) {
if (imp instanceof AadlPackageImpl) {
packages.add((AadlPackageImpl) imp);
}
}
for (AadlPackageImpl aadlPack : packages) {
PublicPackageSection pub = aadlPack.getPublicSection();
for (Classifier cl : pub.getOwnedClassifiers()) {
if (cl instanceof SystemType) {
for (AnnexSubclause sub : cl.getOwnedAnnexSubclauses()) {
if (sub.getName().contains("safety")) {
for (Element child : sub.getChildren()) {
List<String> faultNames = new ArrayList<String>();
if (child instanceof SafetyContractSubclause) {
SafetyContractSubclause safetyChild = (SafetyContractSubclause) child;
SafetyContract cont = (SafetyContract) safetyChild.getContract();
faultNames.addAll(getFaultNamesFromSpecs(cont.getSpecs()));
mapCompNameToFaultNames.put(cl.getName(), faultNames);
}
}
}
}
}
}
}
return mapCompNameToFaultNames;
}
Aggregations