Search in sources :

Example 1 with KeywordPropagationPointType

use of org.osate.ge.errormodel.model.KeywordPropagationPointType in project osate2 by osate.

the class ErrorModelBusinessObjectProvider method getChildBusinessObjects.

@Override
public Stream<?> getChildBusinessObjects(final BusinessObjectProviderContext ctx) {
    final Object bo = ctx.getBusinessObjectContext().getBusinessObject();
    if (bo instanceof AadlPackage) {
        return ErrorModelGeUtil.getErrorModelLibrary((AadlPackage) bo).map(lib -> Stream.concat(Stream.concat(lib.getTypes().stream(), lib.getTypesets().stream()), lib.getBehaviors().stream())).orElseGet(Stream::empty);
    } else if (bo instanceof ErrorBehaviorStateMachine) {
        final ErrorBehaviorStateMachine stateMachine = (ErrorBehaviorStateMachine) bo;
        return Stream.concat(Stream.concat(stateMachine.getEvents().stream(), stateMachine.getStates().stream()), stateMachine.getTransitions().stream());
    } else if (bo instanceof ErrorBehaviorTransition) {
        // See ErrorBehaviorTransitionHandler for details regarding how the business objects related to error behavior transitions are represented.
        final ErrorBehaviorTransition t = (ErrorBehaviorTransition) bo;
        return t.getDestinationBranches().isEmpty() ? Stream.empty() : Stream.concat(Stream.of(new BehaviorTransitionTrunk(t)), t.getDestinationBranches().stream());
    } else if (bo instanceof ErrorType) {
        final ErrorType errorType = (ErrorType) bo;
        if (errorType.getSuperType() != null) {
            return Stream.of(new ErrorTypeExtension(errorType.getSuperType(), errorType));
        }
    } else if (bo instanceof Classifier || bo instanceof Subcomponent) {
        // Anytime the children of a classifier or subcomponent is requested, process of error model subclauses
        // in the element or extended elements and cache the result.
        // Ideally, we would only do this if the classifier has changed but it would require a reliable means to
        // determine if a classifier or any classifiers it extends has changed. If extended classifiers are in another
        // package, the classifier be the same instance.
        // The object is cached so it is available when calling the business object provider on children.
        final Classifier classifier = ErrorModelGeUtil.getClassifier(ctx.getBusinessObjectContext()).orElse(null);
        if (classifier != null) {
            final CombinedErrorModelSubclause cacheEntry = CombinedErrorModelSubclause.create(classifier);
            classifierCache.put(classifier, cacheEntry);
            if (cacheEntry.subclauseExists()) {
                final Set<KeywordPropagationPointType> usedKeywordTypes = cacheEntry.getUsedKeywordPropagations();
                return Stream.of(cacheEntry.getPoints(), cacheEntry.getPaths(), cacheEntry.getFlows(), Arrays.stream(KeywordPropagationPointType.values()).map(t -> new KeywordPropagationPoint(classifier, t, usedKeywordTypes.contains(t)))).flatMap(Function.identity());
            }
        }
    } else if (bo instanceof Feature || bo instanceof PropagationPoint || bo instanceof KeywordPropagationPoint) {
        // Propagation(and containment) objects
        final CombinedErrorModelSubclause cacheEntry = getClassifierCacheEntry(ctx.getBusinessObjectContext());
        return PropagationTreeUtil.getPropagationsForBusinessObjectContext(cacheEntry.getPropagations(), ctx.getBusinessObjectContext());
    }
    return Stream.empty();
}
Also used : Arrays(java.util.Arrays) Feature(org.osate.aadl2.Feature) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) Set(java.util.Set) BusinessObjectProviderContext(org.osate.ge.BusinessObjectProviderContext) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) AadlPackage(org.osate.aadl2.AadlPackage) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Function(java.util.function.Function) ErrorTypeExtension(org.osate.ge.errormodel.model.ErrorTypeExtension) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) PropagationTreeUtil(org.osate.ge.errormodel.combined.PropagationTreeUtil) Stream(java.util.stream.Stream) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Classifier(org.osate.aadl2.Classifier) BusinessObjectProvider(org.osate.ge.BusinessObjectProvider) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Subcomponent(org.osate.aadl2.Subcomponent) WeakHashMap(java.util.WeakHashMap) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) AadlPackage(org.osate.aadl2.AadlPackage) ErrorTypeExtension(org.osate.ge.errormodel.model.ErrorTypeExtension) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) Classifier(org.osate.aadl2.Classifier) Feature(org.osate.aadl2.Feature) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) Subcomponent(org.osate.aadl2.Subcomponent) KeywordPropagationPoint(org.osate.ge.errormodel.model.KeywordPropagationPoint) Stream(java.util.stream.Stream) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType)

Example 2 with KeywordPropagationPointType

use of org.osate.ge.errormodel.model.KeywordPropagationPointType 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)

Aggregations

Classifier (org.osate.aadl2.Classifier)2 KeywordPropagationPointType (org.osate.ge.errormodel.model.KeywordPropagationPointType)2 PropagationPoint (org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 WeakHashMap (java.util.WeakHashMap)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 AadlPackage (org.osate.aadl2.AadlPackage)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 ComponentType (org.osate.aadl2.ComponentType)1 Feature (org.osate.aadl2.Feature)1 Subcomponent (org.osate.aadl2.Subcomponent)1 BusinessObjectContext (org.osate.ge.BusinessObjectContext)1 BusinessObjectProvider (org.osate.ge.BusinessObjectProvider)1 BusinessObjectProviderContext (org.osate.ge.BusinessObjectProviderContext)1 CombinedErrorModelSubclause (org.osate.ge.errormodel.combined.CombinedErrorModelSubclause)1 PropagationTreeUtil (org.osate.ge.errormodel.combined.PropagationTreeUtil)1