Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » passing parameters from one block to another
passing parameters from one block to another [message #652526] Fri, 04 February 2011 12:07 Go to next message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
hi

i am working on mdsd. i am xpand for code generation and gmf for graph editor. i some how managed to generate code from gmf graph. i have a problem with code generation

my ecore file looks like this
TestCase -------main class contains
/ \
/ \
blocks links
/ | \
/ | \
start make end blocks



now in my xpand template

«DEFINE main FOR TestCase»
«FILE name +".mist"»

«EXPAND blk FOREACH blockRef SEPARATOR '#########################'» //this call all the blocks one by one

«ENDFILE»
«ENDDEFINE»

now i want to pass some parameters of start block to make block. how do i approach this?
Re: passing parameters from one block to another [message #652529 is a reply to message #652526] Fri, 04 February 2011 12:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello Ravi,

without knowing you actual metamodel (the following is unreadable to me)

Quote:

TestCase -------main class contains
/ \
/ \
blocks links
/ | \
/ | \
start make end blocks


it is hard to give concrete advice.

but

(1) you can pass additional parameters to templates
(2) you can naivigate the model up and down
(3) you can do sorting / filterting etc.

With some more information (metamodel/model) it can give more advice.

~Christian



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: passing parameters from one block to another [message #652531 is a reply to message #652526] Fri, 04 February 2011 12:38 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hi,

you can pass parameters to Define blocks:
«DEFINE main FOR TestCase»
«FILE name +".mist"»

«EXPAND blk('#########################') FOREACH blockRef» 

«ENDFILE»
«ENDDEFINE»

«DEFINE blk(String param) FOR TestCase»
to something with param «param»
«ENDDEFINE»


Take a look at the Xpand documentation.
Xpand Documentation > I. Reference > Xpand / Xtend / Check Reference > Xpand > Define
Re: passing parameters from one block to another [message #652563 is a reply to message #652531] Fri, 04 February 2011 14:37 Go to previous messageGo to next message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
Hi chris

thanks once again for replying

if i pass parameters like that in expand
i will have to define parameters for all the blocks unnecessarily.



plz find

my whole template code

------------------------------------------------------------


«IMPORT mist»
«DEFINE main FOR TestCase»
«FILE name +".mist"»

«REM»
«FOREACH linkRef AS lk»
«IF lk.sourceBlock.name=="start"»
hhhhhhh
«ENDIF»
«ENDFOREACH»
«FOREACH blockRef AS blocks»
«blocks.name»
«ENDFOREACH»
«ENDREM»

«EXPAND blk FOREACH blockRef SEPARATOR '#########################'»
«ENDFILE»
«ENDDEFINE»

«DEFINE blk FOR block»
#could not find the matching block for this call
«ENDDEFINE»

«DEFINE blk FOR StartBlock»
#********************
#** MIST-IP-PHONES:

ipphone(«dn1»)
ipphone(«dn2»)

#********************

repeat(100)
OpenServer(«servername»,«Sipport»,«applicationname»)
WaitTevent(NULL,1000,LinkConnected)
if(LAST>=0) leave
again


ipRegister(«dn1»,«servername»:«Tlibport»)
ipRegister(«dn2»,«servername»:«Tlibport»)


#********************
#** MIST-REGISTRATION:

RegisterAddress(abstract)
ExpectTevent(abstract, WaitTime, Registered)

RegisterAddress(«dn1»)
ExpectTevent(«dn1», WaitTime, Registered)

RegisterAddress(«dn2»)
ExpectTevent(«dn2», WaitTime, Registered)

«IF this.Dn1type.toString().startsWith("Extension") && this.Dn2type.toString().startsWith("Extension")»
Utc3pccMakeCallInternal(«dn1»,«dn2»,"RETURN_AFTER_ESTABLISHED ")
«ELSEIF this.Dn1type.toString().startsWith("Extension") && this.Dn2type.toString().startsWith("Trunk") »
Utc3pccMakeCallOutbound(«dn1»,«dn2»,"RETURN_AFTER_ESTABLISHED ")
«ELSEIF this.Dn1type.toString().startsWith("Extension") && this.Dn2type.toString().startsWith("TrunkGroup")»
UtcMakeCallLocaToExtTg(«dn1»,«dn2»)
«ELSEIF this.Dn1type.toString().startsWith("Extension") && this.Dn2type.toString().startsWith("RoutingPoint")»
UtcMakeCallLocToRp(«dn1»,«dn2»)
«ENDIF»
«ENDDEFINE»


«DEFINE blk FOR MakeCallBlock»
«StartBlock.getProperty("dn1")»
some make call code.........
«ENDDEFINE»


«DEFINE blk FOR EndBlock»
#exit
exit(expect_error)
teardown:
putln(result,"*** TEARDOWN ***")
exit(-1)
«ENDDEFINE»

«DEFINE lnk FOR link»
this a link from «sourceBlock.name» to «destinationBlock.name»
«ENDDEFINE»







-----------------------------------------------------



now i want to use the dn1type and dn2type parameter of startblock in makecall block



please find my ecore file


------------------------------------------------------------ -------------


<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mist"
nsURI="http://mist.ecore" nsPrefix="mist">
<eClassifiers xsi:type="ecore:EClass" name="TestCase">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="blockRef" upperBound="-1"
eType="#//block" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="linkRef" upperBound="-1"
eType="#//link" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="block" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="link">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="sourceBlock" eType="#//block"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="destinationBlock" eType="#//block"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="StartBlock" eSuperTypes="#//block">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
defaultValueLiteral="0"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Dn1type" eType="#//DNTypes"
defaultValueLiteral=""/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="servername" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="host"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Sipport" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="Sipport"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="applicationname" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="app"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="dn1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="dn1"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="dn2" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Tlibport" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="Tlibport"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Dn2type" eType="#//DNTypes"
defaultValueLiteral=""/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EndBlock" eSuperTypes="#//block">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
defaultValueLiteral="3"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="MakeCallBlock" eSuperTypes="#//block">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
defaultValueLiteral="2"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="DN1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="dn1"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="DN2" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="dn2"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="DNTypes">
<eLiterals name="ACDQueue"/>
<eLiterals name="Extension" value="1"/>
<eLiterals name="RoutingQueue" value="2"/>
<eLiterals name="Trunk" value="3"/>
<eLiterals name="TrunkGroup" value="4"/>
<eLiterals name="VirtualQueue" value="6"/>
<eLiterals name="VoiceoverIpService" value="7"/>
<eLiterals name="VoiceTreatmentPort" value="8"/>
</eClassifiers>
</ecore:EPackage>


------------------------------------------------------------ --------------



Thanks for your patience






























Re: passing parameters from one block to another [message #652569 is a reply to message #652563] Fri, 04 February 2011 15:11 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hi,

do you want something like this?
«DEFINE blk FOR MakeCallBlock»
«getTestCase().getStartBlock().Dn2type»
some make call code.........
«ENDDEFINE»


Then you have to import an Extension in your template
«IMPORT mist»
«EXTENSION template::Extensions»


The extensionfile
Extension.ext:
import mist;

TestCase getTestCase(block block):
	block.eContainer;

getStartBlock(TestCase tc):
	tc.blockRef.typeSelect(StartBlock).first();
icon14.gif  Re: passing parameters from one block to another [message #652606 is a reply to message #652569] Fri, 04 February 2011 17:04 Go to previous messageGo to next message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
Hi Jockel

Thank you so much for replying.

i will just try it out and reply soon


Regards
Ravi Very Happy
icon14.gif  Re: passing parameters from one block to another [message #652619 is a reply to message #652606] Fri, 04 February 2011 18:01 Go to previous messageGo to next message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
Very Happy


Hi Darius Jockel

your solution worked super fine Very Happy


Thank you so much.

i have one more question. as you see my ecore model.

i have blocks and they are connected by links. when i generate code i am not able to generate code based on the flow.
it's based on the creation order of the elements in gmf

in my ecore
a link class has reference to source block and destination block. but blocks doesn't have any ref to links

any pointer as to how i can generate based on the flow
for instance
gmf editor :start--->make---->end

respective block should be called in xpand

i suspect i have to redesign my metamodel file with a linkRef!!! but how i can proceed ?

or should i go about with something like extension



Regards
Ravi


Re: passing parameters from one block to another [message #652630 is a reply to message #652619] Fri, 04 February 2011 18:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

same as before: use xtend to navigate on the model

import mist;

List[block] getSuccessors(block in) :
	((TestCase)in.eContainer).linkRef.select(e|e.sourceBlock == in).destinationBlock;


maybe you should start with the startblock(s) in the testcase
«DEFINE main FOR TestCase»
...
«EXPAND handleStartBlock FOREACH blockRef.typeSelect(StartBlock)»
...
«ENDDEFINE»


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: passing parameters from one block to another [message #652675 is a reply to message #652630] Sat, 05 February 2011 07:26 Go to previous message
Ravi Kiran is currently offline Ravi KiranFriend
Messages: 41
Registered: December 2010
Member
Hi chris

Thanks for responding. it worked very well



Regards
Ravi
Previous Topic:comboboxcelleditor not firing
Next Topic:[Xtend/XPand] Strange behaviour of checks
Goto Forum:
  


Current Time: Sat Apr 20 03:01:12 GMT 2024

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

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

Back to the top