Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem with ChangeRecorder and associations (or connections)
Problem with ChangeRecorder and associations (or connections) [message #420009] Tue, 17 June 2008 11:21 Go to next message
Eclipse UserFriend
Originally posted by: darpan.cmu.edu

Hi,

try {
ResourceSet rSet = root.eResource().getResourceSet();
Resource cdResource = rSet.createResource(root.eResource().getURI());
c = this.endRecording();
if (c != null) {
tempRemoveAdapter();
removed = true;
c.applyAndReverse();
publishEvent(cdResource, c);
c.applyAndReverse();
if (removed) {
this.beginRecording(Collections.singletonList(root));
removed = false;
}
}

In the code above, I am trying to get the recording and convert that to a
forward description using c.applyAndReverse() and then get the model to
the changed state by calling the second c.applyAndReverse(). In between
these two calls I serialize the changeDescription and send it over to
another machine and call applyAndReverse() on it to change the model there.

The call to tempRemoveAdapter removes this changeRecorder from all
notifications while I am changing the model.

Also, I am trying to do this for both UML models and Diagram Interchange
models. This works fine for creating classes, packages, components,
properties, operations, changing types of properties, adding parameters to
operations etc.

But, it fails when I create an association between two UML classes. I
haven't figured out the exact reason but what I have found is the
following:
1. The notification received in this case is a NotificationChain and I
wonder if I should somehow handle that separately.
2. The UML association has a feature called "memberEnd" that is a property
(it creates this property since I created an association between classes).
One half of the notificationchain adds the property to the memberEnd of
the association and the other half adds the association to the property as
"owningAssociation". However to be noted here is the feature has
containment set to false, which results in applyAndReverse
(ChangeDescriptionImpl) to skip its switch-case statement.
3. The exception thrown says that PropertyImpl is not contained in a
resource (it happens during the serialization of the ChangeDescription).
4. Apart from this I also get a BasicEList$IndexOutOfBoundsException in a
call to objectChanges.remove().

I have tried the alternative way of making copies of the model and the
changeDescription but with that:
1. I have the same problem of PropertyImpl is not contained in a resource.
2. Plus when I make a copy of the model, I am not able to resolved
elements on the other side. The ids in the copy of the UML model are
totally different.

I wonder if there is a better approach to doing this?

Any help appreciated.

Thanks,
-darpan
Re: Problem with ChangeRecorder and associations (or connections) [message #420091 is a reply to message #420009] Tue, 17 June 2008 12:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Darpan,

Comments below.

Darpan Saini wrote:
> Hi,
>
> try {
> ResourceSet rSet = root.eResource().getResourceSet();
> Resource cdResource = rSet.createResource(root.eResource().getURI());
This will tend to create a resource of the same type as the root
object's resource. This might well be a specialized resource for
serializing UML instances...
> c = this.endRecording();
> if (c != null) {
> tempRemoveAdapter();
> removed = true;
> c.applyAndReverse();
> publishEvent(cdResource, c);
> c.applyAndReverse();
> if (removed) {
> this.beginRecording(Collections.singletonList(root));
> removed = false;
> }
> }
>
> In the code above, I am trying to get the recording and convert that
> to a forward description using c.applyAndReverse() and then get the
> model to the changed state by calling the second c.applyAndReverse().
> In between these two calls I serialize the changeDescription and send
> it over to another machine and call applyAndReverse() on it to change
> the model there.
>
> The call to tempRemoveAdapter removes this changeRecorder from all
> notifications while I am changing the model.
Isn't it sufficient that endRecording turns of recording?
>
> Also, I am trying to do this for both UML models and Diagram
> Interchange models. This works fine for creating classes, packages,
> components, properties, operations, changing types of properties,
> adding parameters to operations etc.
>
> But, it fails when I create an association between two UML classes. I
> haven't figured out the exact reason but what I have found is the
> following:
> 1. The notification received in this case is a NotificationChain and I
> wonder if I should somehow handle that separately.
That's just internal implementation detail. Only what's visible in the
Notification interface matters.
> 2. The UML association has a feature called "memberEnd" that is a
> property (it creates this property since I created an association
> between classes). One half of the notificationchain adds the property
> to the memberEnd of the association and the other half adds the
> association to the property as "owningAssociation". However to be
> noted here is the feature has containment set to false, which results
> in applyAndReverse (ChangeDescriptionImpl) to skip its switch-case
> statement.
For bidirectional references, it's important that it act only one one side.
> 3. The exception thrown says that PropertyImpl is not contained in a
> resource (it happens during the serialization of the ChangeDescription).
I'm suspicious about your tempRemoveAdapter stuff...
> 4. Apart from this I also get a BasicEList$IndexOutOfBoundsException
> in a call to objectChanges.remove().
>
> I have tried the alternative way of making copies of the model and the
> changeDescription but with that:
> 1. I have the same problem of PropertyImpl is not contained in a
> resource.
> 2. Plus when I make a copy of the model, I am not able to resolved
> elements on the other side. The ids in the copy of the UML model are
> totally different.
>
> I wonder if there is a better approach to doing this?
It's almost impossible to say something meaningful without seeing the
problem in action. Perhaps there's a bug, perhaps your doing something
wrong, I can't say for sure. And I'll be traveling for a few days, so
trying your test case, if you provided one, might take a while.
>
> Any help appreciated.
>
> Thanks,
> -darpan
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with ChangeRecorder and associations - question related to Resource [message #420286 is a reply to message #420091] Tue, 24 June 2008 23:20 Go to previous messageGo to next message
darpan saini is currently offline darpan sainiFriend
Messages: 9
Registered: July 2009
Junior Member
Hi Ed,

A question about the resource suggestion that you made. When I try to
create a resource using
ResourceSet rSet = root.eResource().getResourceSet();
Resource cdResource =
rSet.createResource(URI.createURI("platform:/resource/E/change.xmi));

model changes don't propagate to the other side correctly. This is
because, lets say for example I create a class. This involves creating the
class and then setting its name. The ChangeRecorder records both these
changes and I send them across one by one. However, on the other side when
I try to set the name of the class, the changeRecorder fails to find the
class that was created by the last change. And it does not fail to find
the class when I create it using the model's resource like the code below.
So, does it create the element on the other side with the same id as the
sender?

The receiver code looks like this:
Resource res =
rSet.createResource(targetModelManager.getModelResource().ge tURI());
res.load(bais, null);
ChangeDescription cd = (ChangeDescription) res.getContents().get(0);
cd.apply();

rSet is the resource set of the target model.

Thanks,
-darpan

Darpan,

Comments below.

Darpan Saini wrote:

Hi,

try {
ResourceSet rSet = root.eResource().getResourceSet();
Resource cdResource = rSet.createResource(root.eResource().getURI());

This will tend to create a resource of the same type as the root object's
resource. This might well be a specialized resource for serializing UML
instances...

c = this.endRecording();
if (c != null) {
tempRemoveAdapter();
removed = true;
c.applyAndReverse();
publishEvent(cdResource, c);
c.applyAndReverse();
if (removed) {
this.beginRecording(Collections.singletonList(root));
removed = false;
}
}

In the code above, I am trying to get the recording and convert that
to a forward description using c.applyAndReverse() and then get the model
to the changed state by calling the second c.applyAndReverse(). In between
these two calls I serialize the changeDescription and send it over to
another machine and call applyAndReverse() on it to change the model there.

The call to tempRemoveAdapter removes this changeRecorder from all
notifications while I am changing the model.

Isn't it sufficient that endRecording turns of recording?


Also, I am trying to do this for both UML models and Diagram
Interchange models. This works fine for creating classes, packages,
components, properties, operations, changing types of properties, adding
parameters to operations etc.

But, it fails when I create an association between two UML classes. I
haven't figured out the exact reason but what I have found is the
following:
1. The notification received in this case is a NotificationChain and I
wonder if I should somehow handle that separately.

That's just internal implementation detail. Only what's visible in the
Notification interface matters.

2. The UML association has a feature called "memberEnd" that is a
property (it creates this property since I created an association between
classes). One half of the notificationchain adds the property to the
memberEnd of the association and the other half adds the association to
the property as "owningAssociation". However to be noted here is the
feature has containment set to false, which results in applyAndReverse
(ChangeDescriptionImpl) to skip its switch-case statement.

For bidirectional references, it's important that it act only one one side.

3. The exception thrown says that PropertyImpl is not contained in a
resource (it happens during the serialization of the ChangeDescription).

I'm suspicious about your tempRemoveAdapter stuff...

4. Apart from this I also get a BasicEList$IndexOutOfBoundsException
in a call to objectChanges.remove().

I have tried the alternative way of making copies of the model and the
changeDescription but with that:
1. I have the same problem of PropertyImpl is not contained in a
resource.
2. Plus when I make a copy of the model, I am not able to resolved
elements on the other side. The ids in the copy of the UML model are
totally different.

I wonder if there is a better approach to doing this?

It's almost impossible to say something meaningful without seeing the
problem in action. Perhaps there's a bug, perhaps your doing something
wrong, I can't say for sure. And I'll be traveling for a few days, so
trying your test case, if you provided one, might take a while.


Any help appreciated.

Thanks,
-darpan
Re: Problem with ChangeRecorder and associations - question related to Resource [message #420288 is a reply to message #420286] Wed, 25 June 2008 02:25 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Darpan,

It's really difficult to comment on bits and snips when the issue might
well be something not even mentioned in your notes. If you can try to
encapsulate it as a test case I can run locally (I do have UML
installed) I could help better.


Darpan Saini wrote:
> Hi Ed,
>
> A question about the resource suggestion that you made. When I try to
> create a resource using ResourceSet rSet =
> root.eResource().getResourceSet();
> Resource cdResource =
> rSet.createResource(URI.createURI("platform:/resource/E/change.xmi));
>
> model changes don't propagate to the other side correctly. This is
> because, lets say for example I create a class. This involves creating
> the class and then setting its name. The ChangeRecorder records both
> these changes and I send them across one by one. However, on the other
> side when I try to set the name of the class, the changeRecorder fails
> to find the class that was created by the last change. And it does not
> fail to find the class when I create it using the model's resource
> like the code below. So, does it create the element on the other side
> with the same id as the sender?
>
> The receiver code looks like this:
> Resource res =
> rSet.createResource(targetModelManager.getModelResource().ge tURI());
> res.load(bais, null);
> ChangeDescription cd = (ChangeDescription) res.getContents().get(0);
> cd.apply();
>
> rSet is the resource set of the target model.
>
> Thanks,
> -darpan
>
> Darpan,
>
> Comments below.
>
> Darpan Saini wrote:
>
> Hi,
>
> try {
> ResourceSet rSet = root.eResource().getResourceSet();
> Resource cdResource = rSet.createResource(root.eResource().getURI());
>
> This will tend to create a resource of the same type as the root
> object's resource. This might well be a specialized resource for
> serializing UML instances...
>
> c = this.endRecording();
> if (c != null) {
> tempRemoveAdapter();
> removed = true;
> c.applyAndReverse();
> publishEvent(cdResource, c);
> c.applyAndReverse();
> if (removed) {
> this.beginRecording(Collections.singletonList(root));
> removed = false;
> }
> }
>
> In the code above, I am trying to get the recording and convert
> that to a forward description using c.applyAndReverse() and then get
> the model to the changed state by calling the second
> c.applyAndReverse(). In between these two calls I serialize the
> changeDescription and send it over to another machine and call
> applyAndReverse() on it to change the model there.
>
> The call to tempRemoveAdapter removes this changeRecorder from all
> notifications while I am changing the model.
>
> Isn't it sufficient that endRecording turns of recording?
>
>
> Also, I am trying to do this for both UML models and Diagram
> Interchange models. This works fine for creating classes, packages,
> components, properties, operations, changing types of properties,
> adding parameters to operations etc.
>
> But, it fails when I create an association between two UML classes.
> I haven't figured out the exact reason but what I have found is the
> following:
> 1. The notification received in this case is a NotificationChain
> and I wonder if I should somehow handle that separately.
>
> That's just internal implementation detail. Only what's visible in
> the Notification interface matters.
>
> 2. The UML association has a feature called "memberEnd" that is a
> property (it creates this property since I created an association
> between classes). One half of the notificationchain adds the property
> to the memberEnd of the association and the other half adds the
> association to the property as "owningAssociation". However to be
> noted here is the feature has containment set to false, which results
> in applyAndReverse (ChangeDescriptionImpl) to skip its switch-case
> statement.
>
> For bidirectional references, it's important that it act only one one
> side.
>
> 3. The exception thrown says that PropertyImpl is not contained in
> a resource (it happens during the serialization of the
> ChangeDescription).
>
> I'm suspicious about your tempRemoveAdapter stuff...
>
> 4. Apart from this I also get a
> BasicEList$IndexOutOfBoundsException in a call to objectChanges.remove().
>
> I have tried the alternative way of making copies of the model and
> the changeDescription but with that:
> 1. I have the same problem of PropertyImpl is not contained in a
> resource.
> 2. Plus when I make a copy of the model, I am not able to resolved
> elements on the other side. The ids in the copy of the UML model are
> totally different.
>
> I wonder if there is a better approach to doing this?
>
> It's almost impossible to say something meaningful without seeing the
> problem in action. Perhaps there's a bug, perhaps your doing
> something wrong, I can't say for sure. And I'll be traveling for a
> few days, so trying your test case, if you provided one, might take a
> while.
>
>
> Any help appreciated.
>
> Thanks,
> -darpan
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Retrieve namespace URI
Next Topic:Why doesn't DocumentRoot get a prefix?
Goto Forum:
  


Current Time: Fri Apr 26 02:55:20 GMT 2024

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

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

Back to the top