|
|
Re: [JET2] Customizing an iterate sentence [message #34086 is a reply to message #33984] |
Thu, 20 September 2007 10:53 |
Joaquin Cañadas 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
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.02834 seconds