Search in sources :

Example 1 with CanonicalBusinessObjectReference

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());
    }
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 2 with CanonicalBusinessObjectReference

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);
}
Also used : CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference)

Example 3 with CanonicalBusinessObjectReference

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));
    }
}
Also used : CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) ModeTransition(org.osate.aadl2.ModeTransition)

Example 4 with CanonicalBusinessObjectReference

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());
}
Also used : BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DeclarativeBehaviorTransition(org.osate.ba.declarative.DeclarativeBehaviorTransition) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition)

Example 5 with CanonicalBusinessObjectReference

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;
}
Also used : HashMap(java.util.HashMap) UnrecognizedDiagramType(org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) CustomDiagramType(org.osate.ge.aadl2.internal.diagramtypes.CustomDiagramType) StructureDiagramType(org.osate.ge.aadl2.internal.diagramtypes.StructureDiagramType) DiagramType(org.osate.ge.DiagramType) PackageDiagramType(org.osate.ge.aadl2.internal.diagramtypes.PackageDiagramType) UnrecognizedDiagramType(org.osate.ge.internal.diagram.runtime.types.UnrecognizedDiagramType) UUID(java.util.UUID)

Aggregations

CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)21 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)6 HashMap (java.util.HashMap)5 IProject (org.eclipse.core.resources.IProject)4 URI (org.eclipse.emf.common.util.URI)4 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)4 DiagramConfigurationBuilder (org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Objects (java.util.Objects)3 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 EObject (org.eclipse.emf.ecore.EObject)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 BusinessObjectContext (org.osate.ge.BusinessObjectContext)3 AgeDiagramProvider (org.osate.ge.internal.AgeDiagramProvider)3 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)3 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)3 Collections (java.util.Collections)2