Search in sources :

Example 6 with ErrorSink

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink in project osate2 by osate.

the class CombinedErrorModelSubclause method create.

/**
 * Creates an instance for the specified classifier. Processes error model subclauses owned or inherited by the classifier.
 * @param classifier the classifier for which to create the instance.
 * @return the new instance
 */
public static CombinedErrorModelSubclause create(final Classifier classifier) {
    final Map<String, PropagationPoint> points = new HashMap<>();
    final Map<String, PropagationPath> paths = new HashMap<>();
    final Map<String, ErrorFlow> flows = new HashMap<>();
    final PropagationNode propagations = new PropagationNode();
    final Set<KeywordPropagationPointType> usedKeywordPointTypes = new HashSet<>();
    final EList<Classifier> classifiers = classifier.getSelfPlusAllExtended();
    if (classifier instanceof ComponentImplementation) {
        final ComponentType ct = ((ComponentImplementation) classifier).getType();
        if (ct != null) {
            classifiers.addAll(ct.getSelfPlusAllExtended());
        }
    }
    final boolean[] subclauseFound = { false };
    for (final Classifier tmpClassifier : Lists.reverse(classifiers)) {
        ErrorModelGeUtil.getAllErrorModelSubclauses(tmpClassifier).forEachOrdered(subclause -> {
            subclauseFound[0] = true;
            addAllToMap(subclause.getPoints(), points);
            addAllToMap(subclause.getPaths(), paths);
            addAllToMap(subclause.getFlows(), flows);
            // Create a tree for error propagations
            for (final ErrorPropagation propagation : subclause.getPropagations()) {
                propagations.put(propagation);
            }
            // 
            for (final ErrorPropagation propagation : subclause.getPropagations()) {
                if (propagation.getKind() != null) {
                    usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(propagation.getKind()));
                }
            }
            for (final ErrorFlow errorFlow : subclause.getFlows()) {
                if (errorFlow instanceof ErrorPath) {
                    final ErrorPath errorPath = (ErrorPath) errorFlow;
                    if (errorPath.isAllIncoming() || errorPath.isAllOutgoing()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    }
                    if (errorPath.getIncoming() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getIncoming().getKind()));
                    }
                    if (errorPath.getOutgoing() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getOutgoing().getKind()));
                    }
                } else if (errorFlow instanceof ErrorSink) {
                    final ErrorSink errorSink = (ErrorSink) errorFlow;
                    if (errorSink.isAllIncoming()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    } else if (errorSink.getIncoming() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorSink.getIncoming().getKind()));
                    }
                } else if (errorFlow instanceof ErrorSource) {
                    final ErrorSource errorSrc = (ErrorSource) errorFlow;
                    if (errorSrc.isAll()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    } else if (errorSrc.getSourceModelElement() instanceof ErrorPropagation) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(((ErrorPropagation) errorSrc.getSourceModelElement()).getKind()));
                    }
                }
            }
        });
    }
    return new CombinedErrorModelSubclause(subclauseFound[0], points, paths, flows, usedKeywordPointTypes, propagations);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) PropagationPath(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPath) ComponentType(org.osate.aadl2.ComponentType) HashMap(java.util.HashMap) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) Classifier(org.osate.aadl2.Classifier) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) HashSet(java.util.HashSet)

Example 7 with ErrorSink

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink in project osate2 by osate.

the class EMV2Util method findErrorFlowFrom.

/**
 * find the error flow whose incoming error propagation point is flowSource
 * @param eps List of error propagations
 * @param flowSource ErrorPropagation
 * @return ErrorFlow list
 */
public static EList<ErrorFlow> findErrorFlowFrom(Collection<ErrorFlow> efs, ErrorPropagation flowSource) {
    EList<ErrorFlow> result = new BasicEList<ErrorFlow>();
    for (ErrorFlow ef : efs) {
        ErrorPropagation eprop = null;
        if (ef instanceof ErrorPath) {
            ErrorPath ep = (ErrorPath) ef;
            eprop = ep.getIncoming();
        } else if (ef instanceof ErrorSink) {
            ErrorSink es = (ErrorSink) ef;
            eprop = es.getIncoming();
        }
        if (eprop != null && eprop == flowSource) {
            result.add(ef);
        }
    }
    return result;
}
Also used : ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) BasicEList(org.eclipse.emf.common.util.BasicEList) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink)

Example 8 with ErrorSink

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink in project osate2 by osate.

the class EMV2Util method getErrorModelElement.

/**
 * Get the error model element pointed to by the EMV2Path.
 * An error model element can be ErrorSource, ErrorSink, ErrorPath, ErrorPropagaiton, ErrorState,
 * ErrorBehaviorEvent (ErrorEvent, RecoverEvent, RepairEvent), ErrorBehaviorTransition
 * This works for condition elements (ConditionElement, SConditionElement)
 * @param epath EMV2Path
 * @return NamedElement
 */
public static NamedElement getErrorModelElement(EMV2Path epath) {
    if (epath == null) {
        return null;
    }
    EMV2PathElement target = getLast(epath.getEmv2Target());
    if (target.getNamedElement() instanceof ErrorTypes) {
        EObject prev = target.eContainer();
        if (prev instanceof EMV2PathElement) {
            target = (EMV2PathElement) prev;
        } else {
            return null;
        }
    }
    NamedElement prop = target.getNamedElement();
    if (prop != null) {
        return prop;
    }
    String kind = target.getEmv2PropagationKind();
    Classifier cxtcl = EMV2Util.getAssociatedClassifier(epath);
    if (target.eContainer() instanceof EMV2PathElement) {
        // should be a subcomponent reference
        NamedElement cxt = ((EMV2PathElement) target.eContainer()).getNamedElement();
        if (cxt instanceof Subcomponent) {
            cxtcl = ((Subcomponent) cxt).getAllClassifier();
        }
    } else {
        if (epath.getContainmentPath() != null) {
            ContainmentPathElement last = getLast(epath.getContainmentPath());
            if (last.getNamedElement() instanceof Subcomponent) {
                cxtcl = ((Subcomponent) last.getNamedElement()).getAllClassifier();
            }
        }
    }
    ErrorPropagation ep = findErrorPropagation(cxtcl, kind, DirectionType.IN);
    if (ep == null) {
        ep = findErrorPropagation(cxtcl, kind, DirectionType.OUT);
    }
    return ep;
}
Also used : EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ErrorTypes(org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)

Example 9 with ErrorSink

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink in project osate2 by osate.

the class EMV2Util method findErrorFlowFromComponentInstance.

public static EList<ErrorFlow> findErrorFlowFromComponentInstance(ComponentInstance component, ErrorPropagation flowSource) {
    EList<ErrorFlow> result = new BasicEList<ErrorFlow>();
    Collection<ErrorFlow> efs = EMV2Util.getAllErrorFlows(component.getComponentClassifier());
    ErrorFlow toAdd;
    for (ErrorFlow ef : efs) {
        ErrorPropagation eprop = null;
        toAdd = ef;
        boolean isall = false;
        if (ef instanceof ErrorPath) {
            ErrorPath ep = (ErrorPath) ef;
            eprop = ep.getIncoming();
            isall = ep.isAllIncoming();
        } else if (ef instanceof ErrorSink) {
            ErrorSink es = (ErrorSink) ef;
            eprop = es.getIncoming();
            isall = es.isAllIncoming();
        }
        if ((eprop != null && eprop == flowSource) || isall) {
            result.add(toAdd);
        }
    }
    return result;
}
Also used : ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) BasicEList(org.eclipse.emf.common.util.BasicEList) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink)

Example 10 with ErrorSink

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink in project osate2 by osate.

the class EMV2Util method getAllErrorSinks.

/**
 * return list of error sinks including those inherited from classifiers being extended
 * @param cl Classifier
 * @return Collection<ErrorSource> list of error sinks declared in the flow section
 */
public static Collection<ErrorSink> getAllErrorSinks(Classifier cl) {
    HashMap<String, ErrorSink> result = new LinkedHashMap<>();
    EList<ErrorModelSubclause> emslist = getAllContainingClassifierEMV2Subclauses(cl);
    for (ErrorModelSubclause errorModelSubclause : emslist) {
        EList<ErrorFlow> eflist = errorModelSubclause.getFlows();
        for (ErrorFlow errorFlow : eflist) {
            if (errorFlow instanceof ErrorSink) {
                if (!result.containsKey(errorFlow.getName())) {
                    result.put(errorFlow.getName(), (ErrorSink) errorFlow);
                }
            }
        }
    }
    return result.values();
}
Also used : ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)7 ErrorSink (org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink)7 ErrorFlow (org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow)6 ErrorPath (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath)6 Classifier (org.osate.aadl2.Classifier)3 ErrorSource (org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource)3 BasicEList (org.eclipse.emf.common.util.BasicEList)2 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)2 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)2 Graphic (org.osate.ge.graphics.Graphic)2 StyleBuilder (org.osate.ge.graphics.StyleBuilder)2 EMV2PathElement (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement)2 ErrorModelSubclause (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause)2 Strings (com.google.common.base.Strings)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 EObject (org.eclipse.emf.ecore.EObject)1