|
|
|
|
|
|
|
|
Re: Programmatically access elements imported from another Ecore model [message #1272007 is a reply to message #1271970] |
Sun, 16 March 2014 21:44 |
Luca Gherardi Messages: 62 Registered: November 2010 |
Member |
|
|
Thanks again Christian.
The last question:
let's suppose that LibraryModel is importing elements from another Ecore model: AuthorsModel.
What should I do for accessing the data in author model?
I tried the same procedure but something got wrong.
See the code below.
The last line is printing null.
Thanks,
Luca
P.S.:
The DSL and the MWE2 includes the author meta model.
However the DSL is not directly importing elements of the Author Model. That's because I don't need it.
I tried to import them to see if that was the problem, but it didn't work.
// Register the XMI resource factory for the .website extension
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("librarydsl", new XMIResourceFactoryImpl());
m.put("librarymodel", new XMIResourceFactoryImpl());
m.put("authormodel", new XMIResourceFactoryImpl());
ResourceSet resSet = new ResourceSetImpl();
LibraryPackage.eINSTANCE.eClass();
LibraryModelSupport libraryModelSupport = new LibraryModelSupport();
libraryModelSupport.registerServices(true);
Resource libraryModelResource = resSet.getResource(URI.createURI(PATH_TO_LIBRARY_MODEL), true);
LibraryModel libraryModel = (LibraryModel) libraryModelResource.getContents().get(0);
System.out.println(libraryModel.getName()); // this works
AuthorPackage.eINSTANCE.eClass();
AuthorModelSupport authorModelSupport = new AuthorModelSupport();
authorModelSupport.registerServices(true);
Resource authorModelResource = resSet.getResource(URI.createURI(PATH_TO_AUTHOR_MODEL), true);
AuthorModel authorModel = (AuthorModel) authorModelResource.getContents().get(0);
System.out.println(authorModel.getName()); // this works
LibraryDSLPackage.eINSTANCE.eClass();
new LibraryDSLStandaloneSetup().createInjectorAndDoEMFRegistration();
Resource libraryDSLResource = resSet.getResource(URI.createURI(PATH_TO_DSL_MODEL), true);
LibraryDSL libraryDSL = (LibraryDSL) libraryDSLResource.getContents().get(0);
System.out.println(libraryDSL.getSelectedBooks.get(0).getName()); // now this prints the correct name
System.out.println(libraryDSL.getSelectedBooks.get(0).getAuthor().Name()); // this print null
[Updated on: Sun, 16 March 2014 22:18] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04395 seconds