|
|
|
|
|
Re: Model Migration [message #1252834 is a reply to message #1252653] |
Fri, 21 February 2014 16:50 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Bhushan,
Comments below.
On 21/02/2014 1:59 PM, Bhushan Patil wrote:
> Hi Ed,
>
> I have two models - Model-A and Model-B with specific meta-models
> structure. Model-A contain one element ElementTypeA and Model-B
> contains another element ElementTypeB. ElementTypeB has some
> attributes one of which (is of type ElementTypeA) "refer" to
> ElementTypeA. This means Model-B is referring Model-A.
> If I open Model-B using text editor then I can see this relationship
> (relative href is used for referencing)
>
> Now my meta-model has got changed. So I have transformed Model-A and
> Model-B from OLD meta-models structure to NEW meta-models structure
> using model to model transformation (QVTo).
So you transformed tw
>
> My assumption is if I open both these models and invoke a QVTo (models
> passed as inout params) to perform "model-migration" EMF should
> appropriately take care of reference changes.
>
> Following code will give better idea of how I am opening models.
>
> // open Model-A using resourceset
>
> private EList<EObject> getResourceObjects(final IFile file) {
> ResourceSet resourceSet = new ResourceSetImpl();
> URI resourceUri = URI.createPlatformResourceURI(file.getFullPath()
> toString(), false);
> return resourceSet.getResource(resourceUri.trimFragment(), true)
> getContents();
> }
>
> // open Model-B using resourceset
>
> same as above just pass path of Model-B
But not using the same resource set. That seems like a bad idea,
especially if you plan to transform both A and B.
>
> // perform transformation
>
> transformation UpdateModels(inout model:ModelAorB);
So A and B are in different resource sets so model B will be referring
to a different copy of A than the one you are transforming.
>
> // save Model-B and Model-A one after the other
>
> ResourceSet resourceSet = new ResourceSetImpl();
> for (EObject eObj : outObjects) { Resource targetResource = resourceSet
> createResource(file.getFullPath());
> targetResource.getContents().add(eObj);
You're creating more than one resource with the same URI?
> }
>
> List<Resource> resList = resourceSet.getResources();
>
> for (Resource res : resList){
> res.save(Collections.EMPTY_MAP);
> }
>
> But in reality this is not working and references are not getting
> resolved properly.
No doubt because the transformed B refers to the untransformed A that's
in B's resource set.
> So when I open Model-B and expect that it is referring to Model-A
> appropriate element - its not the case. :(
If you used the debugger wisely, you'd have noticed that B is referring
to a different A than the one you transformed.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03319 seconds