use of org.osate.ba.aadlba.BehaviorTransition in project osate2 by osate.
the class CreateTransitionPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
if (!ctx.getDestination().getBusinessObject(BehaviorState.class).isPresent()) {
return Optional.empty();
}
final BusinessObjectContext srcContainer = getOwnerBoc(ctx.getSource(), ctx.getQueryService());
if (srcContainer == null) {
return Optional.empty();
}
final BusinessObjectContext dstContainer = getOwnerBoc(ctx.getDestination(), ctx.getQueryService());
if (dstContainer != srcContainer) {
return Optional.empty();
}
final BehaviorState srcState = ctx.getSource().getBusinessObject(BehaviorState.class).orElseThrow();
final BehaviorState dstState = ctx.getDestination().getBusinessObject(BehaviorState.class).orElseThrow();
return srcContainer.getBusinessObject(BehaviorAnnex.class).map(ba -> Operation.createSimple(srcContainer, BehaviorAnnex.class, boToModify -> {
final BehaviorTransition baTransition = (BehaviorTransition) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorTransition());
final String srcName = srcState.getName();
final String dstName = dstState.getName();
if (srcName == null || dstName == null) {
return StepResultBuilder.create().abort().build();
}
// Set source and destination for transition
for (final BehaviorState behaviorState : boToModify.getStates()) {
final String name = behaviorState.getName();
if (srcName.equalsIgnoreCase(name)) {
// Source
baTransition.setSourceState(behaviorState);
}
if (dstName.equalsIgnoreCase(name)) {
// Destination
baTransition.setDestinationState(behaviorState);
}
}
// Add new transition
boToModify.getTransitions().add(baTransition);
final String name = getTransitionName(baTransition);
baTransition.setName(name);
// Show
return StepResultBuilder.create().showNewBusinessObject(srcContainer, baTransition).build();
})).orElse(Optional.empty());
}
use of org.osate.ba.aadlba.BehaviorTransition in project osate2 by osate.
the class BehaviorTransitionHandler method getRelativeReference.
@Override
public RelativeBusinessObjectReference getRelativeReference(final ReferenceContext ctx) {
final BehaviorTransition behaviorTransition = ctx.getBusinessObject(BehaviorTransition.class).orElseThrow();
final String refSeg = getTransitionReference((BehaviorAnnex) behaviorTransition.getOwner(), behaviorTransition);
return BehaviorAnnexReferenceUtil.getTransitionRelativeReference(refSeg);
}
use of org.osate.ba.aadlba.BehaviorTransition in project osate2 by osate.
the class BehaviorTransitionHandler method delete.
@Override
public void delete(final CustomDeleteContext ctx) {
final BehaviorAnnex behaviorAnnex = ctx.getContainerBusinessObject(BehaviorAnnex.class).orElseThrow();
// Find transition by URI.
final BehaviorTransition behaviorTransition = (BehaviorTransition) behaviorAnnex.eResource().getResourceSet().getEObject(EcoreUtil.getURI(ctx.getReadonlyBoToDelete(BehaviorTransition.class).orElseThrow()), true);
EcoreUtil.remove(behaviorTransition);
if (behaviorAnnex.getTransitions().isEmpty()) {
behaviorAnnex.unsetTransitions();
}
}
use of org.osate.ba.aadlba.BehaviorTransition in project osate2 by osate.
the class BehaviorTransitionHandler method getCanonicalReference.
@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
final BehaviorTransition behaviorTransition = ctx.getBusinessObject(BehaviorTransition.class).orElseThrow();
final BehaviorAnnex behaviorAnnex = (BehaviorAnnex) behaviorTransition.getOwner();
final int index = behaviorAnnex.getTransitions().indexOf(behaviorTransition);
return new CanonicalBusinessObjectReference(BehaviorAnnexReferenceUtil.TRANSITION_TYPE, Integer.toString(index), ctx.getReferenceBuilder().getCanonicalReference(behaviorAnnex).encode());
}
use of org.osate.ba.aadlba.BehaviorTransition in project osate2 by osate.
the class AadlBaNameResolver method parentComponentIdentifiersUniquenessCheck.
/**
* Check behavior annex's sub component uniqueness within behavior annex's
* parent component scope. Conflicts are reported.
*/
private boolean parentComponentIdentifiersUniquenessCheck() {
boolean result = true;
EList<org.osate.aadl2.NamedElement> lcc = new BasicEList<org.osate.aadl2.NamedElement>(0);
// Merges parent component' subcomponents lists.
lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Data.class));
lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Mode.class));
lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Feature.class));
EList<BehaviorVariable> lvars = _ba.getVariables();
EList<BehaviorState> lstates = _ba.getStates();
EList<BehaviorTransition> ltrans = _ba.getTransitions();
// Check uniqueness within the parent component.
for (org.osate.aadl2.NamedElement ne : lcc) {
for (BehaviorVariable v : lvars) {
String bvName = v.getName();
String neName = ne.getName();
if (bvName.equalsIgnoreCase(neName)) {
reportDuplicateNameError(v, ne);
result = false;
}
}
for (BehaviorState s : lstates) {
String bsName = s.getName();
if (bsName.equalsIgnoreCase(ne.getName())) {
// Links the identifier with the mode.
if (ne instanceof Mode) {
if (s.isComplete() == false) {
_errManager.error(s, "Behavior state " + bsName + " must be declared complete in order to represent " + "mode " + ne.getName() + " located at line " + Aadl2Utils.getLocationReference(ne).getLine());
result = false;
} else {
s.setBindedMode((Mode) ne);
}
} else {
reportDuplicateNameError(s, ne);
result = false;
}
}
}
for (BehaviorTransition t : ltrans) {
String btName = t.getName();
if (btName != null && btName.equalsIgnoreCase(ne.getName())) {
reportDuplicateNameError(t, ne);
result = false;
}
}
}
return result;
}
Aggregations