Search in sources :

Example 1 with AadlPackageImpl

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;
}
Also used : HashMap(java.util.HashMap) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) Classifier(org.osate.aadl2.Classifier) AadlPackageImpl(org.osate.aadl2.impl.AadlPackageImpl) SafetyContractSubclause(edu.umn.cs.crisys.safety.safety.SafetyContractSubclause) PublicPackageSection(org.osate.aadl2.PublicPackageSection) ModelUnit(org.osate.aadl2.ModelUnit) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) SafetyContract(edu.umn.cs.crisys.safety.safety.SafetyContract) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Aggregations

SafetyContract (edu.umn.cs.crisys.safety.safety.SafetyContract)1 SafetyContractSubclause (edu.umn.cs.crisys.safety.safety.SafetyContractSubclause)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 AnnexSubclause (org.osate.aadl2.AnnexSubclause)1 Classifier (org.osate.aadl2.Classifier)1 Element (org.osate.aadl2.Element)1 ModelUnit (org.osate.aadl2.ModelUnit)1 NamedElement (org.osate.aadl2.NamedElement)1 PublicPackageSection (org.osate.aadl2.PublicPackageSection)1 SystemType (org.osate.aadl2.SystemType)1 AadlPackageImpl (org.osate.aadl2.impl.AadlPackageImpl)1