Problem in resolving proxies [message #1272044] |
Sun, 16 March 2014 23:46 |
Luca Gherardi Messages: 62 Registered: November 2010 |
Member |
|
|
Hi all,
I have two meta-model. Let's say A and B.
B is importing elements defined in A.
When I run the editor of B, I can load a model conforming to A by means of the "Load Resource..." command.
At this point I'm able to define elements in B, which contains references of element defined in A.
In my example the two models are in the same directory.
The XML file for B stores the reference to A in this way:
href="modelA.metamodelA#//@ClassA.1"/>
When I load the models from a standalone program I can't resolve the proxies.
I tried to use the ECoreUtil.resolve method, but i doesn't help.
For example:
ResourceSetImpl resourceSet = new ResourceSetImpl();
MetaModelAPackage.eINSTANCE.eClass();
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("metamodelA", new XMIResourceFactoryImpl());
Resource modelAResource = resourceSet.getResource(URI.createURI(FILE_PATH_MODEL_A), true);
modelA = (MetaModelA) modelAResource.getContents().get(0);
MetaModelBPackage.eINSTANCE.eClass();
m.put("metamodelB", new XMIResourceFactoryImpl());
Resource modelBResource = resourceSet.getResource(URI.createURI(FILE_PATH_MODEL_B), true);
modelB = (MetaModelB) modelBResource.getContents().get(0);
System.out.println(modelB.getAs().get(0).getName());
System.out.println(modelB.getAs().get(0).eIsProxy());
A a = (A)ECoreUtil.resolve(modelB.getAs().get(0), resourceSet); //I tried to use also modelAResource as second parameter
System.out.println(a.eIsProxy());
The output is
The only fix I found is referencing the file by means of the absolute path (e.g. href="file/home/luca/projects/testEcore/modelA.metamodelA#//@ClassA.1")
However this is not optimal, because I have to change manually the file.
Is there a way to fix this issue?
Please let me know if further information is required.
Thanks!
|
|
|
Re: Problem in resolving proxies [message #1272063 is a reply to message #1272044] |
Mon, 17 March 2014 01:13 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Luca,
Comments below.
On 16/03/2014 4:46 PM, Luca Gherardi wrote:
> Hi all,
>
> I have two meta-model. Let's say A and B.
>
> B is importing elements defined in A.
>
> When I run the editor of B, I can load a model conforming to A by
> means of the "Load Resource..." command.
> At this point I'm able to define elements in B, which contains
> references of element defined in A.
>
> In my example the two models are in the same directory.
> The XML file for B stores the reference to A in this way:
>
>
> href="modelA.metamodelA#//@ClassA.1"/>
>
>
> When I load the models from a standalone program I can't resolve the
> proxies.
>
> I tried to use the ECoreUtil.resolve method, but i doesn't help.
>
> For example:
>
>
> ResourceSetImpl resourceSet = new ResourceSetImpl();
>
> MetaModelAPackage.eINSTANCE.eClass();
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("metamodelA", new XMIResourceFactoryImpl());
> Resource modelAResource =
> resourceSet.getResource(URI.createURI(FILE_PATH_MODEL_A), true);
What URI is this? Generally it's best to use createFileURI and be sure
to use File.getAbsolutePath for the path to be sure you end up with a
proper absolute URI with an absolute path.
> modelA = (MetaModelA) modelAResource.getContents().get(0);
>
> MetaModelBPackage.eINSTANCE.eClass();
> m.put("metamodelB", new XMIResourceFactoryImpl());
> Resource modelBResource =
> resourceSet.getResource(URI.createURI(FILE_PATH_MODEL_B), true);
> modelB = (MetaModelB) modelBResource.getContents().get(0);
>
> System.out.println(modelB.getAs().get(0).getName());
> System.out.println(modelB.getAs().get(0).eIsProxy());
>
> A a = (A)ECoreUtil.resolve(modelB.getAs().get(0), resourceSet); //I
> tried to use also modelAResource as second parameter
>
> System.out.println(a.eIsProxy());
>
>
>
> The output is
>
> null
> true
> true
>
>
>
> The only fix I found is referencing the file by means of the absolute
> path (e.g.
> href="file/home/luca/projects/testEcore/modelA.metamodelA#//@ClassA.1")
>
> However this is not optimal, because I have to change manually the file.
>
> Is there a way to fix this issue?
>
> Please let me know if further information is required.
>
> Thanks!
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02968 seconds