Skip to main content



      Home
Home » Modeling » EMF » Cross-reference between several models(Using TransactionalEditingDomain)
Cross-reference between several models [message #819159] Mon, 12 March 2012 11:18 Go to next message
Eclipse UserFriend
Hi,

I want to use TransactionalEditingDomain to synchronize several models between them, in order to separate a "business model" (only the usefull information I want to keep) and a "notation model" (e.g. the coordinates of each object) for example (like in GMF).

I want something like this :

Business Model:
<?xml version="1.0" encoding="ASCII"?>
<test:TestModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://test/1.0">
  <square name="squareA"/>
  <circle name="circleA"/>
</test:TestModel>


Notation Model:
<?xml version="1.0" encoding="ASCII"?>
<notation:NotationModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://notation/1.0">
  <notation href="referenceToSquareA" x="40" y="20" />
  <notation href="referenceToCircleA" x="100" y="10" />
</test:TestModel>


For this, I tried to use the absolute URI of each EObject as identifier for the href attribute. I extended ResourceSetListenerImpl to listen to modifications inside my business model and modify my other models like this :

MyListener:
public class MyListener extends ResourceSetListenerImpl {
public Command transactionAboutToCommit(ResourceSetChangeEvent event)
		      throws RollbackException {
	List notifications = event.getNotifications();
	for (Iterator i = notifications.iterator(); i.hasNext();) {
		Notification n = (Notification)i.next();
			
		if (n.getEventType() == Notification.SET && n.getNotifier() instanceof Square) {
			Square notifier = (Square) n.getNotifier();
			System.out.println (EcoreUtil.getURI(notifier));
			// Modification of the notation model
		}
	}
}


Problems appear when :
- I delete an EObject inside my business model:
transactionAboutToCommit:
...
if (n.getEventType() == Notification.REMOVE && n.getOldValue() instanceof Square) {
	Square notifier = (Square) n.getNotifier();
	System.out.println (EcoreUtil.getURI(notifier)); // print "#//"
}
...

- I add an EObject in a collection of EObject:
Modifiying my business model:
editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
	protected void doExecute() {
		TestModel model = (TestModel)resource.getContents().get(0);
					
		Square square = SquareFactory.eINSTANCE.createSquare();
		model.getSquare().add(2,square); // I add square in third position, what about the URI of the fourth and the fifth square ? 
	}
});


I found some topics about the problem of synchronizing several models but no implementation which do this.

Does anybody have an idea to achieve this ?

Best regards,

--
Nicolas
Re: Cross-reference between several models [message #819183 is a reply to message #819159] Mon, 12 March 2012 11:43 Go to previous messageGo to next message
Eclipse UserFriend
Nicolas,

Comments below.

On 12/03/2012 4:18 PM, nicolas h wrote:
> Hi,
>
> I want to use TransactionalEditingDomain to synchronize several models
> between them, in order to separate a "business model" (only the
> usefull information I want to keep) and a "notation model" (e.g. the
> coordinates of each object) for example (like in GMF).
>
> I want something like this :
>
> Business Model:
>
> <?xml version="1.0" encoding="ASCII"?>
> <test:TestModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:test="http://test/1.0">
> <square name="squareA"/>
> <circle name="circleA"/>
> </test:TestModel>
>
>
> Notation Model:
>
> <?xml version="1.0" encoding="ASCII"?>
> <notation:NotationModel xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://notation/1.0">
> <notation href="referenceToSquareA" x="40" y="20" />
> <notation href="referenceToCircleA" x="100" y="10" />
> </test:TestModel>
>
>
> For this, I tried to use the absolute URI of each EObject as
> identifier for the href attribute. I extended ResourceSetListenerImpl
> to listen to modifications inside my business model and modify my
> other models like this :
>
> MyListener:
> public class MyListener extends ResourceSetListenerImpl {
> public Command transactionAboutToCommit(ResourceSetChangeEvent event)
> throws RollbackException {
> List notifications = event.getNotifications();
> for (Iterator i = notifications.iterator(); i.hasNext();) {
> Notification n = (Notification)i.next();
>
> if (n.getEventType() == Notification.SET && n.getNotifier()
> instanceof Square) {
> Square notifier = (Square) n.getNotifier();
> System.out.println (EcoreUtil.getURI(notifier));
> // Modification of the notation model
> }
> }
> }
>
> Problems appear when :
> - I delete an EObject inside my business model: transactionAboutToCommit:
>
> ..
> if (n.getEventType() == Notification.REMOVE && n.getOldValue()
> instanceof Square) {
> Square notifier = (Square) n.getNotifier();
> System.out.println (EcoreUtil.getURI(notifier)); // print "#//"
The object is no longer attached to the graph so it has no containing
resource and hence you can't determine it's original absolute URI.
> }
> ..
>
> - I add an EObject in a collection of EObject:
> Modifiying my business model:
>
> editingDomain.getCommandStack().execute(new
> RecordingCommand(editingDomain) {
> protected void doExecute() {
> TestModel model = (TestModel)resource.getContents().get(0);
>
> Square square = SquareFactory.eINSTANCE.createSquare();
> model.getSquare().add(2,square); // I add square in third
> position, what about the URI of the fourth and the fifth square ? }
> });
>
>
> I found some topics about the problem of synchronizing several models
> but no implementation which do this.
What are you trying to do with the URIs? You could traverse the
notation model to look for dangling references (references to EObjects
for which eResource is null). EcoreUtil has a utility for that.
>
> Does anybody have an idea to achieve this ?
>
> Best regards,
>
Re: Cross-reference between several models [message #820012 is a reply to message #819183] Tue, 13 March 2012 12:12 Go to previous message
Eclipse UserFriend
Hi Ed,

Thank you for your remark. I wasn't interested in the EcoreUtil's capabilities. I'm rereading the part about splitting model into multiple packages from the EMF book. I realize that I wasn't on the right track.

Thank you again,


Regards,


--
Nicolas
Previous Topic:[Databinding] TreeViewer not notified
Next Topic:[Xcore] preceding comment as GenModel documentation?
Goto Forum:
  


Current Time: Mon Jul 07 05:24:51 EDT 2025

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

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

Back to the top