Skip to content

When loading the model, delay resource configuration until after it's loaded #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
*/
@SuppressWarnings("restriction")
public class DefaultModelLoader implements IModelLoader {

IProgressMonitor progressMonitor;

@Override
Expand Down Expand Up @@ -156,7 +156,7 @@ private static Resource loadModel(IExecutionContext context, boolean withAnimati
modelURI = context.getRunConfiguration().getExecutedModelURI();
}
HashMap<String, String> 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) {
Expand All @@ -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
Expand All @@ -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);
}

}
Expand Down Expand Up @@ -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<String, String> 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) {
Expand Down Expand Up @@ -373,13 +367,31 @@ protected void doExecute() {
return session;
}

private static ResourceSet createAndConfigureResourceSet(URI modelURI, HashMap<String, String> nsURIMapping,
private static ResourceSet createResourceSet(URI modelURI, HashMap<String, String> nsURIMapping,
SubMonitor subMonitor) {

final ResourceSet rs = ResourceSetFactory.createFactory().createResourceSet(modelURI);

return rs;
}

private static Resource loadModelThenConfigureResourceSet(ResourceSet rs, URI modelURI, HashMap<String, String> 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<String, String> 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
Expand All @@ -393,7 +405,6 @@ private static ResourceSet createAndConfigureResourceSet(URI modelURI, HashMap<S
// fix sirius to prevent non intentional model savings
converter.getURIHandlers().add(0, new DebugURIHandler(converter.getURIHandlers()));

return rs;
}

// TODO must be extended to support more complex mappings, currently use
Expand Down Expand Up @@ -517,6 +528,4 @@ public URI resolve(URI uri) {
}
}



}