Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Embedding arbitrary models in a model
icon5.gif  Embedding arbitrary models in a model [message #995677] Sun, 30 December 2012 21:20 Go to next message
Daniel Wildschut is currently offline Daniel Wildschut
Messages: 4
Registered: December 2012
Junior Member
Hello,
I'm currently trying to figure out how to embed other models in my EMF model.
I managed to make it work for one model by importing the other metamodel using Load Resource, however I want to be able to use any model without having to add it to my metamodel.

Here's my use case:
I have one metamodel defining a simple document model:
@namespace(
	uri="documentmodel",
	prefix="doc")
package document;

class article {
   val InfoType info;
   val SectionType section;
}

class InfoType {
   attr String title;
   attr String[0..1] role;   
}

class SectionType {
   val InfoType info;
   val ParaType[*] para;   
}

class ParaType {
   val EObject[*] content;
}

Additionally I have other metamodels describing possible content for each paragraph, so that a possible model looks like this:
<?xml version="1.0" encoding="ASCII"?>
<doc:article xmlns:doc="documentmodel" xmlns:us="userstorymodel">
  <info title="Application 1"/>
  <section>
    <info title="Application 1 user stories" role="user story"/>
    <para>
      <content xsi:type="us:story"/>
      	<given>Given</given>
      	<when>When</when>
      	<then>Then</then>
    </para>
  </section>
</doc:article>

The idea is that the user can add new content types without touching the document model by simply registering their metamodel.

As seen in the document model I experimented a bit with EObject containment references, but so far it hasn't worked.

So, is it even possible to do what I want?
And if so, what is the best way to do so?

Thanks in advance.
Regards,
DW
Re: Embedding arbitrary models in a model [message #995814 is a reply to message #995677] Mon, 31 December 2012 07:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26126
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Daniel,<br>
<br>
Comments below.<br>
<br>
<div class="moz-cite-prefix">On 31/12/2012 12:51 AM, Daniel
Wildschut wrote:<br>
</div>
<blockquote cite="mid:kbqk27$b38$1@xxxxxxxxe.org" type="cite">Hello,
<br>
I'm currently trying to figure out how to embed other models in my
EMF model. </blockquote>
A reference of type EObject will allow you to refer to any other
instance...<br>
<blockquote cite="mid:kbqk27$b38$1@xxxxxxxxe.org" type="cite">
I managed to make it work for one model by importing the other
metamodel using Load Resource, however I want to be able to use
any model without having to add it to my metamodel. <br>
</blockquote>
<br>
<blockquote cite="mid:kbqk27$b38$1@xxxxxxxxe.org" type="cite">Here's
my use case:
<br>
I have one metamodel defining a simple document model:
<br>
@namespace(
<br>
    uri="documentmodel",
<br>
    prefix="doc")
<br>
package document;
<br>
<br>
class article {
<br>
  val InfoType info;
<br>
  val SectionType section;
<br>
}
<br>
<br>
class InfoType {
<br>
  attr String title;
<br>
  attr String[0..1] role;   }
<br>
<br>
class SectionType {
<br>
  val InfoType info;
<br>
  val ParaType[*] para;   }
<br>
<br>
class ParaType {
<br>
  val EObject[*] content;
<br>
}
<br>
Additionally I have other metamodels describing possible content
for each paragraph, so that a possible model looks like this:
<br>
&lt;?xml version="1.0" encoding="ASCII"?&gt;
<br>
&lt;doc:article xmlns:doc="documentmodel"
xmlns:us="userstorymodel"&gt;
<br>
 &lt;info title="Application 1"/&gt;
<br>
 &lt;section&gt;
<br>
   &lt;info title="Application 1 user stories" role="user
story"/&gt;
<br>
   &lt;para&gt;
<br>
     &lt;content xsi:type="us:story"/&gt;
<br>
         &lt;given&gt;Given&lt;/given&gt;
<br>
         &lt;when&gt;When&lt;/when&gt;
<br>
         &lt;then&gt;Then&lt;/then&gt;
<br>
   &lt;/para&gt;
<br>
 &lt;/section&gt;
<br>
&lt;/doc:article&gt;
<br>
<br>
The idea is that the user can add new content types without
touching the document model by simply registering their metamodel.
<br>
</blockquote>
Maybe this blog has an idea you can use:<br>
<blockquote><a
href="http://ed-merks.blogspot.de/2008/01/creating-children-you-didnt-know.html">http://ed-merks.blogspot.de/2008/01/creating-children-you-didnt-know.html</a><br>
</blockquote>
<br>
<blockquote cite="mid:kbqk27$b38$1@xxxxxxxxe.org" type="cite">
<br>
As seen in the document model I experimented a bit with EObject
containment references, but so far it hasn't worked.
<br>
</blockquote>
Have a look at that blog to see if that's what you have in mind.<br>
<blockquote cite="mid:kbqk27$b38$1@xxxxxxxxe.org" type="cite">
<br>
So, is it even possible to do what I want?
<br>
And if so, what is the best way to do so?
<br>
<br>
Thanks in advance.
<br>
Regards,
<br>
DW
<br>
</blockquote>
<br>
</body>
</html>
Re: Embedding arbitrary models in a model [message #996031 is a reply to message #995814] Mon, 31 December 2012 21:25 Go to previous messageGo to next message
Daniel Wildschut is currently offline Daniel Wildschut
Messages: 4
Registered: December 2012
Junior Member
While that does look interesting, I have no idea on how to apply this to my application.
Since I'm not using the genmodel, I'm looking for a solution that works dynamically for any .ecore metamodel.
I'm processing my models programmatically by loading them via ResourceSet.getResource(), so I don't use any generated code.

I did some more experiments and so far no luck.
I first tried to fix this by introducing a new (empty) supertype used for the content, so my ParaType now looks like this:
class ParaType {
  val pc.ParaContent[*] content;
}

All content models would then inherit from the supertype like this:
class Stories extends pc.ParaContent {
  val StoryType[*] story;
}

Sadly this only works for the case where the content -- in this case us:story -- is exactly the same as ParaContent -- i.e. empty --, which seems weird.
Is it possible that EMF/the dynamic case here doesn't support polymorphism (or maybe just the cross-model case)?
If that is indeed true, then the only choice is to hardcode all possibilities like this:
class ParaType {
  val us.Story[*] story;
  val ct.Constraint[*] constraint;
}

This breaks the clean separation between the structure and content models and is therefore undesirable but I haven't found any better solution.

Thanks in advance.
Regards,
DW
Re: Embedding arbitrary models in a model [message #996318 is a reply to message #996031] Tue, 01 January 2013 19:22 Go to previous messageGo to next message
Alex Panchenko is currently offline Alex Panchenko
Messages: 342
Registered: July 2009
Senior Member
Hi,

Most probably you should make you dynamic models available to EMF, see
the relevant entries from the FAQ, starting at
http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_register_a_dynamic_package.3F

Regards,
Alex

On 01/01/2013 04:25 AM, Daniel Wildschut wrote:
> While that does look interesting, I have no idea on how to apply this to
> my application.
> Since I'm not using the genmodel, I'm looking for a solution that works
> dynamically for any .ecore metamodel.
> I'm processing my models programmatically by loading them via
> ResourceSet.getResource(), so I don't use any generated code.
>
> I did some more experiments and so far no luck.
> I first tried to fix this by introducing a new (empty) supertype used
> for the content, so my ParaType now looks like this:
> class ParaType {
> val pc.ParaContent[*] content;
> }
> All content models would then inherit from the supertype like this:
>
> class Stories extends pc.ParaContent {
> val StoryType[*] story;
> }
> Sadly this only works for the case where the content -- in this case
> us:story -- is exactly the same as ParaContent -- i.e. empty --, which
> seems weird.
> Is it possible that EMF/the dynamic case here doesn't support
> polymorphism (or maybe just the cross-model case)?
> If that is indeed true, then the only choice is to hardcode all
> possibilities like this:
> class ParaType {
> val us.Story[*] story;
> val ct.Constraint[*] constraint;
> }
> This breaks the clean separation between the structure and content
> models and is therefore undesirable but I haven't found any better
> solution.
>
> Thanks in advance.
> Regards,
> DW
Re: Embedding arbitrary models in a model [message #996329 is a reply to message #996318] Tue, 01 January 2013 20:05 Go to previous messageGo to next message
Daniel Wildschut is currently offline Daniel Wildschut
Messages: 4
Registered: December 2012
Junior Member
Hello,
I already make sure to register every ecore, but I still get the errors.
To elaborate a bit more, I'm using the MWE2 workflow engine with a single ResourceSet for all models.
At the start I register all metamodels by using the StandaloneSetup.addRegisterEcoreFile method, which just wraps a call to registry.put().
Since I get no problems with any other models (including others with references and even inheriting to/from other metamodels, as long as the reference is explicitly part of the metamodel), the package registry should be fine.

As far as I can tell (it would be nice if someone with more know-how could confirm or deny) the problem is that EMF can't seem to dynamically deal with a model not fitting the metamodel's structure, even though according to inheritance rules it should be ok.
So basically I have a value in my model of type B which inherits from the stated type A of the element.
Normally this should work fine since, according to polymorphism, EMF should validate it as the supertype A and leave further processing to whatever is handling type B by looking the value's URI in the package registry.
However, according to my testing, if the type B value differs from the supertype A (e.g. by having an attribute with a name not in type A), then this immediately fails.

Regards,
DW
Re: Embedding arbitrary models in a model [message #996479 is a reply to message #996329] Wed, 02 January 2013 07:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26126
Registered: July 2009
Senior Member
Daniel,

Comments below.

On 01/01/2013 9:05 PM, Daniel Wildschut wrote:
> Hello,
> I already make sure to register every ecore, but I still get the errors.
Error?
> To elaborate a bit more, I'm using the MWE2 workflow engine with a
> single ResourceSet for all models.
> At the start I register all metamodels by using the
> StandaloneSetup.addRegisterEcoreFile method, which just wraps a call
> to registry.put().
> Since I get no problems with any other models (including others with
> references and even inheriting to/from other metamodels, as long as
> the reference is explicitly part of the metamodel), the package
> registry should be fine.
>
> As far as I can tell (it would be nice if someone with more know-how
> could confirm or deny) the problem is that EMF can't seem to
> dynamically deal with a model not fitting the metamodel's structure,
> even though according to inheritance rules it should be ok.
The symptom of not handling it is what?
> So basically I have a value in my model of type B which inherits from
> the stated type A of the element.
> Normally this should work fine since, according to polymorphism, EMF
> should validate it as the supertype A and leave further processing to
> whatever is handling type B by looking the value's URI in the package
> registry.
Normally this should work fine.
> However, according to my testing, if the type B value differs from the
> supertype A (e.g. by having an attribute with a name not in type A),
> then this immediately fails.
Fails in what way?
>
> Regards,
> DW
Re: Embedding arbitrary models in a model [message #996586 is a reply to message #996479] Wed, 02 January 2013 13:02 Go to previous message
Daniel Wildschut is currently offline Daniel Wildschut
Messages: 4
Registered: December 2012
Junior Member
The error I got is a org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'content' not found.
After some more experimenting I think I found the error.
I'm using a custom fileformat deriving from XMIResource and something went wrong when escaping the "", so that instead of xmlns:us=urn://www.teco.edu/modeling/module/user_story it used xmlns:us="urn://www.teco.edu/modeling/module/user_story", which probably lead to an error when looking up the package.

Regards,
DW
Previous Topic:[EMF] Editor Page for source code field?
Next Topic:Usage of "org.eclipse.emf.ecore.factory_override"
Goto Forum:
  


Current Time: Tue Oct 21 02:30:09 GMT 2014

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

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