Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Dynamic EMF / Multiple Inheritance
Dynamic EMF / Multiple Inheritance [message #491030] Mon, 12 October 2009 23:14 Go to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
I have a model defined with two classes:

Class1
attribute1 : String

Class2
attribute2 : String

And I would like to dynamically create a new class Class3 that inherits Class1 and Class2 (Class1 via extends and Class2 via interface inheritance). How can I specify this. I tried something like this:
EPackage pkg = EcoreFactory.eINSTANCE.createEPackage();
pkg.setName("MyPackage");
pkg.setNsPrefix("myprefix");
pkg.setNsURI("my.namespace");

EClass cls = EcoreFactory.eINSTANCE.createEClass();
cls.setName("Class3");

cls.getESuperTypes().add(ModelPackage.eINSTANCE.getClass1());
cls.getESuperTypes().add(ModelPackage.eINSTANCE.getClass2());
		
pkg.getEClassifiers().add(cls);
		
EObject myClass = pkg.getEFactoryInstance().create(cls);

but to no avail. Is this possible using dynamic EMF? And if so, what am I missing?

Thanks,

JT
Re: Dynamic EMF / Multiple Inheritance [message #491047 is a reply to message #491030] Tue, 13 October 2009 03:45 Go to previous messageGo to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
I forgot to mention that I implement the feature 'attribute2' from Class2 in Class3 using the following code:

EAttribute attribute2 = EcoreFactory.eINSTANCE.createEAttribute();
attribute2.setName("attribute2");
attribute2.setEType(EPackage.eINSTANCE.getEString());
cls.getEStructuralFeatures().add(attribute2);


This doesn't, however, connect the derived structural feature id for Class3.attribute2 with the feature id from Class2.attribute2.

Thanks,

JT
Re: Dynamic EMF / Multiple Inheritance [message #491052 is a reply to message #491030] Tue, 13 October 2009 03:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
John,

Comments below.

John T.E. Timm wrote:
> I have a model defined with two classes:
>
> Class1
> attribute1 : String
>
> Class2
> attribute2 : String
>
> And I would like to dynamically create a new class Class3 that
> inherits Class1 and Class2 (Class1 via extends and Class2 via
> interface inheritance). How can I specify this. I tried something like
> this:
>
> EPackage pkg = EcoreFactory.eINSTANCE.createEPackage();
> pkg.setName("MyPackage");
> pkg.setNsPrefix("myprefix");
> pkg.setNsURI("my.namespace");
>
> EClass cls = EcoreFactory.eINSTANCE.createEClass();
> cls.setName("Class3");
>
> cls.getESuperTypes().add(ModelPackage.eINSTANCE.getClass1()) ;
> cls.getESuperTypes().add(ModelPackage.eINSTANCE.getClass2()) ;
>
> pkg.getEClassifiers().add(cls);
>
> EObject myClass = pkg.getEFactoryInstance().create(cls);
>
> but to no avail.
What's not availing? If Class1 and Class2 are generated classes, then
it's not going to work because a dynamic class can only behave like a
generated class if it literally extends the generated Impl...
> Is this possible using dynamic EMF? And if so, what am I missing?
>
> Thanks,
>
> JT


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Dynamic EMF / Multiple Inheritance [message #491053 is a reply to message #491047] Tue, 13 October 2009 03:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
John,

You can't have the same named feature more than once in the hierarchy.


John T.E. Timm wrote:
> I forgot to mention that I implement the feature 'attribute2' from
> Class2 in Class3 using the following code:
>
>
> EAttribute attribute2 = EcoreFactory.eINSTANCE.createEAttribute();
> attribute2.setName("attribute2");
> attribute2.setEType(EPackage.eINSTANCE.getEString());
> cls.getEStructuralFeatures().add(attribute2);
>
>
> This doesn't, however, connect the derived structural feature id for
> Class3.attribute2 with the feature id from Class2.attribute2.
>
> Thanks,
>
> JT


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Dynamic EMF / Multiple Inheritance [message #491058 is a reply to message #491030] Tue, 13 October 2009 04:06 Go to previous messageGo to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
Ed,

Thanks for the reply. I actually created a Class3 with multiple inheritance in UML where one generalization was marked as <<extend>> and the other became an interface when I imported this into EMF, I got:

interface Class1
interface Class2
interface Class3 extends Class1, Class2

class Class3Impl extends Class1Impl implements Class3 {
    protected String attribute2;

    public String getAttribute2() { ... }
    public void setAttribute2(String newAttribute2() { ... }
}


and ended up with features from Class2 copied down into Class3 (e.g. attribute2).

I was trying to replicate this scenario with dynamic EMF so that Class3 actually extends Class1 but also implements Class2 features (hence why I was asking about putting attribute2 into Class3).

I'm basically trying to replicate what is presented here:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .emf.doc/references/overview/EMF.html

Where classes Book and Asset are statically defined and SchoolBook is created via dynamic EMF.

Thanks,

JT

[Updated on: Tue, 13 October 2009 04:15]

Report message to a moderator

Re: Dynamic EMF / Multiple Inheritance [message #491059 is a reply to message #491058] Tue, 13 October 2009 04:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050806040505020906030106
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

John,

Comments below.

John T.E. Timm wrote:
> Ed,
>
> Thanks for the reply. I actually created a Class3 with multiple
> inheritance in UML where one generalization was marked as <<extend>>
> and the other became an interface when I imported this into EMF, I got:
>
> interface Class1
> interface Class2
> interface Class3 extends Class1, Class2
>
> class Class3Impl extends Class1Impl implements Class1, Class2 {
Probably more like class Class3Impl extends Class1Impl implements
*Class3*, Class2 {
> protected String attribute2;
>
> public String getAttribute2() { ... }
> public void setAttribute2(String newAttribute2() { ...}
> }
>
> and ended up with features from Class2 copied down into Class3 (e.g.
> attribute2
The generated code for the mix-in class is duplicated, but that's not
the same as copying features in the Ecore model itself.
>
> I was trying to replicate this scenario with dynamic EMF so that
> Class3 actually extends Class1 but also implements Class2 features
> (hence why I was asking about putting attribute2 into Class3).
Ecore itself has no concept of extends verses implements. That's just
something in the generated Java code which isn't relevant when there
isn't any generated Java code.
>
> Thanks,
>
> JT

--------------050806040505020906030106
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
John,<br>
<br>
Comments below.<br>
<br>
John T.E. Timm wrote:
<blockquote cite="mid:hb0ubi$rfi$1@build.eclipse.org" type="cite">Ed,
<br>
<br>
Thanks for the reply. I actually created a Class3 with multiple
inheritance in UML where one generalization was marked as
&lt;&lt;extend&gt;&gt; and the other became an interface when I
imported this into EMF, I got:
<br>
<br>
interface Class1
<br>
interface Class2
<br>
interface Class3 extends Class1, Class2
<br>
<br>
class Class3Impl extends Class1Impl implements Class1, Class2 {
<br>
</blockquote>
Probably more like class Class3Impl extends Class1Impl implements <b>Class3</b>,
Class2 {
<blockquote cite="mid:hb0ubi$rfi$1@build.eclipse.org" type="cite">  
protected String attribute2;
<br>
<br>
   public String getAttribute2() { ... }
<br>
   public void setAttribute2(String newAttribute2() { ...}
<br>
}
<br>
<br>
and ended up with features from Class2 copied down into Class3 (e.g.
attribute2
<br>
</blockquote>
The generated code for the mix-in class is duplicated, but that's not
the same as copying features in the Ecore model itself.<br>
<blockquote cite="mid:hb0ubi$rfi$1@build.eclipse.org" type="cite"><br>
I was trying to replicate this scenario with dynamic EMF so that Class3
actually extends Class1 but also implements Class2 features (hence why
I was asking about putting attribute2 into Class3).
<br>
</blockquote>
Ecore itself has no concept of extends verses implements. That's just
something in the generated Java code which isn't relevant when there
isn't any generated Java code.<br>
<blockquote cite="mid:hb0ubi$rfi$1@build.eclipse.org" type="cite"><br>
Thanks,
<br>
<br>
JT
<br>
</blockquote>
</body>
</html>

--------------050806040505020906030106--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Dynamic EMF / Multiple Inheritance [message #491060 is a reply to message #491030] Tue, 13 October 2009 04:21 Go to previous message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
I was in the middle of updating my last entry to more accurately reflect the generated code when you replied. It looks like I will not be able to recreate this scenario with dynamic EMF.

Thanks,

JT
Previous Topic:XMLTypeFactoryImpl fails to resolve QNames properly while "undoing change"
Next Topic:StackOverflow Error in Eclipse Galileo and TopCased 3.1.0
Goto Forum:
  


Current Time: Thu Sep 26 14:35:46 GMT 2024

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

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

Back to the top