Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Resolving proxies
Resolving proxies [message #431733] Thu, 23 July 2009 12:11 Go to next message
Andy Carpenter is currently offline Andy CarpenterFriend
Messages: 145
Registered: July 2009
Senior Member
I'm trying to get details of packages refered to from the contents
of a Ecore resource. I've tried the following code

final Map<EObject, Collection<EStructuralFeature.Setting>> externals
= EcoreUtil.ExternalCrossReferencer.find(this);
for (EObject eObject : externals.keySet()) {
final URI uri = EcoreUtil.getURI(eObject);
final EPackage ePackage =
EPackage.Registry.INSTANCE.getEPackage(uri.trimFragment().to String()));
}

This works when the elements of the key set are not proxies. However,
sometimes the key set contains proxies. I've tried getting the resolution
of the proxy using all three of the resolve method in EcoreUtil, but none
of them return the resolved object. Does anyone know how to get the
details of referened packages or resolve these proxies? If it makes
any difference, the proxies that I have in my test case are to elements
in the Ecore model.

thanks, Andy.
Re: Resolving proxies [message #431749 is a reply to message #431733] Thu, 23 July 2009 16:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
Andy,

Comments below.

Andy Carpenter wrote:
> I'm trying to get details of packages refered to from the contents
> of a Ecore resource. I've tried the following code
>
> final Map<EObject, Collection<EStructuralFeature.Setting>> externals
> = EcoreUtil.ExternalCrossReferencer.find(this);
> for (EObject eObject : externals.keySet()) {
> final URI uri = EcoreUtil.getURI(eObject);
> final EPackage ePackage =
> EPackage.Registry.INSTANCE.getEPackage(uri.trimFragment().to String()));
> }
Hmmm...
>
> This works when the elements of the key set are not proxies. However,
> sometimes the key set contains proxies. I've tried getting the resolution
> of the proxy using all three of the resolve method in EcoreUtil, but none
> of them return the resolved object.
That likely means the object can't be resolved.
> Does anyone know how to get the
> details of referened packages or resolve these proxies?
I don't understand the code. What exactly are you hoping to achieve?
> If it makes
> any difference, the proxies that I have in my test case are to elements
> in the Ecore model.
It sounds more like you should be walking up the containment tree of
each eObject to find the containing EPackage...
>
> thanks, Andy.
>
>
>
Re: Resolving proxies [message #431768 is a reply to message #431749] Fri, 24 July 2009 11:37 Go to previous messageGo to next message
Andy Carpenter is currently offline Andy CarpenterFriend
Messages: 145
Registered: July 2009
Senior Member
Ed,

I'm generating the Emfatic import statements needed when
I do a Ecore xmi to Emfatic convert. Previously I was using code
that did walk the containment tree:

final Map<EObject, Collection<EStructuralFeature.Setting>> externals
= EcoreUtil.ExternalCrossReferencer.find(this);
for (EObject eObject : externals.keySet()) {
EObject eContainer = eObject;
while(!(eContainer instanceof EPackage)) {
eContainer = eContainer.eContainer();
}
final EPackage ePackage = (EPackage) eContainer;
...
}

The problem that I had was that some of the eObjects in
the externals ket set were not objects in referenced packages, but
proxies for these objects. Calling eContainer() on these
proxies returned null rather than the containing object.

The test case that I was using was the GenModel copied
to a test workspace. I've now worked out that the references
in the GenModel are relative and did not work from the
location to which I copied it. The solution is to simply
detect the presence of unresolvable proxies, output a sensible
message and to not attempt the conversion.

Thanks for your help.

Andy.

"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:h4a2hp$l99$2@build.eclipse.org...
> Andy,
>
> Comments below.
>
> Andy Carpenter wrote:
>> I'm trying to get details of packages refered to from the contents
>> of a Ecore resource. I've tried the following code
>>
>> final Map<EObject, Collection<EStructuralFeature.Setting>> externals
>> = EcoreUtil.ExternalCrossReferencer.find(this);
>> for (EObject eObject : externals.keySet()) {
>> final URI uri = EcoreUtil.getURI(eObject);
>> final EPackage ePackage =
>> EPackage.Registry.INSTANCE.getEPackage(uri.trimFragment().to String()));
>> }
> Hmmm...
>>
>> This works when the elements of the key set are not proxies. However,
>> sometimes the key set contains proxies. I've tried getting the resolution
>> of the proxy using all three of the resolve method in EcoreUtil, but none
>> of them return the resolved object.
> That likely means the object can't be resolved.
>> Does anyone know how to get the
>> details of referened packages or resolve these proxies?
> I don't understand the code. What exactly are you hoping to achieve?
>> If it makes
>> any difference, the proxies that I have in my test case are to elements
>> in the Ecore model.
> It sounds more like you should be walking up the containment tree of each
> eObject to find the containing EPackage...
>>
>> thanks, Andy.
>>
>>
>>
Re: Resolving proxies [message #431773 is a reply to message #431768] Fri, 24 July 2009 15:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
Andy,

Comments below.

Andy Carpenter wrote:
> Ed,
>
> I'm generating the Emfatic import statements needed when
> I do a Ecore xmi to Emfatic convert. Previously I was using code
> that did walk the containment tree:
>
> final Map<EObject, Collection<EStructuralFeature.Setting>> externals
> = EcoreUtil.ExternalCrossReferencer.find(this);
> for (EObject eObject : externals.keySet()) {
> EObject eContainer = eObject;
> while(!(eContainer instanceof EPackage)) {
> eContainer = eContainer.eContainer();
> }
> final EPackage ePackage = (EPackage) eContainer;
> ...
> }
>
> The problem that I had was that some of the eObjects in
> the externals ket set were not objects in referenced packages, but
> proxies for these objects.
Again, proxies should be getting resolved. If that fails, something is
wrong...
> Calling eContainer() on these
> proxies returned null rather than the containing object.
>
> The test case that I was using was the GenModel copied
> to a test workspace. I've now worked out that the references
> in the GenModel are relative and did not work from the
> location to which I copied it. The solution is to simply
> detect the presence of unresolvable proxies, output a sensible
> message and to not attempt the conversion.
Yes, that's better.
>
> Thanks for your help.
>
> Andy.
>
> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
> news:h4a2hp$l99$2@build.eclipse.org...
>> Andy,
>>
>> Comments below.
>>
>> Andy Carpenter wrote:
>>> I'm trying to get details of packages refered to from the contents
>>> of a Ecore resource. I've tried the following code
>>>
>>> final Map<EObject, Collection<EStructuralFeature.Setting>> externals
>>> = EcoreUtil.ExternalCrossReferencer.find(this);
>>> for (EObject eObject : externals.keySet()) {
>>> final URI uri = EcoreUtil.getURI(eObject);
>>> final EPackage ePackage =
>>> EPackage.Registry.INSTANCE.getEPackage(uri.trimFragment().to String()));
>>> }
>> Hmmm...
>>>
>>> This works when the elements of the key set are not proxies. However,
>>> sometimes the key set contains proxies. I've tried getting the
>>> resolution
>>> of the proxy using all three of the resolve method in EcoreUtil, but
>>> none
>>> of them return the resolved object.
>> That likely means the object can't be resolved.
>>> Does anyone know how to get the
>>> details of referened packages or resolve these proxies?
>> I don't understand the code. What exactly are you hoping to achieve?
>>> If it makes
>>> any difference, the proxies that I have in my test case are to elements
>>> in the Ecore model.
>> It sounds more like you should be walking up the containment tree of
>> each eObject to find the containing EPackage...
>>>
>>> thanks, Andy.
>>>
>>>
>>>
>
Previous Topic:ResourceSetImpl.createResource(URI) does not work with content type binding
Next Topic:Dynamic insertion of a Attribute
Goto Forum:
  


Current Time: Sat Dec 14 16:08:46 GMT 2019

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

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

Back to the top