|
|
Re: Resolving proxies [message #431768 is a reply to message #431749] |
Fri, 24 July 2009 11:37 |
Andy Carpenter 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 |
Ed Merks Messages: 33218 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.
>>>
>>>
>>>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.27403 seconds