Eclipse reflective API editor does not open generated xmi model file [message #1696660] |
Wed, 27 May 2015 16:44 |
|
I have generated .genmodel from an ecore file and then generated java code using this genmodel. Then I use XMIResourceFactoryImpl to persist my model file (guided by this online article). the code I am using is as bellow:
UnivPackage.eINSTANCE.eClass();
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl() );
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.createResource(URI.createURI("MyModel.xmi"));
UnivFactory f=UnivFactory.eINSTANCE;
UnivModel univ=f.createUnivModel();
for (int i = 10; i < 20; i+=5) {
Person p=f.createPerson();
p.setName("John"+i);
p.setAge(i);
univ.getElements().add(p);
}
resource.getContents().add(univ);
try {
resource.save(null);
} catch (IOException e) {}
Running the above code generates an xmi file as bellow:
<?xml version="1.0" encoding="ASCII"?>
<univ:UnivModel
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:univ="http://gholizadeh.net/univ-v1">
<elements age="10" name="John10"/>
<elements age="15" name="John15"/>
</univ:UnivModel>
When I am opening this xmi file using Sample Reflective Ecore Model editor eclipse STOPs responding. It seems it is going to search for something and can not find it.
However, when I follow "rightclick on ecore file > create dynamic instance" inside eclipse and create an xmi model file, I can get the following xmi file:
<?xml version="1.0" encoding="ASCII"?>
<univ:UnivModel
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:univ="http://gholizadeh.net/univ-v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://gholizadeh.net/univ-v1 univ.ecore">
<elements age="10" name="John10"/>
<elements age="15" name="John15"/>
</univ:UnivModel>
This file is well handled by Sample Reflective Ecore Model editor (i.e., I can open the file and add objects, and save it and ...).
Comparing two of the above xmi files, reveals that I am missing two attributes in the first xmi file root, namely "xmlns:xsi" and "xsi:schemaLocation".
My Questions:
1) How can I force "XMIResourceFactoryImpl" to put these two options (i.e., "xmlns:xsi" and "xsi:schemaLocation") in the root of my xmi model file when creating it from code.
2) When I am missing these attributes in my xmi file, and try to open such an xmi file with Sample Reflective Ecore Model editor, why Eclipse stops responding? I have to quit eclipse and reopen it again. I expect that eclipse relinquish trying if it can not open the file, and then come up with a dialogue reporting the problem. But it gets stuck for ever!
[Updated on: Wed, 27 May 2015 20:49] Report message to a moderator
|
|
|
Re: Eclipse reflective API editor does not open generated xmi model file [message #1696727 is a reply to message #1696660] |
Thu, 28 May 2015 09:01 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Hamid,
Comments below.
On 27/05/2015 6:44 PM, Hamid Qartal wrote:
> I have generated .genmodel from an ecore file and generated java code
> using this genmodel. Then I use XMIResourceFactoryImpl to persist my
> model file (guided by
> http://www.vogella.com/tutorials/EclipseEMFPersistence/article.html).
> the code I am using is as bellow:
>
> UnivPackage.eINSTANCE.eClass();
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("xmi", new XMIResourceFactoryImpl() );
> ResourceSet resSet = new ResourceSetImpl();
> Resource resource = resSet.createResource(URI.createURI("MyModel.xmi"));
Using a relative URI as a resource's URI is generally a bad idea.
> UnivFactory f=UnivFactory.eINSTANCE;
> UnivModel univ=f.createUnivModel();
> for (int i = 10; i < 20; i+=5) {
> Person p=f.createPerson();
> p.setName("John"+i);
> p.setAge(i);
> univ.getElements().add(p);
> }
> resource.getContents().add(univ);
> try {
> resource.save(null);
> } catch (IOException e) {}
>
> Running the above code generates an xmi file as bellow:
>
> <?xml version="1.0" encoding="ASCII"?>
> <univ:UnivModel xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:univ="http://gholizadeh.net/univ-v1">
> <elements age="10" name="John10"/>
> <elements age="15" name="John15"/>
> </univ:UnivModel>
>
> When I am opening this xmi file using Sample Reflective Ecore Model
> editor eclipse STOPs responding. It seems it is going to search for
> something and can not find it.
It will use the namespace itself as a schema location and try to
download an Ecore model from it.
> However, when I follow "rightclick on ecore file > create dynamic
> instance" inside eclipse and create an xmi model file, I can get the
> following xmi file:
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <univ:UnivModel
> xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:univ="http://gholizadeh.net/univ-v1"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://gholizadeh.net/univ-v1 univ.ecore">
> <elements age="10" name="John10"/>
> <elements age="15" name="John15"/>
> </univ:UnivModel>
>
> This file is well handled by Sample Reflective Ecore Model editor
> (i.e., I can open the file and add objects, and save it and ...).
>
> Comparing two of the above xmi files, reveals that I am missing two
> attributes in the first xmi file root, namely "xmlns:xsi" and
> "xsi:schemaLocation".
>
> My Questions:
> 1) How can I force "XMIResourceFactoryImpl" to put these two options
> (i.e., "xmlns:xsi" and "xsi:schemaLocation") in my xmi file when
> creating it from code.
org.eclipse.emf.ecore.xmi.XMLResource.OPTION_SCHEMA_LOCATION should be
set to true in the resources save options
>
> 2) When I am missing these attribute in my xmi file, and try to open
> such an xmi file with Sample Reflective Ecore Model editor, why
> Eclipse stops responding? I have to quit eclipse and reopen it again.
> I expect that eclipse relinquish trying, if it can not open the file,
> and then come up with a dialogue reporting it. But it stucks for ever!
I'd expect the internet access to timeout at some point, eventually.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03455 seconds