Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Ecore Annotation as the operation body
Ecore Annotation as the operation body [message #406042] Fri, 22 December 2006 10:46 Go to next message
A. Jibran Shidqie is currently offline A. Jibran Shidqie
Messages: 26
Registered: July 2009
Junior Member
Hi,

I'd like to generate the operation body using EMF model. Is there anyone who
has the experience in using Ecore Annotation as the body of the operation.
What I mean is the body of the operation is generated by some tools and
wrapped as String, then put the string as the Ecore annotation of its
EOperation, then let the EMF codegen generates the model code. And by
modifying the JET templates, those String will be generated as the
corresponding operation body.

What would be the correct thing to do? Is there any problem using that way?

Best regards,
Jibran
Re: Ecore Annotation as the operation body [message #406043 is a reply to message #406042] Fri, 22 December 2006 11:20 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26000
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070207020603040708010104
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jibran,

The generator supports this without modifying the templates because
GenOperationImpl has this in it:

protected String getBody()
{
EOperation eOperation = getEcoreOperation();
EAnnotation eAnnotation =
eOperation.getEAnnotation(*GenModelPackage.eNS_URI*);
return eAnnotation == null ? null :
(String)eAnnotation.getDetails().get("*body*");
}

Here's an example from SDO.ecore:

<eClassifiers xsi:type="ecore:EClass" name="EDataObject"
eSuperTypes="../../org.eclipse.emf.ecore/model/Ecore.ecore#//EObject
#//DataObject">
<eOperations name="getInstanceProperties" eType="#//EJavaList">
<eAnnotations source="*http://www.eclipse.org/emf/2002/GenModel*">
<details key="*body*" value="return
&lt;%org.eclipse.emf.ecore.sdo.util.SDOUtil%>.getInstanceProperties(this); "/>
</eAnnotations>
</eOperations>
</eClassifiers>

The <%...%> marks things that will be imported so the above produces
this in EDataObjectImpl:

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public List getInstanceProperties()
{
return SDOUtil.getInstanceProperties(this);
}

Note that the method is fully @generated and was not hand changed.

So you can use this same technique in any Ecore model...


A. Jibran Shidqie wrote:
> Hi,
>
> I'd like to generate the operation body using EMF model. Is there anyone who
> has the experience in using Ecore Annotation as the body of the operation.
> What I mean is the body of the operation is generated by some tools and
> wrapped as String, then put the string as the Ecore annotation of its
> EOperation, then let the EMF codegen generates the model code. And by
> modifying the JET templates, those String will be generated as the
> corresponding operation body.
>
> What would be the correct thing to do? Is there any problem using that way?
>
> Best regards,
> Jibran
>
>
>


--------------070207020603040708010104
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jibran,<br>
<br>
The generator supports this without modifying the templates because
GenOperationImpl has this in it:<br>
<blockquote>&nbsp; protected String getBody()<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; EOperation eOperation = getEcoreOperation();<br>
&nbsp;&nbsp;&nbsp; EAnnotation eAnnotation = eOperation.getEAnnotation(<b>GenModelPackage.eNS_URI</b>); <br>
&nbsp;&nbsp;&nbsp; return eAnnotation == null ? null :
(String)eAnnotation.getDetails().get("<b>body</b>");<br >
&nbsp; }<br>
</blockquote>
Here's an example from SDO.ecore:<br>
<blockquote>&nbsp; &lt;eClassifiers xsi:type="ecore:EClass"
name="EDataObject"
eSuperTypes="../../org.eclipse.emf.ecore/model/Ecore.ecore#//EObject
#//DataObject"&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;eOperations name="getInstanceProperties"
eType="#//EJavaList"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;eAnnotations source="<b><a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2002/GenModel">http://www.eclipse.org/emf/2002/GenModel</a></b>"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;details key="<b>body</b>" value="return
&amp;lt;%org.eclipse.emf.ecore.sdo.util.<font color="#3333ff">SDOUtil</font>%&gt;.getInstanceProperties(this); "/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/eOperations&gt;<br>
&nbsp; &lt;/eClassifiers&gt;<br>
</blockquote>
The &lt;%...%&gt; marks things that will be imported so the above
produces this in EDataObjectImpl:<br>
<blockquote>&nbsp; /**<br>
&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;<br>
&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;<br>
&nbsp;&nbsp; * @generated<br>
&nbsp;&nbsp; */<br>
&nbsp; public List getInstanceProperties()<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; return <font color="#3333ff">SDOUtil</font>.getInstanceProperties(this); <br>
&nbsp; }<br>
</blockquote>
Note that the method is fully @generated and was not hand changed.<br>
<br>
So you can use this same technique in any Ecore model...<br>
<br>
<br>
A. Jibran Shidqie wrote:
<blockquote cite="midemgukt$4l1$1@utils.eclipse.org" type="cite">
<pre wrap="">Hi,

I'd like to generate the operation body using EMF model. Is there anyone who
has the experience in using Ecore Annotation as the body of the operation.
What I mean is the body of the operation is generated by some tools and
wrapped as String, then put the string as the Ecore annotation of its
EOperation, then let the EMF codegen generates the model code. And by
modifying the JET templates, those String will be generated as the
corresponding operation body.

What would be the correct thing to do? Is there any problem using that way?

Best regards,
Jibran


</pre>
</blockquote>
<br>
</body>
</html>

--------------070207020603040708010104--
Previous Topic:[Announce] EMF 2.3.0M4 is available
Next Topic:Generated vs. Reflective ItemProviders
Goto Forum:
  


Current Time: Fri Aug 22 15:39:59 EDT 2014

Powered by FUDForum. Page generated in 0.02841 seconds