Search in sources :

Example 1 with AbstractTypeSystem

use of org.yakindu.base.types.typesystem.AbstractTypeSystem in project statecharts by Yakindu.

the class DefaultSimulationEngineFactory method restore.

protected ExecutionContext restore(String context, Statechart statechart) {
    try {
        ResourceSet set = new ResourceSetImpl();
        Resource resource = set.createResource(URI.createURI("snapshot.xmi"));
        if (resource == null)
            return null;
        set.getResources().add(resource);
        resource.load(new URIConverter.ReadableInputStream(context, "UTF_8"), Collections.emptyMap());
        IDomain domain = DomainRegistry.getDomain(statechart);
        Injector injector = domain.getInjector(IDomain.FEATURE_SIMULATION);
        ITypeSystem typeSystem = injector.getInstance(ITypeSystem.class);
        if (typeSystem instanceof AbstractTypeSystem) {
            set.getResources().add(((AbstractTypeSystem) typeSystem).getResource());
        }
        EcoreUtil.resolveAll(resource);
        ExecutionContext result = (ExecutionContext) resource.getContents().get(0);
        result.setSnapshot(true);
        return result;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ITypeSystem(org.yakindu.base.types.typesystem.ITypeSystem) IDomain(org.yakindu.sct.domain.extension.IDomain) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ExecutionContext(org.yakindu.sct.model.sruntime.ExecutionContext) Injector(com.google.inject.Injector) AbstractTypeSystem(org.yakindu.base.types.typesystem.AbstractTypeSystem) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URIConverter(org.eclipse.emf.ecore.resource.URIConverter) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with AbstractTypeSystem

use of org.yakindu.base.types.typesystem.AbstractTypeSystem in project statecharts by Yakindu.

the class GeneratorExecutorLookup method createExecutor.

public IGeneratorEntryExecutor createExecutor(GeneratorEntry entry, String generatorId) {
    IGeneratorDescriptor description = GeneratorExtensions.getGeneratorDescriptor(generatorId);
    if (description == null)
        throw new RuntimeException("No generator registered for ID: " + generatorId);
    final IGeneratorEntryExecutor executor = description.createExecutor();
    if (executor == null)
        throw new RuntimeException("Failed to create generator instance for ID:" + generatorId);
    Injector injector = createInjector(entry, description, generatorId);
    injector.injectMembers(executor);
    ITypeSystem typeSystem = injector.getInstance(ITypeSystem.class);
    if (entry.getElementRef() == null || entry.getElementRef().eResource() == null) {
        throw new RuntimeException("Could not resolve reference to model ");
    }
    if (typeSystem instanceof AbstractTypeSystem) {
        ResourceSet set = entry.getElementRef().eResource().getResourceSet();
        set.getResources().add(((AbstractTypeSystem) typeSystem).getResource());
        // XXX: avoid resolving the whole resource set, because there might
        // be models with different domains, we have to ensure that just the
        // models related to the current entry are resolved
        EcoreUtil.resolveAll(entry);
        EcoreUtil.resolveAll(entry.getElementRef());
        EcoreUtil.resolveAll(((AbstractTypeSystem) typeSystem).getResource());
    }
    return executor;
}
Also used : ITypeSystem(org.yakindu.base.types.typesystem.ITypeSystem) Injector(com.google.inject.Injector) AbstractTypeSystem(org.yakindu.base.types.typesystem.AbstractTypeSystem) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

Injector (com.google.inject.Injector)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 AbstractTypeSystem (org.yakindu.base.types.typesystem.AbstractTypeSystem)2 ITypeSystem (org.yakindu.base.types.typesystem.ITypeSystem)2 CoreException (org.eclipse.core.runtime.CoreException)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 URIConverter (org.eclipse.emf.ecore.resource.URIConverter)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 IDomain (org.yakindu.sct.domain.extension.IDomain)1 IGeneratorDescriptor (org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor)1 ExecutionContext (org.yakindu.sct.model.sruntime.ExecutionContext)1