Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Eclipse reflective API editor does not open generated xmi model file(XMIResourceFactoryImpl does not add two attributes, namely xmlns:xsi and xsi:schemaLocation to my xmi file)
Eclipse reflective API editor does not open generated xmi model file [message #1696660] Wed, 27 May 2015 16:44 Go to next message
Hamid Qartal is currently offline Hamid QartalFriend
Messages: 33
Registered: December 2013
Member
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30544
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.
Re: Eclipse reflective API editor does not open generated xmi model file [message #1696730 is a reply to message #1696727] Thu, 28 May 2015 09:29 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6481
Registered: July 2009
Senior Member
On 28/05/2015 10:01, Ed Merks wrote:

>>
>> 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.
>
A bug was fixed about five years ago whereby a bad intenet access was
re-attempted for each proxy that targetted it. For even modest size
files this could make it seem like it took forever.

The failure is now cached so that it should only occur once, and should
timeout typically within 30 seconds.

If you have a repro, please raise a BUgzilla.

Regards

Ed Willink
Previous Topic:[xcore] Couldn't resolve reference to GenBase 'EDiagnositicChain'
Next Topic:An Ecore file whose instances are other Ecore files
Goto Forum:
  


Current Time: Tue Oct 15 22:22:44 GMT 2019

Powered by FUDForum. Page generated in 0.02184 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top