Search in sources :

Example 11 with ComponentType

use of org.osate.aadl2.ComponentType in project AGREE by loonwerks.

the class EphemeralImplementationUtil method generateEphemeralCompInstanceFromImplementation.

/**
 * Generate an ephemeral {@link SystemInstance} matching the subtype of the given {@link ComponentType}.
 * <p>
 * Ephemerally generated system instances are placed it in an ephemeral {@link Resource}.  The ephemeral
 * resources are intended to have short lifecycles and deleted by the {@link cleanup} method.
 *
 * @param ct The component type for which to create an ephemeral implementation.
 * @return A system instance for the given component type.
 * @throws Exception
 * @since 2.8
 */
@SuppressWarnings("unchecked")
public SystemInstance generateEphemeralCompInstanceFromImplementation(ComponentImplementation ci) throws Exception {
    final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
    Resource instanceAadlResource = getResource(InstantiateModel.getInstanceModelURI(ci));
    ephemeralResources.add(instanceAadlResource);
    List<SystemInstance> instanceResultList;
    SystemInstance instanceResult;
    // We execute this command on the command stack because otherwise, we will not
    // have write permissions on the editing domain.
    Command instanceCmd = new RecordingCommand(domain) {

        public SystemInstance systemInstance;

        @Override
        protected void doExecute() {
            try {
                final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
                systemInstance = instantiateModel.createSystemInstance(ci, instanceAadlResource);
            } catch (InterruptedException e) {
            // Do nothing. Will be thrown after execute.
            } catch (Exception e) {
                e.printStackTrace();
                errorMessage = e.getMessage();
                e.getMessage();
            }
        }

        @Override
        public List<SystemInstance> getResult() {
            return Collections.singletonList(systemInstance);
        }
    };
    ((TransactionalCommandStack) domain.getCommandStack()).execute(instanceCmd, null);
    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }
    try {
        // We're done: Save the model.
        monitor.subTask("Saving instance model");
        instanceAadlResource.save(null);
    } catch (IOException e) {
        e.printStackTrace();
        setErrorMessage(e.getMessage());
        return null;
    }
    instanceResultList = (List<SystemInstance>) instanceCmd.getResult();
    instanceResult = instanceResultList.get(0);
    return instanceResult;
}
Also used : InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) Resource(org.eclipse.emf.ecore.resource.Resource) Aadl2Factory(org.osate.aadl2.Aadl2Factory) WorkspaceEditingDomainFactory(org.eclipse.emf.workspace.WorkspaceEditingDomainFactory) IOException(java.io.IOException) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) RollbackException(org.eclipse.emf.transaction.RollbackException) IOException(java.io.IOException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) TransactionalCommandStack(org.eclipse.emf.transaction.TransactionalCommandStack) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Command(org.eclipse.emf.common.command.Command) SystemInstance(org.osate.aadl2.instance.SystemInstance)

Example 12 with ComponentType

use of org.osate.aadl2.ComponentType in project AGREE by loonwerks.

the class EphemeralImplementationUtil method generateEphemeralCompInstanceFromType.

/**
 * Generate an ephemeral {@link SystemInstance} matching the subtype of the given {@link ComponentType}.
 * <p>
 * Ephemerally generated system instances are placed it in an ephemeral {@link Resource}.  The ephemeral
 * resources are intended to have short lifecycles and deleted by the {@link cleanup} method.
 *
 * @param ct The component type for which to create an ephemeral implementation.
 * @return A system instance for the given component type.
 * @throws Exception
 * @since 2.8
 */
@SuppressWarnings("unchecked")
public SystemInstance generateEphemeralCompInstanceFromType(ComponentType ct) throws Exception {
    Resource implementationAadlResource = getResource(getEphemeralImplURI(ct));
    ephemeralResources.add(implementationAadlResource);
    List<ComponentImplementation> implementationResultList;
    ComponentImplementation implementationResult;
    final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
    Command implementationCmd = new RecordingCommand(domain) {

        public ComponentImplementation implementation;

        @Override
        protected void doExecute() {
            try {
                implementation = createComponentImplementationInternal(ct, implementationAadlResource);
            } catch (InterruptedException e) {
            // Do nothing. Will be thrown after execute.
            }
        }

        @Override
        public List<ComponentImplementation> getResult() {
            return Collections.singletonList(implementation);
        }
    };
    ((TransactionalCommandStack) domain.getCommandStack()).execute(implementationCmd, null);
    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }
    try {
        // We're done: Save the model.
        // We don't respond to a cancel at this point
        monitor.subTask("Saving implementation model");
        implementationAadlResource.save(null);
    } catch (IOException e) {
        e.printStackTrace();
        setErrorMessage(e.getMessage());
        return null;
    }
    implementationResultList = (List<ComponentImplementation>) implementationCmd.getResult();
    implementationResult = implementationResultList.get(0);
    Resource instanceAadlResource = getResource(InstantiateModel.getInstanceModelURI(implementationResult));
    ephemeralResources.add(instanceAadlResource);
    List<SystemInstance> instanceResultList;
    SystemInstance instanceResult;
    // We execute this command on the command stack because otherwise, we will not
    // have write permissions on the editing domain.
    Command instanceCmd = new RecordingCommand(domain) {

        public SystemInstance systemInstance;

        @Override
        protected void doExecute() {
            try {
                final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
                systemInstance = instantiateModel.createSystemInstance(implementationResult, instanceAadlResource);
            } catch (InterruptedException e) {
            // Do nothing. Will be thrown after execute.
            } catch (Exception e) {
                e.printStackTrace();
                errorMessage = e.getMessage();
                e.getMessage();
            }
        }

        @Override
        public List<SystemInstance> getResult() {
            return Collections.singletonList(systemInstance);
        }
    };
    ((TransactionalCommandStack) domain.getCommandStack()).execute(instanceCmd, null);
    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }
    try {
        // We're done: Save the model.
        monitor.subTask("Saving instance model");
        instanceAadlResource.save(null);
    } catch (IOException e) {
        e.printStackTrace();
        setErrorMessage(e.getMessage());
        return null;
    }
    instanceResultList = (List<SystemInstance>) instanceCmd.getResult();
    instanceResult = instanceResultList.get(0);
    return instanceResult;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) Resource(org.eclipse.emf.ecore.resource.Resource) Aadl2Factory(org.osate.aadl2.Aadl2Factory) WorkspaceEditingDomainFactory(org.eclipse.emf.workspace.WorkspaceEditingDomainFactory) IOException(java.io.IOException) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) RollbackException(org.eclipse.emf.transaction.RollbackException) IOException(java.io.IOException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) TransactionalCommandStack(org.eclipse.emf.transaction.TransactionalCommandStack) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Command(org.eclipse.emf.common.command.Command) SystemInstance(org.osate.aadl2.instance.SystemInstance)

Example 13 with ComponentType

use of org.osate.aadl2.ComponentType in project AGREE by loonwerks.

the class VerifyHandler method getComponentImplementation.

protected ComponentImplementation getComponentImplementation(Element root, EphemeralImplementationUtil implUtil) {
    Classifier classifier = getOutermostClassifier(root);
    if (isRealizability()) {
        if (!(classifier instanceof ComponentType)) {
            throw new AgreeException("Must select an AADL Component Type");
        }
        ComponentImplementation result;
        try {
            result = implUtil.generateEphemeralCompImplFromType((ComponentType) classifier);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AgreeException("Error creating component implementation.");
        }
        return result;
    } else {
        if (classifier instanceof ComponentImplementation) {
            return (ComponentImplementation) classifier;
        }
        if (!(classifier instanceof ComponentType)) {
            throw new AgreeException("Must select an AADL Component Type or Implementation");
        }
        ComponentType ct = (ComponentType) classifier;
        List<ComponentImplementation> cis = getComponentImplementations(ct);
        if (cis.size() == 0) {
            throw new AgreeException("AADL Component Type has no implementation to verify");
        } else if (cis.size() == 1) {
            ComponentImplementation ci = cis.get(0);
            Shell shell = getWindow().getShell();
            String message = "User selected " + ct.getFullName() + ".\nRunning analysis on " + ci.getFullName() + " instead.";
            shell.getDisplay().asyncExec(() -> MessageDialog.openInformation(shell, "Analysis information", message));
            return ci;
        } else {
            throw new AgreeException("AADL Component Type has multiple implementations to verify: please select just one");
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) Shell(org.eclipse.swt.widgets.Shell) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) PartInitException(org.eclipse.ui.PartInitException) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) JKindException(jkind.JKindException)

Example 14 with ComponentType

use of org.osate.aadl2.ComponentType in project AGREE by loonwerks.

the class VerifyHandler method getComponentImplementations.

private List<ComponentImplementation> getComponentImplementations(ComponentType ct) {
    List<ComponentImplementation> result = new ArrayList<>();
    AadlPackage pkg = AadlUtil.getContainingPackage(ct);
    for (ComponentImplementation ci : EcoreUtil2.getAllContentsOfType(pkg, ComponentImplementation.class)) {
        if (ci.getType().equals(ct)) {
            result.add(ci);
        }
    }
    return result;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) AadlPackage(org.osate.aadl2.AadlPackage) ArrayList(java.util.ArrayList)

Example 15 with ComponentType

use of org.osate.aadl2.ComponentType in project AGREE by loonwerks.

the class MATLABFunctionHandler method setMatlabExportInfo.

private void setMatlabExportInfo(ComponentType ct, ModelInfo info) {
    ListValue lv = getOrCreateSourceText(ct);
    StringLiteral sl1 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
    sl1.setValue(savePathToAADLProperty(info.outputDirPath));
    StringLiteral sl2 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
    sl2.setValue(savePathToAADLProperty(info.implMdlPath));
    StringLiteral sl3 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
    sl3.setValue(savePathToAADLProperty(info.verifyMdlName));
    StringLiteral sl4 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
    sl4.setValue(savePathToAADLProperty(info.subsystemName));
}
Also used : StringLiteral(org.osate.aadl2.StringLiteral) ListValue(org.osate.aadl2.ListValue)

Aggregations

ComponentType (org.osate.aadl2.ComponentType)73 ComponentImplementation (org.osate.aadl2.ComponentImplementation)46 Classifier (org.osate.aadl2.Classifier)34 ArrayList (java.util.ArrayList)29 AnnexSubclause (org.osate.aadl2.AnnexSubclause)24 ComponentClassifier (org.osate.aadl2.ComponentClassifier)24 EObject (org.eclipse.emf.ecore.EObject)18 NamedElement (org.osate.aadl2.NamedElement)18 EventDataPort (org.osate.aadl2.EventDataPort)15 DataPort (org.osate.aadl2.DataPort)14 EventPort (org.osate.aadl2.EventPort)14 AadlPackage (org.osate.aadl2.AadlPackage)13 Feature (org.osate.aadl2.Feature)13 CyberMission (com.ge.research.osate.verdict.dsl.verdict.CyberMission)11 CyberRel (com.ge.research.osate.verdict.dsl.verdict.CyberRel)11 CyberReq (com.ge.research.osate.verdict.dsl.verdict.CyberReq)11 Event (com.ge.research.osate.verdict.dsl.verdict.Event)11 SafetyRel (com.ge.research.osate.verdict.dsl.verdict.SafetyRel)11 SafetyReq (com.ge.research.osate.verdict.dsl.verdict.SafetyReq)11 Statement (com.ge.research.osate.verdict.dsl.verdict.Statement)11