|
|
Re: Resolving of URIs in XMI files [message #1755368 is a reply to message #1755367] |
Thu, 02 March 2017 16:30 |
Alexander Fichtinger Messages: 66 Registered: January 2013 |
Member |
|
|
This is the method which we use for loading the model.
The resources themselves can be found correclty of course =).
public T loadModel(final String xmiFilePath, final String... additionalFiles)
{
final ResourceSet resourceSet = new ResourceSetImpl();
final Resource resource = resourceSet.getResource(URI.createFileURI(xmiFilePath), true);
for (final String additionalFile : additionalFiles)
{
resourceSet.getResource(URI.createFileURI(additionalFile), true);
}
EcoreUtil.resolveAll(resourceSet);
return (T)resource.getContents().get(0);
}
And thanks for your incredibly fast first answer =D.
[Updated on: Thu, 02 March 2017 16:31] Report message to a moderator
|
|
|
Re: Resolving of URIs in XMI files [message #1755374 is a reply to message #1755368] |
Thu, 02 March 2017 17:04 |
|
hmmm i cannot reproduce this
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.util.StringInputStream;
import org.xtext.example.mydsl3.myDsl.Model;
import com.google.inject.Injector;
public class Main {
public static void main(String[] args) throws IOException {
Injector i = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = i.getInstance(ResourceSet.class);
Resource r1 = rs.createResource(URI.createURI("dummy1.mydsl3"));
Resource r2 = rs.createResource(URI.createURI("dummy2.mydsl3"));
r1.load(new StringInputStream("Hello B from A!"), null);
r2.load(new StringInputStream("Hello A!"), null);
EcoreUtil2.resolveAll(rs);
System.err.println(r1.getErrors());
System.err.println(r2.getErrors());
Resource r1x = rs.createResource(URI.createURI("r1x.xmi"));
Resource r2x = rs.createResource(URI.createURI("r2x.xmi"));
r1x.getContents().addAll(r1.getContents());
r2x.getContents().addAll(r2.getContents());
r1x.save(null);
r2x.save(null);
ResourceSet rsx = new ResourceSetImpl();
Resource r1xl = rsx.getResource(URI.createURI("r1x.xmi"), true);
Resource r2xl = rsx.getResource(URI.createURI("r2x.xmi"), true);
EcoreUtil2.resolveAll(rsx);
System.err.println(r1xl.getErrors());
System.err.println(r2xl.getErrors());
Model m = (Model) r1xl.getContents().get(0);
System.out.println(m.getGreetings().get(0).getFrom().getName());
}
}
but my xmi looks slightly different
<?xml version="1.0" encoding="ASCII"?>
<myDsl:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:myDsl="http://www.xtext.org/example/mydsl3/MyDsl">
<greetings name="B">
<from href="r2x.xmi#//@greetings.0"/>
</greetings>
</myDsl:Model>
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04620 seconds