From 47a7be9381b8761dd61e19a7a91d3a2bcb729a35 Mon Sep 17 00:00:00 2001 From: Erwan Bousse Date: Mon, 17 Jul 2017 11:54:57 +0200 Subject: [PATCH] [DefaultModelLoader] Delay the ResourceSet configuration Previously, when Melange was solving a cross-ref of the model, a Melange query was always added to the URI of the cross-ref although Melange needed to access to the resource without any query. This PR delays the configuration of the ResourceSet with the XMLURIHandler and the MelangeURIConverter, until after the model was entirely loaded, which includes the MelangeResource creation, and avoids the aforementioned problem. --- .../modelloader/DefaultModelLoader.java | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/framework/execution_framework/plugins/org.gemoc.executionframework.extensions.sirius/src/org/gemoc/executionframework/extensions/sirius/modelloader/DefaultModelLoader.java b/framework/execution_framework/plugins/org.gemoc.executionframework.extensions.sirius/src/org/gemoc/executionframework/extensions/sirius/modelloader/DefaultModelLoader.java index 5e55a0517..a702dc96c 100644 --- a/framework/execution_framework/plugins/org.gemoc.executionframework.extensions.sirius/src/org/gemoc/executionframework/extensions/sirius/modelloader/DefaultModelLoader.java +++ b/framework/execution_framework/plugins/org.gemoc.executionframework.extensions.sirius/src/org/gemoc/executionframework/extensions/sirius/modelloader/DefaultModelLoader.java @@ -92,7 +92,7 @@ */ @SuppressWarnings("restriction") public class DefaultModelLoader implements IModelLoader { - + IProgressMonitor progressMonitor; @Override @@ -156,7 +156,7 @@ private static Resource loadModel(IExecutionContext context, boolean withAnimati modelURI = context.getRunConfiguration().getExecutedModelURI(); } HashMap nsURIMapping = getnsURIMapping(context); - ResourceSet resourceSet = createAndConfigureResourceSet(modelURI, nsURIMapping, subMonitor); + ResourceSet resourceSet = createResourceSet(modelURI, nsURIMapping, subMonitor); // If there is animation, we ask sirius to create the resource if (withAnimation && context.getRunConfiguration().getAnimatorURI() != null) { @@ -165,7 +165,7 @@ private static Resource loadModel(IExecutionContext context, boolean withAnimati // Killing + restarting Sirius session for animation killPreviousSiriusSession(context.getRunConfiguration().getAnimatorURI()); openNewSiriusSession(context, context.getRunConfiguration().getAnimatorURI(), resourceSet, modelURI, - subMonitor); + subMonitor,nsURIMapping); // At this point Sirius has loaded the model, we just need to // find it @@ -182,13 +182,7 @@ private static Resource loadModel(IExecutionContext context, boolean withAnimati // If there is no animation, we create a resource ourselves else { - Resource resource = resourceSet.createResource(modelURI); - try { - resource.load(null); - } catch (IOException e) { - new RuntimeException("The model could not be loaded.", e); - } - return resource; + return loadModelThenConfigureResourceSet(resourceSet, modelURI, nsURIMapping, subMonitor); } } @@ -231,14 +225,14 @@ public void run() { } private static Session openNewSiriusSession(final IExecutionContext context, URI sessionResourceURI, ResourceSet rs, - URI modelURI, SubMonitor subMonitor) throws CoreException { + URI modelURI, SubMonitor subMonitor, HashMap nsURIMapping) throws CoreException { subMonitor.subTask("Loading model"); subMonitor.newChild(3); // load model resource and resolve all proxies - Resource r = rs.getResource(modelURI, true); - EcoreUtil.resolveAll(rs); + + Resource r = loadModelThenConfigureResourceSet(rs, modelURI, nsURIMapping, subMonitor); // force adaptee model resource in the main ResourceSet if (r instanceof MelangeResourceImpl) { @@ -373,13 +367,31 @@ protected void doExecute() { return session; } - private static ResourceSet createAndConfigureResourceSet(URI modelURI, HashMap nsURIMapping, + private static ResourceSet createResourceSet(URI modelURI, HashMap nsURIMapping, + SubMonitor subMonitor) { + + final ResourceSet rs = ResourceSetFactory.createFactory().createResourceSet(modelURI); + + return rs; + } + + private static Resource loadModelThenConfigureResourceSet(ResourceSet rs, URI modelURI, HashMap nsURIMapping, + SubMonitor subMonitor) { + + Resource resource = rs.getResource(modelURI, true); + EcoreUtil.resolveAll(rs); + configureResourceSet(rs,modelURI,nsURIMapping,subMonitor); + + return resource; + + } + + private static void configureResourceSet(ResourceSet rs, URI modelURI, HashMap nsURIMapping, SubMonitor subMonitor) { subMonitor.subTask("Configuring ResourceSet"); subMonitor.newChild(1); - final ResourceSet rs = ResourceSetFactory.createFactory().createResourceSet(modelURI); final String fileExtension = modelURI.fileExtension(); // indicates which melange query should be added to the xml uri handler // for a given extension @@ -393,7 +405,6 @@ private static ResourceSet createAndConfigureResourceSet(URI modelURI, HashMap