Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET2] Customizing an iterate sentence
[JET2] Customizing an iterate sentence [message #33941] Mon, 17 September 2007 22:01 Go to next message
Joaquin  Cañadas is currently offline Joaquin CañadasFriend
Messages: 25
Registered: July 2009
Junior Member
Hello,
it is possible to execute the body of an iterate sentence only for some
elements of the collection?.
For example, the following input model contain 4 classes:

<Package name="AssessmentSchema">
<classes name="Residence" />
<classes name="Applicant" />
<classes name="ResidenceCriterion" />
<classes name="ResidenceDecision" />
</Package>


My main.jet template contain the following code:

<c:iterate select="$curPackage/classes" var="curBean">
<java:class
name="{$curBean/@name}Bean"
template="templates/JavaBean2JavaCode.jet" />
</c:iterate>

The body of the iterate sentence is applied to the 4 classes that
appear in the input model. However, I would like to apply the body only
to 2 of those classes, providing for example a configuration file
including the list of classes to apply the template:

Residence
Applicant

How can I implement that kind of transformation?

One solution would be adding a new attribute to the input model,
allowing the selection of the classes. However, the decision of
selecting or not a class is a "design decision", and it would not be
adequate to change the input model (and metamodel)... At least I think so...

Thank you in advance.
Joaquin
Re: [JET2] Customizing an iterate sentence [message #33984 is a reply to message #33941] Wed, 19 September 2007 14:10 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Joaquin:

XPath expressions can contain 'predicates', which act as filters on a step.
So, your iterate could be:

<c:iterate select="$curPackage/classes[@name = 'Residence' or @name =
'Applicant']" var="curBean">
<java:class
name="{$curBean/@name}Bean"
template="templates/JavaBean2JavaCode.jet" />
</c:iterate>

But, I'm not sure that you would want to hard code 'Residence' and
'Applicant'. You mention a configuration file. For simplicity, lets assume
that it is something that JET can read easily (like an XML file), and that
it is located in some known location (like the same directory as the input
your are providing. Let's assume that your config file is called config.xml
and it looks something like this:

<config>
<gen name="Residence"/>
<gen name="Applicant"/>
</config>

In your main.jet, prior to doing and c:iterates, do the following:

<%-- load the config.xml file from the same directory as the current
input --%>
<c:load url="{$org.eclipse.jet.resource.parent.fullPath}/config.xml "
urlContext="workspace" var="config"/>

.... then in your c:iterate:

<c:iterate select="$curPackage/classes[@name =
$config/config/gen/@name]" var="curBean">
<java:class
name="{$curBean/@name}Bean"
template="templates/JavaBean2JavaCode.jet" />
</c:iterate>

Works like a charm!

Paul

"Joaqu
Re: [JET2] Customizing an iterate sentence [message #34086 is a reply to message #33984] Thu, 20 September 2007 10:53 Go to previous message
Joaquin  Cañadas is currently offline Joaquin CañadasFriend
Messages: 25
Registered: July 2009
Junior Member
Thank you Paul for your help.
It works really well !
Joaquín

Paul Elder escribió:
> Joaquin:
>
> XPath expressions can contain 'predicates', which act as filters on a step.
> So, your iterate could be:
>
> <c:iterate select="$curPackage/classes[@name = 'Residence' or @name =
> 'Applicant']" var="curBean">
> <java:class
> name="{$curBean/@name}Bean"
> template="templates/JavaBean2JavaCode.jet" />
> </c:iterate>
>
> But, I'm not sure that you would want to hard code 'Residence' and
> 'Applicant'. You mention a configuration file. For simplicity, lets assume
> that it is something that JET can read easily (like an XML file), and that
> it is located in some known location (like the same directory as the input
> your are providing. Let's assume that your config file is called config.xml
> and it looks something like this:
>
> <config>
> <gen name="Residence"/>
> <gen name="Applicant"/>
> </config>
>
> In your main.jet, prior to doing and c:iterates, do the following:
>
> <%-- load the config.xml file from the same directory as the current
> input --%>
> <c:load url="{$org.eclipse.jet.resource.parent.fullPath}/config.xml "
> urlContext="workspace" var="config"/>
>
> ... then in your c:iterate:
>
> <c:iterate select="$curPackage/classes[@name =
> $config/config/gen/@name]" var="curBean">
> <java:class
> name="{$curBean/@name}Bean"
> template="templates/JavaBean2JavaCode.jet" />
> </c:iterate>
>
> Works like a charm!
>
> Paul
>
> "Joaquín Cañadas" <jjcanada@ual.es> wrote in message
> news:fcmtfi$gqa$1@build.eclipse.org...
>> Hello,
>> it is possible to execute the body of an iterate sentence only for some
>> elements of the collection?.
>> For example, the following input model contain 4 classes:
>>
>> <Package name="AssessmentSchema">
>> <classes name="Residence" />
>> <classes name="Applicant" />
>> <classes name="ResidenceCriterion" />
>> <classes name="ResidenceDecision" />
>> </Package>
>>
>>
>> My main.jet template contain the following code:
>>
>> <c:iterate select="$curPackage/classes" var="curBean">
>> <java:class
>> name="{$curBean/@name}Bean"
>> template="templates/JavaBean2JavaCode.jet" />
>> </c:iterate>
>>
>> The body of the iterate sentence is applied to the 4 classes that appear
>> in the input model. However, I would like to apply the body only to 2 of
>> those classes, providing for example a configuration file including the
>> list of classes to apply the template:
>>
>> Residence
>> Applicant
>>
>> How can I implement that kind of transformation?
>>
>> One solution would be adding a new attribute to the input model, allowing
>> the selection of the classes. However, the decision of selecting or not a
>> class is a "design decision", and it would not be adequate to change the
>> input model (and metamodel)... At least I think so...
>>
>> Thank you in advance.
>> Joaquin
>
>
Previous Topic:[JET] Returning a List from a custom XPath function.
Next Topic:MOFScript with EMF UML2 v1.0.0 XMI
Goto Forum:
  


Current Time: Thu Apr 25 05:26:49 GMT 2024

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

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

Back to the top