Book a Demo

Author Topic: Code Template: Iterate over Tagged Value  (Read 3501 times)

b1256

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Code Template: Iterate over Tagged Value
« on: May 03, 2013, 09:30:53 pm »
Hello,

is it possible to iterate in a code template over all tagged values of the same name? Or perhaps iterate over a comma seperated list of values in one tagged value?

Thanks.
Bernhard

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Re: Code Template: Iterate over Tagged Value
« Reply #1 on: May 05, 2013, 04:12:23 pm »
I created a template that parses key/value pairs (and one to create them). It uses the Function macros like FIND, LEFT, MID, and TRIM to locate the comma, get the part before the comma, get the remainder and remove the comma. The pair gets used to generate some text and then the template calls itself with the remaining list. I'll post it Monday, if I remember.

Cheers,
Dan

b1256

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Code Template: Iterate over Tagged Value
« Reply #2 on: May 07, 2013, 12:17:09 am »
Thanks for the idea, I was able to implement it as you suggested.  8-)

$PREFIX_MESSAGE="message"
$throwsList=$parameter1
$splitChar=","
$pos=%FIND($throwsList, $splitChar)%
%if $pos == "-1"%
$throws=$throwsList
$throwsRest=""
%else%
$throws=%LEFT($throwsList, $pos)%
$trimlen=%MATH_ADD($pos, "1")%
$throwsRest=%MID($throwsList, $trimlen)%
%endIf%
$faultName=%opName%+$throws+"Fault"
$faultMessageName=%opName%+$throws+"FaultMessage"
<wsdl:message name='$faultMessageName'>
<wsdl:part name='fault' element='$PREFIX_MESSAGE:$faultName'/>
</wsdl:message>
%if $throwsRest != ""%
%Operation__MessageThrowsRecursive($throwsRest)%
%endIf%

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Re: Code Template: Iterate over Tagged Value
« Reply #3 on: May 07, 2013, 07:49:52 am »
Cool. I didn't know about MATH_*(). Here is my snippet:

Code: [Select]
$COMMENT=" Pull the first attribute, type pair from the   "
$COMMENT=" list and create an attribute for it. Prune     "
$COMMENT=" the list and recurse until list is empty. The  "
$COMMENT=" list format is: {<name>,<type>}*               "
$COMMENT=""
$COMMENT=" First, assign useful names to the parameters   "
$class   =$parameter1
$keys    =$parameter2
$isKey   =$parameter3
%if $keys == ""%
%endTemplate%
$COMMENT=""
$COMMENT=               "* Get the first name in the list "
$sep=%FIND($keys, ",")%
$name=%LEFT($keys, $sep)%
$name=%TRIM($name)%
$COMMENT=""
$COMMENT=               "* Cut the name from the list     "
$next=%MID($keys, $sep)%
$next=%TRIM_LEFT($next, ",")%
$sep=%FIND($next, ",")%
$COMMENT=""
$COMMENT=               "* Get the type of this attribute "
%if $sep != "-1"%
$type=%LEFT($next, $sep)%
$COMMENT=               "*   Cut the type from the list   "
$remaining=%MID($next, $sep)%
$remaining=%TRIM_LEFT($remaining, ",")%
%else%
$type=$next
$remaining=""
%endIf%
$type=%TRIM($type)%
Attribute
{
  name="$class$name"
  type=%qt%%CONVERT_TYPE("IDL", $type)%%qt%
%if $isKey == "T"%
  stereotype="key"
%endIf%
}

%AddAttribute($class, $remaining, $xumlTag)%

No error checking because when things go wrong, they go terribly wrong...  ;)