use of org.yakindu.base.types.typesystem.ITypeSystem 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;
}
use of org.yakindu.base.types.typesystem.ITypeSystem 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;
}
Aggregations