Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Trying to reference an interface from an EClass
Trying to reference an interface from an EClass [message #425727] Fri, 05 December 2008 15:44 Go to next message
Derek Palma is currently offline Derek PalmaFriend
Messages: 141
Registered: July 2009
Senior Member
Hi,

I want to have an EClass with a reference to my Java interface (not an EMF
class); let's call this MyInterface. I need a getter and setter for it. I
have created an EReference in my Ecore model in my hosting EClass. I have
made an EClass with its instance type as MyInterface and set the EReference
to refer to this EClass. (I have also tweaked derived, volatile, and
transient.) However, I see a MyInterfaceImpl get generated by EMF. This file
does not compile because it does not contain the methods which implement
MyInterface. Also, the generated FactoryImpl contains a create method for
the reference.

I presume I cannot use interfaces as references the way I am attempting. I
would like to avoid generation of the factory method and the Impl class or
achieve some similar effect. What is the correct approach for modeling a
reference to an interface in an EClass?

Thanks in advance.
Derek Palma
Re: Trying to reference an interface from an EClass [message #425732 is a reply to message #425727] Fri, 05 December 2008 16:15 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Hey Derek,

> I presume I cannot use interfaces as references the way I am attempting.
> I would like to avoid generation of the factory method and the Impl
> class or achieve some similar effect. What is the correct approach for
> modeling a reference to an interface in an EClass?

You can create an EDataType and set its class attribute to your
interface type. Then in the referencing class use an EAttribute with
that EDataType as its type.

Felix
Re: Trying to reference an interface from an EClass [message #425739 is a reply to message #425732] Fri, 05 December 2008 18:59 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Felix/Derek,

It's also possible to wrap an EClass around an existing interface (the
same as an EDataType does) and mark isInterface and isAbstract true.
This is typically most useful for use as an EClass.eSuperType. If used
as an EReference, EMF will assume that the actual instance value
implements EObject when it tried to serialize it, so that might be
bad. If you use an EDataType for an EAttribute, you generally will
need to write code in the generated XyzFactoryImpl to convert the
instance value to and from a string.


Felix Dorner wrote:
> Hey Derek,
>
>> I presume I cannot use interfaces as references the way I am
>> attempting. I would like to avoid generation of the factory method
>> and the Impl class or achieve some similar effect. What is the
>> correct approach for modeling a reference to an interface in an EClass?
>
> You can create an EDataType and set its class attribute to your
> interface type. Then in the referencing class use an EAttribute with
> that EDataType as its type.
>
> Felix


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EList performance issues
Next Topic:Metamodel registered multiple times
Goto Forum:
  


Current Time: Wed Apr 24 22:06:15 GMT 2024

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

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

Back to the top