Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Applying a ChangeDescription to a different model
Applying a ChangeDescription to a different model [message #526581] Mon, 12 April 2010 11:01 Go to next message
Scott Dybiec is currently offline Scott DybiecFriend
Messages: 148
Registered: July 2009
Senior Member
I have written some code that captures changes to an EMF Resource
(capture-side) and applies those changes to a remote replica copy
(apply-side).

Since the ChangeDescription captured by a ChangeRecorder contains URI
references to the original capture-side model, the easiest thing to do
seemed to be to replace these URIs using a ResourceSet's URI Converter.

Here's the code I used:

// Convert the proxy hrefs in the ChangeDescription to point to the
replica file
URIConverter converter = new ExtensibleURIConverterImpl() {

URI replacementURI = resource.getURI();

@Override
public URI normalize(URI uri) {
if (uri.fileExtension().equals("rml")) {
return replacementURI;
} else {
return super.normalize(uri);
}
}
};

// Put the change description and model in the same ResourceSet, then
apply the changes
ResourceSet resourceSet = getResourceSet(); // This ResourceSet already
contains the model to apply changes to
resourceSet.setURIConverter(converter);
resourceSet.getResources().add(changeDescription.eResource() );
changeDescription.apply();

It works, is there a better way to attack this problem?

$cott
Re: Applying a ChangeDescription to a different model [message #526637 is a reply to message #526581] Mon, 12 April 2010 13:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Scott,

Comments below.

Scott Dybiec wrote:
> I have written some code that captures changes to an EMF Resource
> (capture-side) and applies those changes to a remote replica copy
> (apply-side).
>
> Since the ChangeDescription captured by a ChangeRecorder contains URI
> references to the original capture-side model, the easiest thing to do
> seemed to be to replace these URIs using a ResourceSet's URI Converter.
>
> Here's the code I used:
>
> // Convert the proxy hrefs in the ChangeDescription to point to the
> replica file
> URIConverter converter = new ExtensibleURIConverterImpl() {
>
> URI replacementURI = resource.getURI();
>
> @Override
> public URI normalize(URI uri) {
> if (uri.fileExtension().equals("rml")) {
> return replacementURI;
> } else {
> return super.normalize(uri);
> }
> }
> };
Could you have don't this just with a URI mapping rather than
specializing the normalize method?
>
> // Put the change description and model in the same ResourceSet, then
> apply the changes
> ResourceSet resourceSet = getResourceSet(); // This ResourceSet
> already contains the model to apply changes to
> resourceSet.setURIConverter(converter);
> resourceSet.getResources().add(changeDescription.eResource() );
> changeDescription.apply();
>
> It works, is there a better way to attack this problem?
If you can get away with URI mappings, that would be nicer.
>
> $cott


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Applying a ChangeDescription to a different model [message #526663 is a reply to message #526637] Mon, 12 April 2010 14:05 Go to previous messageGo to next message
Maximilian Koegel is currently offline Maximilian KoegelFriend
Messages: 253
Registered: July 2009
Senior Member
Scott,

I have (successfully) tried what you did with a URI mapping. It works
quite OK until you have multiple Change Descriptions from different
nodes that might be contradicting and incoming at the same time. Then
you would essentially need to scan the change descriptions for conflicts
before applying them to the remote replica and potentially you would
need to merge them. If you will never run in such a situation, I guess
your approach could work just fine. Otherwise I would recommend you to
use CDO (EMF) or EMFStore (emfstore.org) to share your models among
multiple nodes.

Cheers,
Maximilian



> Comments below.
>
> Scott Dybiec wrote:
>> I have written some code that captures changes to an EMF Resource
>> (capture-side) and applies those changes to a remote replica copy
>> (apply-side).
>>
>> Since the ChangeDescription captured by a ChangeRecorder contains URI
>> references to the original capture-side model, the easiest thing to do
>> seemed to be to replace these URIs using a ResourceSet's URI Converter.
>>
>> Here's the code I used:
>>
>> // Convert the proxy hrefs in the ChangeDescription to point to the
>> replica file
>> URIConverter converter = new ExtensibleURIConverterImpl() {
>>
>> URI replacementURI = resource.getURI();
>>
>> @Override
>> public URI normalize(URI uri) {
>> if (uri.fileExtension().equals("rml")) {
>> return replacementURI;
>> } else {
>> return super.normalize(uri);
>> }
>> }
>> };
> Could you have don't this just with a URI mapping rather than
> specializing the normalize method?
>>
>> // Put the change description and model in the same ResourceSet, then
>> apply the changes
>> ResourceSet resourceSet = getResourceSet(); // This ResourceSet
>> already contains the model to apply changes to
>> resourceSet.setURIConverter(converter);
>> resourceSet.getResources().add(changeDescription.eResource() );
>> changeDescription.apply();
>>
>> It works, is there a better way to attack this problem?
> If you can get away with URI mappings, that would be nicer.
>>
>> $cott
Re: Applying a ChangeDescription to a different model [message #531868 is a reply to message #526581] Thu, 06 May 2010 12:32 Go to previous messageGo to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Scott Dybiec wrote on Mon, 12 April 2010 07:01
I have written some code that captures changes to an EMF Resource
(capture-side) and applies those changes to a remote replica copy
(apply-side).

$cott


I would like to do the same thing, but I can not. The ChangeDescription created by ChangeRecorder contains the old state of the model, so I can only use it to undo the changes. What I need is to keep two model instances in sync. Is there a dedicated change model and recorder for this?
Thank you,
Csaba
Re: Applying a ChangeDescription to a different model [message #531886 is a reply to message #531868] Thu, 06 May 2010 13:13 Go to previous messageGo to next message
Cyril Jaquier is currently offline Cyril JaquierFriend
Messages: 80
Registered: July 2009
Member
Hi,

> I would like to do the same thing, but I can not. The ChangeDescription
> created by ChangeRecorder contains the old state of the model, so I can
> only use it to undo the changes. What I need is to keep two model
> instances in sync. Is there a dedicated change model and recorder for this?

No, there is nothing dedicated to this. You can applyAndReverse the
ChangeDescription, serialize it and apply it again. You can then apply
the serialized ChangeDescription to your second model.

Regards,
Cyril
Re: Applying a ChangeDescription to a different model [message #531899 is a reply to message #531886] Thu, 06 May 2010 13:50 Go to previous messageGo to next message
Csaba Koncz is currently offline Csaba KonczFriend
Messages: 49
Registered: July 2009
Member
Hi Cyril,

Thank you for the tip. It is a smart trick, but I am concerned of the performance issues it might have. At both endpoints I have a number of change listeners and unless I disable them somehow, will have a lot of unnecessary view and domain model changes.

Currently I am using Epatch for propagating the changes. Epatch is nice but it has two features that are not really needed for me:
1. is a two way-patch. For me it means it carries unnecessary information (I am applying it only in one direction)
2. I can not apply the patch directly to the target model. Epatch only creates a patched copy of the target that needs then Matched/Diffed/Merged with the original in order to get the changes to their destination.

So despite of my concerns the ChangeDescription trick might be more effective than what I currently have.

Thank you again!
Csaba
Re: Applying a ChangeDescription to a different model [message #531957 is a reply to message #531868] Thu, 06 May 2010 15:07 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Csaba,

Using applyAndReverse you can achieve the inverted set of changes and of
course you can do it again to get back to the final state.
Alternatively you could copy the model and the change description
(EcoreUtil.copyAll) and then invert that copy.


Csaba Koncz wrote:
> Scott Dybiec wrote on Mon, 12 April 2010 07:01
>> I have written some code that captures changes to an EMF Resource
>> (capture-side) and applies those changes to a remote replica copy
>> (apply-side).
>>
>> $cott
>
>
> I would like to do the same thing, but I can not. The
> ChangeDescription created by ChangeRecorder contains the old state of
> the model, so I can only use it to undo the changes. What I need is to
> keep two model instances in sync. Is there a dedicated change model
> and recorder for this?
> Thank you,
> Csaba


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Using delegates in standalone application
Next Topic:Ant task for EMF validation?
Goto Forum:
  


Current Time: Fri Apr 26 07:28:50 GMT 2024

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

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

Back to the top