use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class ComponentInstanceHandler method getCanonicalReference.
@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
final ComponentInstance bo = ctx.getBusinessObject(ComponentInstance.class).get();
final String systemInstanceKey = AadlReferenceUtil.getSystemInstanceKey(bo);
if (bo instanceof SystemInstance) {
return AadlReferenceUtil.getCanonicalBusinessObjectReferenceForSystemInstance(systemInstanceKey);
} else {
return new CanonicalBusinessObjectReference(AadlReferenceUtil.INSTANCE_ID, AadlReferenceUtil.COMPONENT_INSTANCE_KEY, systemInstanceKey, bo.getInstanceObjectPath());
}
}
use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class DeclarativeReferenceResolver method resolve.
@Override
public Optional<Object> resolve(final ResolveContext ctx) {
final CanonicalBusinessObjectReference ref = ctx.getReference();
final List<String> refSegs = ref.getSegments();
if (refSegs.size() < 2) {
return Optional.empty();
}
// The object that will be returned
Object referencedObject = null;
final String type = refSegs.get(0);
final String qualifiedName = refSegs.get(1);
if (type.equals(DeclarativeReferenceType.PACKAGE.getId())) {
referencedObject = getAadlPackage(qualifiedName);
} else if (type.equals(DeclarativeReferenceType.CLASSIFIER.getId())) {
referencedObject = getClassifierByQualifiedName(qualifiedName);
}
return Optional.ofNullable(referencedObject);
}
use of org.osate.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class ModeTransitionHandler method getCanonicalReference.
@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
final ModeTransition mt = ctx.getBusinessObject(ModeTransition.class).get();
final String name = mt.getName();
if (name == null) {
return AadlReferenceUtil.getCanonicalReferenceForUnnamedModeTransition(mt);
} else {
return new CanonicalBusinessObjectReference(DeclarativeReferenceType.MODE_TRANSITION_NAMED.getId(), ctx.getReferenceBuilder().getCanonicalReference(mt.eContainer()).encode(), AadlReferenceUtil.getNameForSerialization(mt));
}
}
use of org.osate.ge.CanonicalBusinessObjectReference 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.ge.CanonicalBusinessObjectReference in project osate2 by osate.
the class DiagramSerialization method createAgeDiagram.
/**
* Converts the serialized diagram to a runtime diagram
* @param project the project in which the serialized diagram is contained.
* @param mmDiagram the serialized diagram
* @param extRegistry the Eclipse extension registry
* @return the runtime diagram
*/
public static AgeDiagram createAgeDiagram(final IProject project, final org.osate.ge.diagram.Diagram mmDiagram, final ExtensionRegistryService extRegistry) {
Objects.requireNonNull(extRegistry, "extRegistry is null");
// Set the id which should be used for new diagram elements.
final AgeDiagram ageDiagram = new AgeDiagram();
// Read the diagram configuration
// Set the diagram type
final String diagramTypeId;
if (mmDiagram.getConfig() == null || mmDiagram.getConfig().getType() == null) {
// Assign a diagram type ID if the diagram does not have specify one.
String autoAssignedDiagramTypeId = CustomDiagramType.ID;
// Set the diagram type based on the diagram's context
if (mmDiagram.getConfig() != null) {
final CanonicalBusinessObjectReference contextRef = convert(mmDiagram.getConfig().getContext());
if (contextRef != null && contextRef.getSegments().size() > 1) {
if (DeclarativeReferenceType.PACKAGE.getId().equals(contextRef.getSegments().get(0))) {
autoAssignedDiagramTypeId = PackageDiagramType.ID;
} else if (DeclarativeReferenceType.CLASSIFIER.getId().equals(contextRef.getSegments().get(0))) {
autoAssignedDiagramTypeId = StructureDiagramType.ID;
}
}
}
diagramTypeId = autoAssignedDiagramTypeId;
} else {
diagramTypeId = mmDiagram.getConfig().getType();
}
final DiagramType diagramType = extRegistry.getDiagramTypeById(diagramTypeId).orElseGet(() -> new UnrecognizedDiagramType(diagramTypeId));
final DiagramConfigurationBuilder configBuilder = new DiagramConfigurationBuilder(diagramType, false);
if (mmDiagram.getConfig() != null) {
final org.osate.ge.diagram.DiagramConfiguration mmDiagramConfig = mmDiagram.getConfig();
configBuilder.contextBoReference(convert(mmDiagramConfig.getContext()));
final org.osate.ge.diagram.AadlPropertiesSet enabledAadlProperties = mmDiagramConfig.getEnabledAadlProperties();
if (enabledAadlProperties != null) {
for (final String enabledProperty : enabledAadlProperties.getProperty()) {
configBuilder.addAadlProperty(enabledProperty);
}
}
configBuilder.connectionPrimaryLabelsVisible(mmDiagramConfig.getConnectionPrimaryLabelsVisible());
}
// Ensure UUIDs are valid and handle migration from legacy id's.
final Map<Long, UUID> legacyIdToUuidMap = new HashMap<>();
ensureIdsAreValid(mmDiagram, legacyIdToUuidMap);
updateReferencesToLegacyIds(mmDiagram, legacyIdToUuidMap);
ageDiagram.modify("Configure Diagram", m -> {
m.setDiagramConfiguration(configBuilder.build());
});
// Read elements
ageDiagram.modify("Read from File", m -> {
readElements(project, m, ageDiagram, mmDiagram, legacyIdToUuidMap);
});
return ageDiagram;
}
Aggregations