Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EAnnotation usage in ecore
EAnnotation usage in ecore [message #1694795] Fri, 08 May 2015 00:13 Go to next message
Hamid Qartal is currently offline Hamid QartalFriend
Messages: 33
Registered: December 2013
Member
I am exploring emf framework, so excuse me for this novice question.

Can anybody explain the usage of EAnnotation in ecore, in terms of its specific fields (i.e., Source, Details, EModel Element, Contents, and References). I looked at its API documentation here, but could not get that much from there.

I am looking for a kind of guideline that explains by example what are the purpose of having annotations with such fields in ecore.

I asked this question here, but it seems there are less people of EMF in stackoverflow.

Thanks
Re: EAnnotation usage in ecore [message #1694806 is a reply to message #1694795] Fri, 08 May 2015 04:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Hamid,

Comments below.

On 08/05/2015 2:13 AM, Hamid Qartal wrote:
> I am exploring emf framework, so excuse me for this novice question.
>
> Can anybody explain the usage of EAnnotation in ecore, in terms of its
> specific fields (i.e., Source,
This should typically be a URI and helps identify/describe the purpose
of the annotation and is useful for looking it up using
org.eclipse.emf.ecore.util.EcoreUtil.getAnnotation(EModelElement,
String, String).
> Details,
These are key/value pairs. One generally hopes that all the additional
information you need to associate with the model can be represented in
this way exclusively and again, the above utility is useful for looking
things up...
> EModel Element,
An EAnnotation is an EModelElement, so can also be annotated. It's not
often used, but would allow you to build a complex structure...
> Contents,
EAnnotations can contain arbitrary other objects. This is also not
often used, and if you do use it, you can't generate a normal
XyzPackageImpl but must ensure that the GenPackage specifies "Initialize
by Loading"...
> and References).
EAnnotations can refer to arbitrary other objects. This is also not
often used, and the same caveat applies and for the contents...
> I looked at its API documentation
> http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.2/org/eclipse/emf/ecore/EAnnotation.html#getReferences%28%29,
> but could not get that much from there.
> I am looking for a kind of guideline that explains by example what are
> the purpose of having annotations with such fields in ecore.
>
> I asked this question
> http://stackoverflow.com/questions/30112555/eannotation-usage-in-ecore, but
> it seems there are less people of EMF in stackoverflow.
Yes, I don't generally monitor that forum...
>
> Thanks


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EAnnotation usage in ecore [message #1694809 is a reply to message #1694795] Fri, 08 May 2015 07:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

On 08/05/2015 01:13, Hamid Qartal wrote:
> I am looking for a kind of guideline that explains by example what are
> the purpose of having annotations with such fields in ecore.
Within Ecore the main usage of EAnnotations is for extended modeling
that influences Java code generation or XSD serialization.

The simplest is
"http://www.eclipse.org/emf/2002/GenModel"::documentation. It supports a
documentation comment that can appear in hover text and Java comments.

The most powerful is
"http://www.eclipse.org/emf/2002/Ecore"::invocationDelegates/settingDelegates/validationDelegates"
that enables executable behavior to be defined for operation
bodies/property initialization/invariants. Related annotations such as
"http://www.eclipse.org/emf/2002/Ecore/OCL" provide OCL-based executable
behavior.

The most extensive is "http://www.eclipse.org/uml2/2.0.0/UML" that
supports a representation of many of the important UML aspects such as
Stereotypes that are not adequately captured by Ecore.

So perhaps the strongest guideline is that the source name should have a
URL style prefix to clearly identify the project that takes
responsibility for defining the detailed semantics.

Regards

Ed Willink
Re: EAnnotation usage in ecore [message #1770264 is a reply to message #1694806] Wed, 09 August 2017 13:37 Go to previous messageGo to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 40
Registered: May 2012
Member
Hello,

Ed Merks wrote on Fri, 08 May 2015 00:52

On 08/05/2015 2:13 AM, Hamid Qartal wrote:
> [...]
> Contents,
EAnnotations can contain arbitrary other objects. This is also not
often used, and if you do use it, you can't generate a normal
XyzPackageImpl but must ensure that the GenPackage specifies "Initialize
by Loading"...


I have a complex structure (Class) that is supposed to bring more characterization to each Association (Reference/Composition) defined between Classes in my ecore metamodel. I tought I could use the References attribute of EAnnotation for this purpose.

Let's say that A is the Class that "enrich" any association in my metamodel with additional data. Then I have Classes P and Q that represent concepts in my metamodel. I can define a Reference qs that goes from P to Q to indicate that P references (many) Q(s). In addition, I define an EAnnotation in qs so that I can use its References attribute to refer the instance of A that is going to characterize qs at level M1.

Ideally I would like to express a kind of "derived Reference" in the EAnnotation. Indeed, my business model logic at M1 is such that, in principle, I could express the "derivation rule" in OCL, so that the qs' EAnnotation References attribute is automatically filled with the proper instance of A that characterize qs.

Is it possible to achieve this with direct OCL expressions in the ecore metamodel, or am I supposed to customize the generated editor to get the desired behavior?

And by the way, can you explain what is the purpose of enabling "Initialize
by Loading" in GenPackage? What is it useful for?

Thanks.
--
Matteo
Re: EAnnotation usage in ecore [message #1770278 is a reply to message #1770264] Wed, 09 August 2017 15:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You should be able to use OCLinEcore to define your derived features. Optionally you can use the OCL2Java code generator to get faster execution.

Initialize by loading is essential for huge metamodels such as UML that would otherwise hit 64k byte limit problems. Not usually appropriate until you have a problem.

Regards

Ed Willink
Re: EAnnotation usage in ecore [message #1770289 is a reply to message #1770278] Wed, 09 August 2017 16:27 Go to previous messageGo to next message
Matteo M. is currently offline Matteo M.Friend
Messages: 40
Registered: May 2012
Member
Thanks Ed for your reply.

Ed Willink wrote on Wed, 09 August 2017 11:07

You should be able to use OCLinEcore to define your derived features. Optionally you can use the OCL2Java code generator to get faster execution.


Infact I cannot achieve what I want, apparently. I tried to process my model instance with QVTo to just be sure that what I wanted was feasible and it seems to me that I'm not allowed to save instance values in EAnnotations.

More specifically, (i) I've created a model with instances A1, P1 and Q1. Then, (ii) I assigned Q1 to P1.qs and (iii) I processed the model (as inout) with a small QVTo script to add A1 as references in the EAnnotation of qs. These are the commands that I've used:
// p1 and a1 are the variables that make the P1 and A1 instances accessible
var r_qs := p1.oclAsType(EObject).eClass().eReferences![name = "qs"];
var ea_qs  := r_qs.eAnnotations![source = "my_qs_EAnn_Uri"];
ea_qs._references += a1.oclAsType(EObject);


I had to cast a1 to ecore::EObject and now, once I process again the model e.g., with my QVTo script, only the metamodel attributes of A are accessible (not of its instance A1). Is there a way to refer A1 (the instance) in the EAnnotation of P1.qs (that has been defined at metamodel level)?

Thanks.
--
Matteo
Re: EAnnotation usage in ecore [message #1770300 is a reply to message #1770289] Wed, 09 August 2017 18:51 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Use of EObject has been troublesome since EMF (correctly) removed automatic modeled inheritance at Helios M4. It is therefore very difficult to comment sensibly without a repro.

Regards

Ed Willink
Previous Topic:Update map using EditingDomain
Next Topic:EObject does not send Notification.SET
Goto Forum:
  


Current Time: Thu Apr 25 00:18:33 GMT 2024

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

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

Back to the top