Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » specialization(How do i extend a common base class with specific features?)
specialization [message #714420] Wed, 10 August 2011 14:01 Go to next message
Daniel Winkels is currently offline Daniel WinkelsFriend
Messages: 19
Registered: October 2010
Junior Member
Hello together,

i've got a problem: I want to create a meta model for a system, with which i want to generate some code. in this model occur the following EClasses with their corresponding value types:
Field
TextField (String)
NumericField (Integer)
DateField (Date)
KeywordField (String[])

I want to have the common properties in the abstract "Field"-Class and also want to have a property "fieldType" which contains a String that i need in the generated code, which is depending on the concrete class. To use this in Xpand i think i have to model it in the "Field"-Class, but how do i set it depending on the class directly in ecore? Is there a specific annotation that can help me? i just don't know where to look for my solution Smile

i would appreciate any help

thank you
daniel
Re: specialization [message #714452 is a reply to message #714420] Wed, 10 August 2011 14:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Daniel,

I read your question and I actually don't understand it. Perhaps you
can use an EAnnotation on the EClass but I don't really understand what
you're trying to do specifically.


On 10/08/2011 7:01 AM, Daniel Winkels wrote:
> Hello together,
>
> i've got a problem: I want to create a meta model for a system, with
> which i want to generate some code. in this model occur the following
> EClasses with their corresponding value types:
> Field
> TextField (String)
> NumericField (Integer)
> DateField (Date)
> KeywordField (String[])
>
> I want to have the common properties in the abstract "Field"-Class and
> also want to have a property "fieldType" which contains a String that
> i need in the generated code, which is depending on the concrete
> class. To use this in Xpand i think i have to model it in the
> "Field"-Class, but how do i set it depending on the class directly in
> ecore? Is there a specific annotation that can help me? i just don't
> know where to look for my solution :)
>
> i would appreciate any help
>
> thank you
> daniel


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: specialization [message #714741 is a reply to message #714452] Thu, 11 August 2011 12:18 Go to previous messageGo to next message
Daniel Winkels is currently offline Daniel WinkelsFriend
Messages: 19
Registered: October 2010
Junior Member
Hello Ed,

i assumed that the question is somehow unclear. I uploaded an image with a small example of what i am intending to do.
I just explain it:
index.php/fa/3627/0/
"DialogElement" is the abstract common base of "File" and "Date". There will be no instance of "DialogElement" but of its children. All I want to do is set the field "type" = "DateField" or "type" = "FileField" according to the Class of the instance. There will be no need to change the value again, so it can be set statically or on initialization time. I just do not know how to assign static or default values in a subclass to a field that is modeled in the superclass.

I hope it is getting clearer Smile
Re: specialization [message #714768 is a reply to message #714741] Thu, 11 August 2011 12:36 Go to previous messageGo to next message
Daniel Winkels is currently offline Daniel WinkelsFriend
Messages: 19
Registered: October 2010
Junior Member
Am 11.08.11 14:18, schrieb Daniel Winkels:
> Hello Ed,
>
> i assumed that the question is somehow unclear. I uploaded an image with a small example of what i am intending to do.
> I just explain it:
>
> "DialogElement" is the abstract common base of "File" and "Date". There will be no instance of "DialogElement" but of its children. All I want to do is set the field "type" = "DateField" or "type" = "FileField" according to the Class of the instance. There will be no need to change the value again, so it can be set statically or on initialization time. I just do not know how to assign static or default values in a subclass to a field that is modeled in the superclass.
>
> I hope it is getting clearer :)

I just saw that my image is wrong. The superclass of Date should be
DialogElement.
Re: specialization [message #714769 is a reply to message #714768] Thu, 11 August 2011 12:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

I don't think you can override the default value. What you could do is
to model it as a derived feature and implement the corresponding get
method in the subclass' implementation. That way the values may differ
and you still access it as a "normal" attribute.

hallvard

On 11.08.11 14.36, Daniel Winkels wrote:
> Am 11.08.11 14:18, schrieb Daniel Winkels:
>> Hello Ed,
>>
>> i assumed that the question is somehow unclear. I uploaded an image
>> with a small example of what i am intending to do.
>> I just explain it:
>>
>> "DialogElement" is the abstract common base of "File" and "Date".
>> There will be no instance of "DialogElement" but of its children. All
>> I want to do is set the field "type" = "DateField" or "type" =
>> "FileField" according to the Class of the instance. There will be no
>> need to change the value again, so it can be set statically or on
>> initialization time. I just do not know how to assign static or
>> default values in a subclass to a field that is modeled in the
>> superclass.
>>
>> I hope it is getting clearer :)
>
> I just saw that my image is wrong. The superclass of Date should be
> DialogElement.
Re: specialization [message #714772 is a reply to message #714769] Thu, 11 August 2011 13:03 Go to previous messageGo to next message
Daniel Winkels is currently offline Daniel WinkelsFriend
Messages: 19
Registered: October 2010
Junior Member
Hello Hallvard,

this sounds like a pretty good solution, even though i thought it would
be possible in another way. I will try it like this. But wouldn't it be
possible to set a self defined annotation to the class "Date" or "File"
which contains the actual field value and then write the get method in
the superclass so, that it accesses the annotation of the concrete
eclass based on the instance? So i would have
DialogElement.getType() -> this.getEClass().getMyAnnotationValue()
(this is really pseudo code)

It is really just thinking and discussing. Don't be to hard on me if
this is too complicated, impossible or anything else :-)

Daniel

Am 11.08.11 14:42, schrieb Hallvard Trætteberg:
> I don't think you can override the default value. What you could do is
> to model it as a derived feature and implement the corresponding get
> method in the subclass' implementation. That way the values may differ
> and you still access it as a "normal" attribute.
>
> hallvard
>
> On 11.08.11 14.36, Daniel Winkels wrote:
>> Am 11.08.11 14:18, schrieb Daniel Winkels:
>>> Hello Ed,
>>>
>>> i assumed that the question is somehow unclear. I uploaded an image
>>> with a small example of what i am intending to do.
>>> I just explain it:
>>>
>>> "DialogElement" is the abstract common base of "File" and "Date".
>>> There will be no instance of "DialogElement" but of its children. All
>>> I want to do is set the field "type" = "DateField" or "type" =
>>> "FileField" according to the Class of the instance. There will be no
>>> need to change the value again, so it can be set statically or on
>>> initialization time. I just do not know how to assign static or
>>> default values in a subclass to a field that is modeled in the
>>> superclass.
>>>
>>> I hope it is getting clearer :)
>>
>> I just saw that my image is wrong. The superclass of Date should be
>> DialogElement.
>
Re: specialization [message #714774 is a reply to message #714769] Thu, 11 August 2011 13:11 Go to previous messageGo to next message
Daniel Winkels is currently offline Daniel WinkelsFriend
Messages: 19
Registered: October 2010
Junior Member
So,

this is my solution in DialogElement:

public String getType() {
return this.eClass().getName() + "Field";
}

I just was hoping for an annotation that gives me the opportunity to set
the value of each subclass individually. So if anybody knows a way, i am
still interested, but so far this solves my problem for the near future
(at least i hope)

So, thank you!

Daniel

Am 11.08.11 14:42, schrieb Hallvard Trætteberg:
> I don't think you can override the default value. What you could do is
> to model it as a derived feature and implement the corresponding get
> method in the subclass' implementation. That way the values may differ
> and you still access it as a "normal" attribute.
>
> hallvard
>
> On 11.08.11 14.36, Daniel Winkels wrote:
>> Am 11.08.11 14:18, schrieb Daniel Winkels:
>>> Hello Ed,
>>>
>>> i assumed that the question is somehow unclear. I uploaded an image
>>> with a small example of what i am intending to do.
>>> I just explain it:
>>>
>>> "DialogElement" is the abstract common base of "File" and "Date".
>>> There will be no instance of "DialogElement" but of its children. All
>>> I want to do is set the field "type" = "DateField" or "type" =
>>> "FileField" according to the Class of the instance. There will be no
>>> need to change the value again, so it can be set statically or on
>>> initialization time. I just do not know how to assign static or
>>> default values in a subclass to a field that is modeled in the
>>> superclass.
>>>
>>> I hope it is getting clearer :)
>>
>> I just saw that my image is wrong. The superclass of Date should be
>> DialogElement.
>
Re: specialization [message #714787 is a reply to message #714774] Thu, 11 August 2011 13:56 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
You could try this:

this.eClass().getEAnnotation("TypeElement").getDetails().get("type")


where TypeElement is the EAnnotation attached to your sub-classes and "type" being the detail value...
Re: specialization [message #714802 is a reply to message #714787] Thu, 11 August 2011 14:03 Go to previous message
Daniel Winkels is currently offline Daniel WinkelsFriend
Messages: 19
Registered: October 2010
Junior Member
This looks very good. I'll try it (and i think this will have the effect
i was looking for)

Thank you

Am 11.08.11 15:56, schrieb Erdal Karaca:
> You could try this:
>
> this.eClass().getEAnnotation("TypeElement").getDetails().get("type")
>
> where TypeElement is the EAnnotation attached to your sub-classes and
> "type" being the detail value...
Previous Topic:[xcore] some problems and fixes
Next Topic:(no subject)
Goto Forum:
  


Current Time: Tue Apr 23 15:12:20 GMT 2024

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

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

Back to the top