Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to interact with metamodel.ecore and Model.xmi elements in one template
How to interact with metamodel.ecore and Model.xmi elements in one template [message #975014] Wed, 07 November 2012 09:26 Go to next message
Adnan AL-SOSWA is currently offline Adnan AL-SOSWA
Messages: 41
Registered: May 2010
Member
Hello all ,
I have question concerning xpand , I have create a metamodel with the some eclasses , attributes and references . after that I create a dynamic instance of the metamodel to generate Model.xmi and I built the model.xmi according to the structure of the metamodel.My question how I can combine between the elements of the Metamodel and the Model.xmi in one template file .

Ex . I have eclass called Entity in my metamodel
and I have created three Entities Students, lectures, Lecturers in my Model.xmi
I want to generate with xpand somthing like
Entity (no , Students)
Entity (no , lectures)
Entity (no , Lecturers)
and this should be automatically , i tried some code here
«DEFINE main FOR ecore::EPackage»
«FILE name+".txt"»
«EXPAND classifier FOREACH eClassifiers.typeSelect(ecore::EClass) »
«ENDFILE»
«ENDDEFINE»

«DEFINE classifier FOR ecore::EClass»  
  «name» (#no ,«EXPAND class FOREACH name »
  «ENDDEFINE»
 «DEFINE class FOR  name »
 «name»
 «ENDDEFINE»


I have a mistake in the second xpand statment that name is not collection , but how a can get all the entities that I defined ?
Re: How to interact with metamodel.ecore and Model.xmi elements in one template [message #976275 is a reply to message #975014] Thu, 08 November 2012 07:56 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

I guess you are mixing things. The Xpand definitions would not be declared for Ecore, but for concepts of your metamodel, here: Entity.

«DEFINE main FOR MyModel»
«FILE name+".txt"»
«EXPAND classifier FOREACH eAllContents.typeSelect(Entity) »
«ENDFILE»
«ENDDEFINE»

«DEFINE classifier FOR mymetamodelpackage::Entity»  
  «name»
  «ENDDEFINE»



"name" is a single-valued attribute. FOREACH expects a collection.

Install the Xpand sample project (File / New / Xpand Project) and look as reference there.

Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de

[Updated on: Thu, 08 November 2012 08:01]

Report message to a moderator

Re: How to interact with metamodel.ecore and Model.xmi elements in one template [message #977758 is a reply to message #976275] Fri, 09 November 2012 09:52 Go to previous message
Adnan AL-SOSWA is currently offline Adnan AL-SOSWA
Messages: 41
Registered: May 2010
Member
Hi Karsten


thanks a lot but I think you did not get what I want to do Smile
I need everything to be atutomatic for any metamodel,and Entity was only example , I actually I do not know what is the metamodel structure and the model.xmi ,and I want to extract all the eclasses in my metamodel . it means I can not type specific eclass in my defin template as I want all of them
«DEFINE main FOR ecore::EPackage»
«FILE name+".txt"»
«EXPAND classifier FOREACH eClassifiers.typeSelect(ecore::EClass) »
«ENDFILE»
«ENDDEFINE»

«DEFINE classifier FOR ecore::EClass»  // here I will get all the eclasses in m my metamodel as it is defined in the generator   
«name»(no ,«EXPAND classifier FOREACH eAllContents.typeSelect(name)»)// this your code but I have mistake as eAllContents is not in the ecore::EClass
«ENDDEFINE»

«DEFINE classifier FOR metamodel::name»  
  «name»
  «ENDDEFINE»


I need output for any metamodel
for example for xpand example metamodel the output will be

Entity (no , Person)
Entity (no ,address)
Datatype(no, string)
Datatype(no,Integer)
Previous Topic:[Acceleo] Dynamic overriding
Next Topic:[Xpand]
Goto Forum:
  


Current Time: Wed Apr 16 00:54:14 EDT 2014

Powered by FUDForum. Page generated in 0.02085 seconds