Load HUTN as ecore model [message #1845869] |
Fri, 08 October 2021 16:34  |
Eclipse User |
|
|
|
Hi
I want use HUTN to write unit tests. So I give a text snippet of the model and want to retrieve the EObject ...
protected EObject loadHutn(final String content) throws Exception {
final var ecoreResourceSet = new ResourceSetImpl();
ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl());
ecoreResourceSet.getPackageRegistry().put(ImPackage.eINSTANCE.getNsURI(), ImPackage.eINSTANCE);
try (var inModel = new HutnModel("name", content)) {
// ... ?
inModel.dispose();
inModel.close();
}
return ecoreResourceSet.getContents().get(0);
}
How do I get the HutnModel to push the content into the resource set, so I can retrieve the objects?
thanks Frank
|
|
|
|
Re: Load HUTN as ecore model [message #1846928 is a reply to message #1846926] |
Sat, 09 October 2021 05:14   |
Eclipse User |
|
|
|
I try it like this, but the collection from allContents is empty:
static final ImPackage PCK = ImPackage.eINSTANCE;
protected EObject loadHutn(final String content) throws Exception {
final var ecoreResourceSet = new ResourceSetImpl();
ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
PCK.getNsPrefix(),
new XMIResourceFactoryImpl());
ecoreResourceSet.getPackageRegistry().put(PCK.getNsURI(), PCK);
EObject result = null;
try (var inModel = new HutnModel("name.im", content)) {
inModel.load();
result = (EObject) inModel.allContents().iterator().next(); // java.util.NoSuchElementException here
inModel.dispose();
}
return result;
}
@Test
void testName() throws Exception {
loadHutn(String.format("""
@Spec {
metamodel "%s" {
nsUri: "%s"
}
}
ImModel {
}
""", PCK.getNsPrefix(), PCK.getNsURI()));
}
I expect, that it gives me 1 object back.
Also, when I try to put in child objects, I get parse errors.
Is the connection between my ImPackage and the HutnModel properly established?
[Updated on: Sat, 09 October 2021 05:15] by Moderator
|
|
|
|
|
|
|
|
|
|
|
Re: Load HUTN as ecore model [message #1847962 is a reply to message #1847942] |
Mon, 15 November 2021 06:43  |
Eclipse User |
|
|
|
Hello Dimitris,
I think I missed something in the Flexmi doc. so I can specify both, the attribute to assign to and the explicit EClass to be used.
Trials with simplest Flexmi-Yaml snippets need less than 10ms to be processed.
So I guess, I will continue my evaluation with Flexmi/yaml
Thanks for your support
Frank
|
|
|
Powered by
FUDForum. Page generated in 0.31582 seconds