Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » linking multiple models
linking multiple models [message #405476] Wed, 22 November 2006 16:32 Go to next message
Eclipse UserFriend
Originally posted by: stevehorne.gmail.com

I cannot find a reference to this anywhere, so I'm hoping someone can point me in the right direction.

I have an existing ecore metamodel as well as a couple of instance models based on that metamodel. For example, the metamodel describes classes such as "Zoo" and "Animal", etc. The instance model contains a specific Zoo, with specific Animals associated with it.

I would like to augment these instance models with additional information without modifying the originals. I would like to add a property to Animal called "favoriteFood".

The core team (that maintains the zoo instance models) isn't concerned with the favoriteFood property, so they don't want it in their metamodel nor in their instance models. I would like to have an extension instance model that supplements the original instance by adding a property.

In the end, I would like to have two model instance files. One is the original Zoo model like it was before and the other my extension model that has references to instances in the original and provides only the supplemental information.

In summary, my problem is NOT extending an EMF metamodel. I know how to do that. I want to extend INSTANCE models, not metamodels...

Any suggestions are welcome.
Re: linking multiple models [message #405480 is a reply to message #405476] Wed, 22 November 2006 18:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Steve,

It sound like you want kind of a decorator model, right? This would be
similar to how the GenModel decorates the Ecore model. So you'd have
a ZooDecorator class that has a reference to a Zoo class and then has
additional attributes and reference. This decorator model could mirror
the hierarchy of the original model.. Is that what you have in mind?


Steve Horne wrote:
> I cannot find a reference to this anywhere, so I'm hoping someone can point me in the right direction.
>
> I have an existing ecore metamodel as well as a couple of instance models based on that metamodel. For example, the metamodel describes classes such as "Zoo" and "Animal", etc. The instance model contains a specific Zoo, with specific Animals associated with it.
>
> I would like to augment these instance models with additional information without modifying the originals. I would like to add a property to Animal called "favoriteFood".
>
> The core team (that maintains the zoo instance models) isn't concerned with the favoriteFood property, so they don't want it in their metamodel nor in their instance models. I would like to have an extension instance model that supplements the original instance by adding a property.
>
> In the end, I would like to have two model instance files. One is the original Zoo model like it was before and the other my extension model that has references to instances in the original and provides only the supplemental information.
>
> In summary, my problem is NOT extending an EMF metamodel. I know how to do that. I want to extend INSTANCE models, not metamodels...
>
> Any suggestions are welcome.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: linking multiple models [message #405485 is a reply to message #405480] Thu, 23 November 2006 03:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: stevehorne.gmail.com

> Steve,
>
> It sound like you want kind of a decorator model,
> right? This would be
> similar to how the GenModel decorates the Ecore
> model. So you'd have
> a ZooDecorator class that has a reference to a Zoo
> class and then has
> additional attributes and reference. This decorator
> model could mirror
> the hierarchy of the original model.. Is that what
> you have in mind?
>

Yes, it is the decorator pattern. I have since discovered that there is no difference for extending the model vs. extending the metamodel (a rose by any other name)- I have done that now for my extended model.

So now, I have an extended metamodel (called AnimalCare, for instance) and I have created a "Diet" class in my extended model. A property of Diet is "favoriteFood". It also has a reference to an Animal (from the Zoo metamodel).

Now, in the generated AnimalCare editor, I can do a "Load Resource" on a Zoo model instance ("frankfurt.zoo"). Then I can create a Diet instance, set the Animal reference to "Stampy the Elephant" and set favoriteFood to "watermelons". So far so good.

Now my problem is the reference between the model files. It seems to be entirely positional (e.g. frankfurt.zoo#//Zoo.0/Animal.3)
Any change to the original model breaks the relationship. Is there any way to have a unique identifier for the purpose of keeping looser coupling on the association?

Thanks for reading.
Re: linking multiple models [message #405493 is a reply to message #405485] Thu, 23 November 2006 10:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090804080205090109000007
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Steve,

We've been playing with
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=119586>

https://bugs.eclipse.org/bugs/show_bug.cgi?id=119586

which would allow you to specify which attributes of a referenced type
act as keys with respect to that type. This would allow references like
this .../@Animals[name='Stampy%20the%20Elephant'] where the name would
be the key of the Animals reference. But since we haven't committed
that yet, you can't use it yet. :-(

Another very similar approach is to specialize
eObjectForURIFragmentSegment/eURIFragmentSegment to use a more friendly
syntax. We've done this in Ecore and you can look at EModelElementImpl
for how we've done that.

A third approach is to use IDs. You could use an XMLResourceImpl with
useUUIDs overridden to return true; this will assign very ugly IDs to
each object and fill your resource with them. But they have the nice
property that the identity of an object is fixed for all time and that
you don't have to manage them manual. Another variation on the ID
approach is to define EAttributes with isID true. This is like defining
an attribute of type xsd:ID in XML Schema. You must assign the
attribute value yourself, and if present, that value will be used as a
reference. The value must be unique within the resource and it should
conform to the production rule for XML Schema IDs, i.e., it should be an
NCName; EMF is more forgiving than that, so as long as the value doesn't
use characters with special meaning, ' ', '#', ':', it would work okay.


Steve Horne wrote:
> &gt; Steve,
> &gt;
> &gt; It sound like you want kind of a decorator model,
> &gt; right? This would be
> &gt; similar to how the GenModel decorates the Ecore
> &gt; model. So you'd have
> &gt; a ZooDecorator class that has a reference to a Zoo
> &gt; class and then has
> &gt; additional attributes and reference. This decorator
> &gt; model could mirror
> &gt; the hierarchy of the original model.. Is that what
> &gt; you have in mind?
> &gt;
>
> Yes, it is the decorator pattern. I have since discovered that there is no difference for extending the model vs. extending the metamodel (a rose by any other name)- I have done that now for my extended model.
>
> So now, I have an extended metamodel (called AnimalCare, for instance) and I have created a "Diet" class in my extended model. A property of Diet is "favoriteFood". It also has a reference to an Animal (from the Zoo metamodel).
>
> Now, in the generated AnimalCare editor, I can do a "Load Resource" on a Zoo model instance ("frankfurt.zoo"). Then I can create a Diet instance, set the Animal reference to "Stampy the Elephant" and set favoriteFood to "watermelons". So far so good.
>
> Now my problem is the reference between the model files. It seems to be entirely positional (e.g. frankfurt.zoo#//Zoo.0/Animal.3)
> Any change to the original model breaks the relationship. Is there any way to have a unique identifier for the purpose of keeping looser coupling on the association?
>
> Thanks for reading.
>


--------------090804080205090109000007
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Steve,<br>
<br>
We've been playing with<a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=119586"><br>
</a>
<blockquote><a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=119586">https://bugs.eclipse.org/bugs/show_bug.cgi?id=119586</a><br>
</blockquote>
which would allow you to specify which attributes of a referenced type
act as keys with respect to that type.&nbsp; This would allow references
like this .../@Animals[name='Stampy%20the%20Elephant'] where the name
would be the key of the Animals reference.&nbsp; But since we haven't
committed that yet, you can't use it yet.&nbsp; :-(<br>
<br>
Another very similar approach is to specialize
eObjectForURIFragmentSegment/eURIFragmentSegment to use a more friendly
syntax.&nbsp; We've done this in Ecore and you can look at EModelElementImpl
for how we've done that.<br>
<br>
A third approach is to use IDs.&nbsp; You could use an XMLResourceImpl with
useUUIDs overridden to return true; this will assign very ugly IDs to
each object and fill your resource with them.&nbsp; But they have the nice
property that the identity of an object is fixed for all time and that
you don't have to manage them manual.&nbsp; Another variation on the ID
approach is to define EAttributes with isID true.&nbsp; This is like
defining an attribute of type xsd:ID in XML Schema.&nbsp; You must assign
the attribute value yourself, and if present, that value will be used
as a reference.&nbsp; The value must be unique within the resource and it
should conform to the production rule for XML Schema IDs, i.e., it
should be an NCName; EMF is more forgiving than that, so as long as the
value doesn't use characters with special meaning, ' ', '#', ':', it
would work okay.<br>
<br>
<br>
Steve Horne wrote:
<blockquote
cite="mid6197322.1164253730266.JavaMail.root@cp1.javalobby.org"
type="cite">
<pre wrap="">&amp;gt; Steve,
&amp;gt;
&amp;gt; It sound like you want kind of a decorator model,
&amp;gt; right? This would be
&amp;gt; similar to how the GenModel decorates the Ecore
&amp;gt; model. So you'd have
&amp;gt; a ZooDecorator class that has a reference to a Zoo
&amp;gt; class and then has
&amp;gt; additional attributes and reference. This decorator
&amp;gt; model could mirror
&amp;gt; the hierarchy of the original model.. Is that what
&amp;gt; you have in mind?
&amp;gt;

Yes, it is the decorator pattern. I have since discovered that there is no difference for extending the model vs. extending the metamodel (a rose by any other name)- I have done that now for my extended model.

So now, I have an extended metamodel (called AnimalCare, for instance) and I have created a "Diet" class in my extended model. A property of Diet is "favoriteFood". It also has a reference to an Animal (from the Zoo metamodel).

Now, in the generated AnimalCare editor, I can do a "Load Resource" on a Zoo model instance ("frankfurt.zoo"). Then I can create a Diet instance, set the Animal reference to "Stampy the Elephant" and set favoriteFood to "watermelons". So far so good.

Now my problem is the reference between the model files. It seems to be entirely positional (e.g. frankfurt.zoo#//Zoo.0/Animal.3)
Any change to the original model breaks the relationship. Is there any way to have a unique identifier for the purpose of keeping looser coupling on the association?

Thanks for reading.
</pre>
</blockquote>
<br>
</body>
</html>

--------------090804080205090109000007--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: linking multiple models [message #405574 is a reply to message #405493] Mon, 27 November 2006 22:52 Go to previous message
Eclipse UserFriend
Originally posted by: stevehorne.gmail.com

Ed:
Thanks for your reply, it set me on the one true path...

For the benefit of others, I am posting some of the implementation:

I created XMIResourceFactoryImpl:
package zoo;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;

public class XMIResourceFactoryImpl extends
       org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl {

	@Override
	public Resource createResource(URI arg0) {
		return new zoo.XMIResourceImpl(arg0);
	}

}


Then I created XMIResourceImpl:
package zoo;

import org.eclipse.emf.common.util.URI;

public class XMIResourceImpl extends
		org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl {

	public XMIResourceImpl() { super(); }
	public XMIResourceImpl(URI uri) { super(uri); }

	@Override
	protected boolean useUUIDs() {
		return true;
	}

}


Then I changed the plugin.xml, adding the extension "extension_parser":

<plugin>

<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri = "http://zoo/id"
class = "zoo.ZooPackage"
genModel = "model/zoo.genmodel" />
</extension>
<extension
point="org.eclipse.emf.ecore.extension_parser">
<parser type="zoo"
class="zoo.XMIResourceFactoryImpl"/>
</extension>

</plugin>
[/xml]

After doing all this, I launched the new editor and got a new attribute on the Animal nodes:
xmi:id="_VXq9AH5nEduqocJBhRz8pA"


External references to those nodes use the xmi:id as the href...

Thanks again for all your help!
Previous Topic:Adding further properties to the genmodel
Next Topic:Re: EMF using XMI
Goto Forum:
  


Current Time: Thu Apr 25 21:15:13 GMT 2024

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

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

Back to the top