Home » Modeling » EMF » Embedding arbitrary models in a model
|
Re: Embedding arbitrary models in a model [message #995814 is a reply to message #995677] |
Mon, 31 December 2012 07:14 |
Ed Merks Messages: 33141 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>
<?xml version="1.0" encoding="ASCII"?>
<br>
<doc:article xmlns:doc="documentmodel"
xmlns:us="userstorymodel">
<br>
<info title="Application 1"/>
<br>
<section>
<br>
<info title="Application 1 user stories" role="user
story"/>
<br>
<para>
<br>
<content xsi:type="us:story"/>
<br>
<given>Given</given>
<br>
<when>When</when>
<br>
<then>Then</then>
<br>
</para>
<br>
</section>
<br>
</doc:article>
<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>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Embedding arbitrary models in a model [message #996318 is a reply to message #996031] |
Tue, 01 January 2013 19:22 |
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 |
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 |
Ed Merks Messages: 33141 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 22:33:24 GMT 2024
Powered by FUDForum. Page generated in 0.02899 seconds
|