Search in sources :

Example 1 with InstantiateModel

use of org.osate.aadl2.instantiation.InstantiateModel 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 2 with InstantiateModel

use of org.osate.aadl2.instantiation.InstantiateModel 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 3 with InstantiateModel

use of org.osate.aadl2.instantiation.InstantiateModel in project osate2 by osate.

the class InstantiateModel method rebuildInstanceModelFile.

/**
 * This method will construct an instance model, save it on disk and return
 * its root object The method will make sure the declarative models are up
 * to date.
 *
 * @param si system implementation
 *
 * @return SystemInstance or <code>null</code> if cancelled.
 * @since 1.1
 */
public static SystemInstance rebuildInstanceModelFile(final IResource ires, final IProgressMonitor monitor) throws Exception {
    ires.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
    ResourceSet rset = new ResourceSetImpl();
    Resource res = rset.getResource(OsateResourceUtil.toResourceURI(ires), true);
    SystemInstance target = (SystemInstance) res.getContents().get(0);
    ComponentImplementation ci = target.getComponentImplementation();
    URI uri = EcoreUtil.getURI(ci);
    res.getContents().clear();
    res.save(null);
    res.unload();
    ci = (ComponentImplementation) rset.getEObject(uri, true);
    if (ci == null) {
        // The root component instance doesn't exist anymore
        throw new RootMissingException();
    }
    final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
    SystemInstance root = instantiateModel.createSystemInstance(ci, res);
    return root;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) SystemInstance(org.osate.aadl2.instance.SystemInstance) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) InstanceFactory(org.osate.aadl2.instance.InstanceFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager)

Example 4 with InstantiateModel

use of org.osate.aadl2.instantiation.InstantiateModel in project osate2 by osate.

the class InstantiateModel method rebuildAllInstanceModelFiles.

/*
	 * This method will regenerate all instance models in the workspace
	 */
public static void rebuildAllInstanceModelFiles(final IProgressMonitor monitor) throws Exception {
    HashSet<IFile> files = TraverseWorkspace.getInstanceModelFilesInWorkspace();
    List<URI> instanceRoots = new ArrayList<URI>();
    List<IResource> instanceIResources = new ArrayList<IResource>();
    ResourceSet rset = new ResourceSetImpl();
    for (IFile iFile : files) {
        IResource ires = iFile;
        ires.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
        Resource res = rset.getResource(OsateResourceUtil.toResourceURI(ires), true);
        SystemInstance target = (SystemInstance) res.getContents().get(0);
        ComponentImplementation ci = target.getComponentImplementation();
        URI uri = EcoreUtil.getURI(ci);
        instanceRoots.add(uri);
        instanceIResources.add(ires);
        res.getContents().clear();
        res.save(null);
        res.unload();
    }
    for (int i = 0; i < instanceRoots.size(); i++) {
        ComponentImplementation ci = (ComponentImplementation) rset.getEObject(instanceRoots.get(i), true);
        monitor.subTask("Reinstantiating " + ci.getName());
        final InstantiateModel instantiateModel = new InstantiateModel(new NullProgressMonitor(), new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
        Resource res = rset.getResource(OsateResourceUtil.toResourceURI(instanceIResources.get(i)), true);
        instantiateModel.createSystemInstance(ci, res);
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) InstanceFactory(org.osate.aadl2.instance.InstanceFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) SystemInstance(org.osate.aadl2.instance.SystemInstance) IResource(org.eclipse.core.resources.IResource)

Example 5 with InstantiateModel

use of org.osate.aadl2.instantiation.InstantiateModel in project osate2 by osate.

the class InstantiateModel method processConnections.

// --------------------------------------------------------------------------------------------
// Methods for connection sets and connection patterns
// --------------------------------------------------------------------------------------------
private void processConnections(SystemInstance root) throws InterruptedException {
    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }
    EList<ComponentInstance> replicateConns = new UniqueEList<ComponentInstance>();
    List<ConnectionInstance> toRemove = new ArrayList<ConnectionInstance>();
    EList<ConnectionInstance> connilist = root.getAllConnectionInstances();
    for (ConnectionInstance conni : connilist) {
        // track all component instances that contain connection instances
        replicateConns.add(conni.getComponentInstance());
        PropertyAssociation setPA = getPA(conni, "Connection_Set");
        PropertyAssociation patternPA = getPA(conni, "Connection_Pattern");
        if (setPA == null && patternPA == null) {
            // OsateDebug.osateDebug("[InstantiateModel] processConnections");
            LinkedList<Integer> srcDims = new LinkedList<Integer>();
            LinkedList<Integer> dstDims = new LinkedList<Integer>();
            LinkedList<Integer> srcSizes = new LinkedList<Integer>();
            LinkedList<Integer> dstSizes = new LinkedList<Integer>();
            boolean done = false;
            analyzePath(conni.getContainingComponentInstance(), conni.getSource(), null, srcDims, srcSizes);
            analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), null, dstDims, dstSizes);
            for (int d : srcDims) {
                if (d != 0) {
                    done = true;
                    if (interpretConnectionPatterns(conni, false, null, 0, srcSizes, 0, dstSizes, 0, new ArrayList<Long>(), new ArrayList<Long>())) {
                        toRemove.add(conni);
                    }
                    break;
                }
            }
            if (!done) {
                for (int d : dstDims) {
                    if (d != 0) {
                        done = true;
                        if (interpretConnectionPatterns(conni, false, null, 0, srcSizes, 0, dstSizes, 0, new ArrayList<Long>(), new ArrayList<Long>())) {
                            toRemove.add(conni);
                        }
                        break;
                    }
                }
            }
        } else if (patternPA != null) {
            boolean isOpposite = Aadl2InstanceUtil.isOpposite(conni);
            EcoreUtil.remove(patternPA);
            List<PropertyExpression> patterns = ((ListValue) patternPA.getOwnedValues().get(0).getOwnedValue()).getOwnedListElements();
            for (PropertyExpression pe : patterns) {
                List<PropertyExpression> pattern = ((ListValue) pe).getOwnedListElements();
                LinkedList<Integer> srcSizes = new LinkedList<Integer>();
                LinkedList<Integer> dstSizes = new LinkedList<Integer>();
                analyzePath(conni.getContainingComponentInstance(), conni.getSource(), null, null, srcSizes);
                analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), null, null, dstSizes);
                if (srcSizes.size() == 0 && dstSizes.size() == 0) {
                    errManager.warning(conni, "Connection pattern specified for connection that does not connect array elements.");
                } else {
                    if (interpretConnectionPatterns(conni, isOpposite, pattern, 0, srcSizes, 0, dstSizes, 0, new ArrayList<Long>(), new ArrayList<Long>())) {
                        toRemove.add(conni);
                    }
                }
            }
        }
        // no else as we want both the pattern and the connection set evaluated
        if (setPA != null) {
            EcoreUtil.remove(setPA);
            // TODO-LW: modal conn set allowed?
            List<Long> srcIndices;
            List<Long> dstIndices;
            for (PropertyExpression pe : ((ListValue) setPA.getOwnedValues().get(0).getOwnedValue()).getOwnedListElements()) {
                RecordValue rv = (RecordValue) pe;
                srcIndices = getIndices(rv, "src");
                dstIndices = getIndices(rv, "dst");
                if (Aadl2InstanceUtil.isOpposite(conni)) {
                    // flip indices since we are going in the opposite direction
                    createNewConnection(conni, dstIndices, srcIndices);
                } else {
                    createNewConnection(conni, srcIndices, dstIndices);
                }
            }
            toRemove.add(conni);
        }
    }
    for (ConnectionInstance conni : toRemove) {
        EcoreUtil.delete(conni);
    }
    replicateConnections(replicateConns);
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) UniqueEList(org.eclipse.emf.common.util.UniqueEList) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) RecordValue(org.osate.aadl2.RecordValue) LinkedList(java.util.LinkedList) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ArrayList(java.util.ArrayList) UniqueEList(org.eclipse.emf.common.util.UniqueEList) List(java.util.List) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) PropertyExpression(org.osate.aadl2.PropertyExpression)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)5 AnalysisErrorReporterManager (org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager)5 SystemInstance (org.osate.aadl2.instance.SystemInstance)4 IResource (org.eclipse.core.resources.IResource)3 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 InstanceFactory (org.osate.aadl2.instance.InstanceFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 Command (org.eclipse.emf.common.command.Command)2 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)2 RollbackException (org.eclipse.emf.transaction.RollbackException)2 TransactionalCommandStack (org.eclipse.emf.transaction.TransactionalCommandStack)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)2 WorkspaceEditingDomainFactory (org.eclipse.emf.workspace.WorkspaceEditingDomainFactory)2 Aadl2Factory (org.osate.aadl2.Aadl2Factory)2 InstantiateModel (org.osate.aadl2.instantiation.InstantiateModel)2