Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Saving emfresource while updating references
Saving emfresource while updating references [message #425645] Wed, 03 December 2008 16:48 Go to next message
Eclipse UserFriend
Originally posted by: benoit.maggi.atosorigin.com

Hi everyone,

I'm stuck by a very annoying problem.

When i try to rename an emf file, it works but all models referencing
this model are not updating.

For example, i have 2 uml models : A and B, A reference B

so it contains text like : href="B.uml"

When i rename B.uml in NewB.uml, the text stay as href="B.uml", and my A
model is now broken.

I don't find any emf option to allow this comportment. Is there one?


Otherwise i don't find any solution to get easily ( without parsing all
the workspace) the list of the resource which reference ones.

Regards
Benoit MAGGI
Re: Saving emfresource while updating references [message #425650 is a reply to message #425645] Wed, 03 December 2008 17:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Benoit,

Comments below.


Benoit MAGGI wrote:
> Hi everyone,
>
> I'm stuck by a very annoying problem.
>
> When i try to rename an emf file, it works but all models referencing
> this model are not updating.
They need to be loaded before the renaming, and saved as well after the
renaming.
>
> For example, i have 2 uml models : A and B, A reference B
>
> so it contains text like : href="B.uml"
>
> When i rename B.uml in NewB.uml, the text stay as href="B.uml", and my
> A model is now broken.
>
> I don't find any emf option to allow this comportment. Is there one?
>
>
> Otherwise i don't find any solution to get easily ( without parsing
> all the workspace) the list of the resource which reference ones.
That's the only way. I.e., you have to physically change all these
referencing files, right?
>
> Regards
> Benoit MAGGI
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Saving emfresource while updating references [message #425662 is a reply to message #425650] Thu, 04 December 2008 11:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benoit.maggi.atosorigin.com

Hi,

Thanks for answering.

I'm trying to change the uri of a file and update all the file that
reference it. I don't find a function that migrate an model from one uri
to ah other. So here is my algorithm:

FIRST : i load the A resource that reference B

Resource A= resourceSet.getResource(fileURI, true);
try {
A.load(Collections.EMPTY_MAP);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

SECOND : i set to B a new URI

URI newRenamedFileURI =
URI.createPlatformResourceURI(newPath.toOSString(), true);
B.setURI(newRenamedFileURI);


THIRD : i save B
try {
B.save(Collections.EMPTY_MAP);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("ERROR");
e.printStackTrace();
}

At the end i get a A referencing the old B file, and neWB file tha is
correct ( copy of b with new Name and uri).

Where am i wrong?

regards
Benoit MAGGI



Ed Merks a écrit :
> Benoit,
>
> Comments below.
>
>
> Benoit MAGGI wrote:
>> Hi everyone,
>>
>> I'm stuck by a very annoying problem.
>>
>> When i try to rename an emf file, it works but all models referencing
>> this model are not updating.
> They need to be loaded before the renaming, and saved as well after the
> renaming.
>>
>> For example, i have 2 uml models : A and B, A reference B
>>
>> so it contains text like : href="B.uml"
>>
>> When i rename B.uml in NewB.uml, the text stay as href="B.uml", and my
>> A model is now broken.
>>
>> I don't find any emf option to allow this comportment. Is there one?
>>
>>
>> Otherwise i don't find any solution to get easily ( without parsing
>> all the workspace) the list of the resource which reference ones.
> That's the only way. I.e., you have to physically change all these
> referencing files, right?
>>
>> Regards
>> Benoit MAGGI
>>
>>
Re: Saving emfresource while updating references [message #425668 is a reply to message #425662] Thu, 04 December 2008 13:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Benoit,

Comments below.

Benoit MAGGI wrote:
> Hi,
>
> Thanks for answering.
>
> I'm trying to change the uri of a file and update all the file that
> reference it. I don't find a function that migrate an model from one
> uri to ah other. So here is my algorithm:
>
> FIRST : i load the A resource that reference B
>
> Resource A= resourceSet.getResource(fileURI, true);
> try {
> A.load(Collections.EMPTY_MAP);
It's already loaded by now, so this is redundant.
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
Probably it's important to use EcoreUtil.resolveAll to ensure that all
proxies to B are resolved.
>
> SECOND : i set to B a new URI
>
> URI newRenamedFileURI =
> URI.createPlatformResourceURI(newPath.toOSString(), true);
I can't imagine that using toOSString is good given that it will use "\"
instead of "/" on Windows.
> B.setURI(newRenamedFileURI);
>
>
> THIRD : i save B
> try {
> B.save(Collections.EMPTY_MAP);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> System.out.println("ERROR");
> e.printStackTrace();
> }
>
Where do you save A?
> At the end i get a A referencing the old B file, and neWB file tha is
> correct ( copy of b with new Name and uri).
>
> Where am i wrong?
Load all the files that refer to B into the resource set using
getResource(uri, true), use EcoreUtil.resolveAll on the resource set,
rename the URI of B, then save all the resources.
>
> regards
> Benoit MAGGI
>
>
>
> Ed Merks a écrit :
>> Benoit,
>>
>> Comments below.
>>
>>
>> Benoit MAGGI wrote:
>>> Hi everyone,
>>>
>>> I'm stuck by a very annoying problem.
>>>
>>> When i try to rename an emf file, it works but all models
>>> referencing this model are not updating.
>> They need to be loaded before the renaming, and saved as well after
>> the renaming.
>>>
>>> For example, i have 2 uml models : A and B, A reference B
>>>
>>> so it contains text like : href="B.uml"
>>>
>>> When i rename B.uml in NewB.uml, the text stay as href="B.uml", and
>>> my A model is now broken.
>>>
>>> I don't find any emf option to allow this comportment. Is there one?
>>>
>>>
>>> Otherwise i don't find any solution to get easily ( without parsing
>>> all the workspace) the list of the resource which reference ones.
>> That's the only way. I.e., you have to physically change all these
>> referencing files, right?
>>>
>>> Regards
>>> Benoit MAGGI
>>>
>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EDataType and Resource
Next Topic:[CDO / Net4J]Null Pointer Exception
Goto Forum:
  


Current Time: Thu Mar 28 13:13:20 GMT 2024

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

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

Back to the top