use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath in project osate2 by osate.
the class ErrorFlowHandler method getGraphicalConfiguration.
@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
final ErrorFlow bo = ctx.getBusinessObjectContext().getBusinessObject(ErrorFlow.class).get();
final BusinessObjectContext classifierBoc = ctx.getBusinessObjectContext().getParent();
if (classifierBoc == null) {
return Optional.empty();
}
// Determine the type of graphic and the source and destination of the connection
final ErrorFlowEnd src;
final ErrorFlowEnd dst;
final Graphic graphic;
if (bo instanceof ErrorSource) {
graphic = SOURCE_GRAPHIC;
final ErrorSource es = (ErrorSource) bo;
src = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, es.isAll(), es.getSourceModelElement()).orElse(null);
dst = null;
} else if (bo instanceof ErrorSink) {
graphic = SINK_GRAPHIC;
final ErrorSink es = (ErrorSink) bo;
src = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, es.isAllIncoming(), es.getIncoming()).orElse(null);
dst = null;
} else if (bo instanceof ErrorPath) {
graphic = PATH_GRAPHIC;
final ErrorPath ep = (ErrorPath) bo;
src = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, ep.isAllIncoming(), ep.getIncoming()).orElse(null);
dst = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, ep.isAllOutgoing(), ep.getOutgoing()).orElse(null);
} else {
return Optional.empty();
}
// Determine style
final StyleBuilder sb = StyleBuilder.create(GraphicalExtensionUtil.isInherited(ctx.getBusinessObjectContext()) ? GraphicalExtensionUtil.STYLE_INHERITED_ELEMENT : Style.EMPTY).lineWidth(4.0);
final boolean partial = (src != null && src.partial) || (dst != null && dst.partial);
if (partial) {
sb.dotted();
}
return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).style(sb.build()).defaultDockingPosition(DockingPosition.ANY).source(src == null ? null : src.boc).destination(dst == null ? null : dst.boc).build());
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath in project osate2 by osate.
the class ErrorPropagationHandler method canDelete.
@Override
public boolean canDelete(final CanDeleteContext ctx) {
final ErrorPropagation bo = ctx.getBusinessObject(ErrorPropagation.class).get();
// Don't allow deleting if there exists an error flow that references the error propagation
final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(bo.getContainingClassifier());
return !combined.getFlows().anyMatch(f -> {
if (f instanceof ErrorSource) {
final ErrorSource src = (ErrorSource) f;
return src.getSourceModelElement() == bo;
} else if (f instanceof ErrorSink) {
final ErrorSink snk = (ErrorSink) f;
return snk.getIncoming() == bo;
} else if (f instanceof ErrorPath) {
final ErrorPath path = (ErrorPath) f;
return path.getIncoming() == bo || path.getOutgoing() == bo;
}
return false;
});
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath 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);
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath in project osate2 by osate.
the class EMV2Util method mapToken.
/**
* figure out the target typetoken based on the source and type mappings
* Path can be a connection instance, a flow spec instance, or an error flow
* If null or no mapping found, then use source type token
* @param path connection instance, flow spec instance, error flow
* @param path path of mapping
* @return TypeToken
*/
public static TypeToken mapToken(TypeToken sourceToken, EObject path) {
TypeToken result = sourceToken;
if (path instanceof ConnectionInstance) {
if (sourceToken != null) {
// TODO lookup type transformations for connections and use them to determine target type
ConnectionReference connref = Aadl2InstanceUtil.getTopConnectionReference((ConnectionInstance) path);
ComponentInstance parentci = connref.getContext();
TypeTransformationSet tts = getAllTypeTransformationSet(parentci);
result = EMV2TypeSetUtil.mapTypeToken(sourceToken, tts);
}
} else if (path instanceof ErrorPath) {
ErrorPath epath = (ErrorPath) path;
// map the token
TypeSet ttup = epath.getTargetToken();
if (ttup == null) {
// map token via tms
TypeMappingSet tms = getUseMappings(epath);
if (tms != null) {
result = EMV2TypeSetUtil.mapTypeToken(sourceToken, tms);
}
} else {
result = ttup.getTypeTokens().get(0);
}
} else if (path instanceof FlowSpecificationInstance) {
// pass on source token
}
return result;
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath 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;
}
Aggregations