Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » EMF + Texo + Xpand2(Access ecore model annotations in custom texo template)
EMF + Texo + Xpand2 [message #972126] Mon, 05 November 2012 11:26 Go to next message
Pradeep Badiger is currently offline Pradeep Badiger
Messages: 53
Registered: November 2012
Member
Hi,

I am new to Texo and want to generate JPA code with custom annotations on conditions for which i need to read metadata information in ecore model.

what is the correct way to access ecore model annotations in a template file?

thanks,
Pradeep V.B.

Re: EMF + Texo + Xpand2 [message #972363 is a reply to message #972126] Mon, 05 November 2012 15:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Pradeep,
This page gives an idea on how to add/use your own custom templates:
http://wiki.eclipse.org/Texo/Template_Overriding

The page also has links to example templates. Some of them are quite complex because of support for featuremaps and
such, in general more specific templates are much simpler.

gr. Martin

On 11/05/2012 02:36 PM, Pradeep Badiger wrote:

> Hi,
>
> I am new to Texo and want to generate JPA code with custom annotations on conditions for which i need to read metadata
> information in ecore model.
>
> what is the correct way to access ecore model annotations in a template file?
>
> thanks,
> Pradeep V.B.
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: EMF + Texo + Xpand2 [message #973183 is a reply to message #972363] Tue, 06 November 2012 06:04 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep Badiger
Messages: 53
Registered: November 2012
Member
Hi Martin,

Thanks for your reply. I was able to add my own template and generate the code. But i need to access custom annotations in my template file.

index.php/fa/12203/0/index.php/fa/12204/0/

How can i achieve this?

thanks,
Pradeep B
Re: EMF + Texo + Xpand2 [message #973188 is a reply to message #973183] Tue, 06 November 2012 06:08 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Pradeep,
How are these annotations stored, in eannotations?

btw, I saw the code you generated in the snippet image, in the templates I always use fully qualified names, texo will
take care of import resolving.

gr. Martin

On 11/06/2012 07:04 AM, Pradeep Badiger wrote:
> Hi Martin,
>
> Thanks for your reply. I was able to add my own template and generate the code. But i need to access custom annotations in my template file.
>
>
>
> How can i achieve this?
>
> thanks,
> Pradeep B
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: EMF + Texo + Xpand2 [message #974538 is a reply to message #973188] Wed, 07 November 2012 06:08 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep Badiger
Messages: 53
Registered: November 2012
Member
Hi Martin,

Yes the metadata required are added as EAnnotations in the model. I need to use this metadata as conditional fields in the overridden template to generate additional code in the generated code.

I was using JET templates earlier which had access to metadata defined on the models which allowed me to control the code generation. I was hoping the same when using the Xpand language and Texo.

thanks,
Pradeep V.B.

Re: EMF + Texo + Xpand2 [message #974652 is a reply to message #974538] Wed, 07 November 2012 08:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Pradeep,
You can extend/override the texo templates using XPand. The git location shows several examples of xpand templates:
http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/generator/org.eclipse.emf.texo.modelgenerator/src/org/eclipse/emf/texo/modelgenerator/templates/

For examples the addition.xpt (see below). Within the define you have access to the ModelGenAnnotation instance (for
EClass, EPackage etc). From the ModelGenAnnotation instance you can find the underlying modelelement as a property, for
example eClass, ePackage etc.

«REM»Template file which can be overridden to generate additional files or code«ENDREM»
«IMPORT org::eclipse::emf::texo::modelgenerator::modelannotations»
«IMPORT org::eclipse::emf::texo::generator»

«REM»Called for EPackages, even if you don't want to generate code for EPackages, still keep this empty DEFINE«ENDREM»
«DEFINE root(ModelController modelController) FOR EPackageModelGenAnnotation-»
«ENDDEFINE»

«REM»Called for EClasses, even if you don't want to generate code for EClasses, still keep this empty DEFINE«ENDREM»
«DEFINE root(ModelController modelController) FOR EClassModelGenAnnotation-»
«ENDDEFINE»

«REM»Called for EEnums, even if you don't want to generate code for EEnums, still keep this empty DEFINE«ENDREM»
«DEFINE root(ModelController modelController) FOR EEnumModelGenAnnotation-»
«ENDDEFINE»



gr. Martin

On 11/07/2012 07:08 AM, Pradeep Badiger wrote:
> Hi Martin,
>
> Yes the metadata required are added as EAnnotations in the model. I need to use this metadata as conditional fields in
> the overridden template to generate additional code in the generated code.
> I was using JET templates earlier which had access to metadata defined on the models which allowed me to control the
> code generation. I was hoping the same when using the Xpand language and Texo.
>
> thanks,
> Pradeep V.B.
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: EMF + Texo + Xpand2 [message #976026 is a reply to message #974652] Thu, 08 November 2012 08:58 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep Badiger
Messages: 53
Registered: November 2012
Member
Thanks Martin, I will give a try.

regards,
Pradeep V.B.
Re: EMF + Texo + Xpand2 [message #991053 is a reply to message #976026] Mon, 17 December 2012 08:38 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep Badiger
Messages: 53
Registered: November 2012
Member
Hi Martin, I am trying to override addtions.xpt and generate a file for every EClass in emf file. I need a different package and class name for the new file. How do i override that. I am not able to generate it in a different package. A new file is getting generated in with the same name as that of EClass.

Thanks,
Pradeep V.B.
Re: EMF + Texo + Xpand2 [message #991871 is a reply to message #991053] Thu, 20 December 2012 11:37 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5332
Registered: July 2009
Senior Member
Hi Pradeep,
Sorry missed your post. The file is generated using this directive:
«FILE classFileName(this) java-»

(as an example), so you can determine the filename yourselve.
In the above example the filename is created using this utility:
String classFileName( EClassifierModelGenAnnotation this ): qualifiedClassName.replaceAll("\\.","/") + ".java";

Let me know if you have additional questions.

gr. Martin

On 12/17/2012 09:39 AM, Pradeep Badiger wrote:
> Hi Martin, I am trying to override addtions.xpt and generate a file for every EClass in emf file. I need a different
> package and class name for the new file. How do i override that. I am not able to generate it in a different package. A
> new file is getting generated in with the same name as that of EClass.
>
> Thanks,
> Pradeep V.B.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:Multi Java Annotations in the model
Next Topic:[Texo] Example for creating orm.xml from ecore model programmatically
Goto Forum:
  


Current Time: Sat Sep 20 06:08:15 GMT 2014

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

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