Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EReference to another ECore File
EReference to another ECore File [message #430970] Mon, 22 June 2009 09:39 Go to next message
No real name is currently offline No real nameFriend
Messages: 15
Registered: July 2009
Junior Member
Hello,

I import multiple xml schemas, which results in a different ecore file for
each of the schemas. After the import i load the coresponding GenModel
file and iterate through all EReferences and add the EOpposites. All works
perfectly fine as long as the Reference is in one ecore file. When there
is a reference from x.ecore to y.ecore than i get a "Unable to resolve
proxy" error, when i try to load the model in an editor. When i look at
the GenModel file than the EReference points to the wrong element (in the
wrong namespace). I can correct it manually, but i don't know how to do it
programmatically.

Can anyone help?
Re: EReference to another ECore File [message #430983 is a reply to message #430970] Mon, 22 June 2009 19:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Manfred,

Comments below.

Manfred wrote:
> Hello,
>
> I import multiple xml schemas, which results in a different ecore file
> for each of the schemas. After the import i load the coresponding
> GenModel file and iterate through all EReferences and add the EOpposites.
There's an ecore:opposite annotation you could use directly in the
schema instead.
> All works perfectly fine as long as the Reference is in one ecore
> file. When there is a reference from x.ecore to y.ecore than i get a
> "Unable to resolve proxy" error, when i try to load the model in an
> editor.
I guess the question is how did you make the change?
> When i look at the GenModel file than the EReference points to the
> wrong element (in the wrong namespace). I can correct it manually, but
> i don't know how to do it programmatically.
Aren't you making these changes in the Ecore file itself?
> Can anyone help?
Best to use ecore:opposite on the element or attribute itself in the
schema...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EReference to another ECore File [message #430989 is a reply to message #430983] Tue, 23 June 2009 12:06 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 15
Registered: July 2009
Junior Member
Ed,

thanks for your reply.

Comments below.

Ed Merks wrote:

> Manfred,

> Comments below.

> Manfred wrote:
>> Hello,
>>
>> I import multiple xml schemas, which results in a different ecore file
>> for each of the schemas. After the import i load the coresponding
>> GenModel file and iterate through all EReferences and add the EOpposites.
> There's an ecore:opposite annotation you could use directly in the
> schema instead.

The problem is, i'm looking at a possibly very large number of schema
files, which are not specified by us. So i though manipulating the ecore
files is easier than automatically process the xsd and add the opposites
there.

>> All works perfectly fine as long as the Reference is in one ecore
>> file. When there is a reference from x.ecore to y.ecore than i get a
>> "Unable to resolve proxy" error, when i try to load the model in an
>> editor.
> I guess the question is how did you make the change?

I load the genmodel and iterate through it and for each EReference i find
and where there is no EOpposite i create one:

EReference eOpposite = EcoreFactory.eINSTANCE.createEReference();
reference.setEOpposite(eOpposite);
eOpposite.setEOpposite(reference);
eOpposite.setEType(reference.getEContainingClass());
eOpposite.setName(oppositeName);
reference.getEReferenceType().getEStructuralFeatures().add(e Opposite);

After that i save the changed ecore file.

>> When i look at the GenModel file than the EReference points to the
>> wrong element (in the wrong namespace). I can correct it manually, but
>> i don't know how to do it programmatically.
> Aren't you making these changes in the Ecore file itself?

What i meant was, that i can correct the ecore files manually, when i open
them in a text editor, but i don't know how to do it automatically, when
the EReference points to an element of another namespace.
Re: EReference to another ECore File [message #430990 is a reply to message #430989] Tue, 23 June 2009 13:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Manfred,

Comments below.

Manfred wrote:
> Ed,
>
> thanks for your reply.
>
> Comments below.
>
> Ed Merks wrote:
>
>> Manfred,
>
>> Comments below.
>
>> Manfred wrote:
>>> Hello,
>>>
>>> I import multiple xml schemas, which results in a different ecore
>>> file for each of the schemas. After the import i load the
>>> coresponding GenModel file and iterate through all EReferences and
>>> add the EOpposites.
>> There's an ecore:opposite annotation you could use directly in the
>> schema instead.
>
> The problem is, i'm looking at a possibly very large number of schema
> files, which are not specified by us. So i though manipulating the
> ecore files is easier than automatically process the xsd and add the
> opposites there.
Whatever is easier is best...
>
>>> All works perfectly fine as long as the Reference is in one ecore
>>> file. When there is a reference from x.ecore to y.ecore than i get a
>>> "Unable to resolve proxy" error, when i try to load the model in an
>>> editor.
>> I guess the question is how did you make the change?
>
> I load the genmodel and iterate through it and for each EReference i
> find and where there is no EOpposite i create one:
>
> EReference eOpposite = EcoreFactory.eINSTANCE.createEReference();
> reference.setEOpposite(eOpposite);
> eOpposite.setEOpposite(reference);
> eOpposite.setEType(reference.getEContainingClass());
> eOpposite.setName(oppositeName);
> reference.getEReferenceType().getEStructuralFeatures().add(e Opposite);
>
> After that i save the changed ecore file.
Do you save both Ecore files?
>>> When i look at the GenModel file than the EReference points to the
>>> wrong element (in the wrong namespace). I can correct it manually,
>>> but i don't know how to do it programmatically.
>> Aren't you making these changes in the Ecore file itself?
>
> What i meant was, that i can correct the ecore files manually, when i
> open them in a text editor, but i don't know how to do it
> automatically, when the EReference points to an element of another
> namespace.
Try doing it with the Sample Ecore Editor and looking at how it saves
the result. Manual text editing is just asking for trouble...
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EReference to another ECore File [message #430998 is a reply to message #430990] Tue, 23 June 2009 18:50 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 15
Registered: July 2009
Junior Member
Ed,

thanks for your help, i saved the modified ecore files wrong. But i have
another problem...with proxies.

I have a reference from Class A to Class B. Now i create an opposite for
the reference from B to A. After i load a model and if B is a proxy then
the reference to A is only set on the proxy, after proxy resolution the
reference from B to A is null.
Re: EReference to another ECore File [message #431001 is a reply to message #430998] Tue, 23 June 2009 19:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Manfred,

Cross document references must be serialized in both documents because
resolving a proxy does nothing to update the other end, which is assumed
to also hold a proxy with is resolved only when accessed...


Manfred wrote:
> Ed,
> thanks for your help, i saved the modified ecore files wrong. But i
> have another problem...with proxies.
>
> I have a reference from Class A to Class B. Now i create an opposite
> for the reference from B to A. After i load a model and if B is a
> proxy then the reference to A is only set on the proxy, after proxy
> resolution the reference from B to A is null.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EReference to another ECore File [message #431009 is a reply to message #431001] Wed, 24 June 2009 07:56 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 15
Registered: July 2009
Junior Member
Ed Merks wrote:

> Cross document references must be serialized in both documents because
> resolving a proxy does nothing to update the other end, which is assumed
> to also hold a proxy with is resolved only when accessed...

Ed,

i get the proxies also in a same-document reference and i have no idea how
i can avoid the problem, that the proxy has the reference to the object on
the other side of the reference, but the resolved object does not. Any
hints would be greatly appreciated.
Re: EReference to another ECore File [message #431010 is a reply to message #431009] Wed, 24 June 2009 08:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Manfred,

Is the type in the schema IDREF or anyURI? In the former case the
EReference.resolveProxies will be false and in that case, the EReference
you create also should have it set to false and should have "transient"
set to false so that it's not serialized. The serialized form will then
not include a "#" but will simply be an ID. That ID will be resolved at
the end of parsing (or while parsing) and the resolved object will be
set into the reference, which updates both ends of the object. No proxy
will be created in this case.


Manfred wrote:
> Ed Merks wrote:
>
>> Cross document references must be serialized in both documents
>> because resolving a proxy does nothing to update the other end, which
>> is assumed to also hold a proxy with is resolved only when accessed...
>
> Ed,
>
> i get the proxies also in a same-document reference and i have no idea
> how i can avoid the problem, that the proxy has the reference to the
> object on the other side of the reference, but the resolved object
> does not. Any hints would be greatly appreciated.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EReference to another ECore File [message #431059 is a reply to message #431010] Thu, 25 June 2009 11:13 Go to previous message
No real name is currently offline No real nameFriend
Messages: 15
Registered: July 2009
Junior Member
I solved the problem by replacing all proxies by the actual elements after
loading the model.
Previous Topic:EMF in plugin
Next Topic:Re: An org.eclipse.emf.validation.examples.ocl example plug-in howto
Goto Forum:
  


Current Time: Mon Sep 23 21:38:36 GMT 2024

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

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

Back to the top