Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Package.eINSTANCE.getElement not equals reference.etype - ResourceFactory or Registry Problem?
Package.eINSTANCE.getElement not equals reference.etype - ResourceFactory or Registry Problem? [message #1790866] Tue, 19 June 2018 09:39 Go to next message
Simon BBBBBBB is currently offline Simon BBBBBBBFriend
Messages: 58
Registered: March 2015
Member
Hello,

i have a Problem with equality between the *Packe.eINSTANCE.getModelAElement and a directly referenced Modelelement.

I have a Metamodel that allows my user to reference Elements from a loaded *.ecore File, wich contains the Class ModelAElement. To reference these the user has to use the load-Resource Option from the context-menu and then enter the platform:/plugin/mymodel/mymodel.ecore uri

in my editor if i find a reference that links to ModelAElement i want to react in a special way. i tryed to make a comparison:

if(ereference.getEType() == MyModelPackage.eINSTANCE.getModelAElement)

but this never returns true. if i make some debug PrintLines i can see that they have different Hashcodes and EcoreResourceFactorys with different uris:

one has platform:/plugin/.... and the other has http://...

The EClasses are the right ones but with different hashcodes.

What can i do to fix this issue?

Thank you for your time.
Simon
Re: Package.eINSTANCE.getElement not equals reference.etype - ResourceFactory or Registry Problem? [message #1790867 is a reply to message #1790866] Tue, 19 June 2018 09:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6438
Registered: July 2009
Senior Member
Hi

This is a classic example of metamodel schizophrenia. You must never load the 'same' metamodel by more than one mechanism else you get X is not equal to X anomalies.

The simplest approach is to ensure that you are consistent in what you load.

If you configure the URImap, perhaps aided by the EcorePlugin.ExtensionProcessor, you can ensure that the 'wrong' mechanism is redirected to the 'right' one.

If you really can't control your users/usage you may use the (Standalone)ProjectMap from Eclipse OCL to ensure that metamodels are distinct wrt their nsURI rather than their external URI.

Regards

Ed Willink

Re: Package.eINSTANCE.getElement not equals reference.etype - ResourceFactory or Registry Problem? [message #1790872 is a reply to message #1790867] Tue, 19 June 2018 11:45 Go to previous messageGo to next message
Simon BBBBBBB is currently offline Simon BBBBBBBFriend
Messages: 58
Registered: March 2015
Member
Hello Ed, thanks for your answer. I still cant find a solution.

The user loads the resource as a direct dependency, so it has to have the plaatform:/plugin/... uri, right?

But i have to access the package in a programmatical way so i have to use the NamePacke.eINSTANCE.get... what resolvs to the http:// reference. is there a different way for me to retrieve that one specific eclass?

i can get the resource set from my current object, find the right resource, navigate threw the model and then get my class, but that cant be the right way, or is it?

another hint would be nice.

Greetings
Re: Package.eINSTANCE.getElement not equals reference.etype - ResourceFactory or Registry Problem? [message #1790873 is a reply to message #1790872] Tue, 19 June 2018 12:13 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6438
Registered: July 2009
Senior Member
Hi

You provide no clues as to your environment so I have to guess, How does the user load ? Using a shovel?

If you have org.eclipse.emf.ecore checked out in your workspace you have three candidate for http://www.eclipse.org/emf/2002/Ecore.
- the Java classes associated with org.eclipse.emf.ecore.EPackage
- the platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore content in the EMF JAR
- the platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore content in your workspace
in addition to various file: navigations in your file system.

You just use just one and ensure that referebces to otgher are redirected.

If you are running under Eclipse OSGI the redirections happen automatically so using any of the above three can be equivalent.

If your are running standalone see https://wiki.eclipse.org/EMF/FAQ#How_do_I_make_my_EMF_standalone_application_Eclipse-aware.3F amngst others.

Regards

Ed Willink
Re: Package.eINSTANCE.getElement not equals reference.etype - ResourceFactory or Registry Problem? [message #1804254 is a reply to message #1790873] Thu, 21 March 2019 09:42 Go to previous messageGo to next message
Simon BBBBBBB is currently offline Simon BBBBBBBFriend
Messages: 58
Registered: March 2015
Member
Hey ed,

i am implementing a custom EMF validator. in this validator, i use NamePacke.eINSTANCE.get... to find a specific eClass. Then i start an eclipse and install my validator into this eclipse threw a plugin and then use the Sample Reflective Ecore Editor to validate my model. This Editor references my target Model threw a platform:/plugin/ -reference, so i have to different loading mechanisms.

how can i redirect the loading from NamePackage.eINSTANCE.get ... to the platform:/plugin/ resource? since i cant change the sample reflective ecore editor, the changes have to be inside my validator.
Re: Package.eINSTANCE.getElement not equals reference.etype - ResourceFactory or Registry Problem? [message #1804257 is a reply to message #1804254] Thu, 21 March 2019 10:23 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30353
Registered: July 2009
Senior Member
There's not much contextual information in your post. You cannot and should not redirect XyzPackage.eINSTANCE to "load" something else. This is the generated model and just be constructed and initialized properly by XyxPackageImpl.

This is more a question of how do your instances specify their schema location. It sounds as if you've created dynamic instances but you should not expect to use your generated validator on those. The generated validator can only validate instances of your generated model. Likely you can just remove the schemaLocation attribute from the instance so that it used the generated model that you've installed.
Previous Topic:Generated XSDs have XMI postfix
Next Topic:Loading models/ metamodels from classpath resources.
Goto Forum:
  


Current Time: Wed Aug 21 09:05:35 GMT 2019

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

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

Back to the top