Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Using 'dump.jet' for sub-files
Using 'dump.jet' for sub-files [message #64304] Mon, 13 July 2009 12:08 Go to next message
aart matsinger is currently offline aart matsingerFriend
Messages: 12
Registered: July 2009
Junior Member
I have 2 questions about the following transformations that I am using:
'main.jet' initiates 'dump.jet' and 'work.jet' which have as input
'profile.xml' containing url's of models.
'work.jet' loads within a loop the models specified in 'profile.xml' and
deals with details from these models (based on an ealier thread in this
group).
Since the generated 'dump.xml' only contains the content of the profile I
try to add in 'work.jet' another activation of 'dump.jet', just before the
load statement of the sub-model. When I hardcode the output to be
generated, this has no effect: no dump output is generated for the
model-files.
This is the specific code in 'work jet' (all used parameters have been set
before):

<ws:file template="templates/dump.jet"
path="{$org.eclipse.jet.resource.project.name}/out/sub_dump.xml "/>
<c:load
url=" {$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/@ model} "
var="cmodel"/>

When I dynamically build the path for the dump-output, I get syntactic
errors. The following Java code is used to set the build-path:
<%
String s1 =
" {$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/@ model}/ ";
String s2 = (String) context.getVariable("x0");
String myName = s1 + s2 + ".xml";
%>
And this is the code that does not pick up the varable 'myName':
<ws:file template="templates/dump.jet" path="{$myName}"/>

Any clue how to solve these 2 issues?
For the dump-file rather than creating a specific dump-file for each xml
file it would be ok to combine all dump output in one file.

Aart
Re: Using 'dump.jet' for sub-files [message #64462 is a reply to message #64304] Tue, 14 July 2009 11:29 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Aart:

I'll start with the syntactic:

You wrote:
> ... The following Java code is used to set the build-path:
> <%
> String s1 =
> " {$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/@ model}/ ";
> String s2 = (String) context.getVariable("x0");
> String myName = s1 + s2 + ".xml";
> %>
> And this is the code that does not pick up the varable 'myName':
> <ws:file template="templates/dump.jet" path="{$myName}"/>

The JET compiler produces Java code. Any Java code in <% %>, <%! %> or <%=
%> is written verbatim to that class - embedded XPath expressions are not
processed in embedded Java code.

So, rewrite you template like this:

<c:setVariable var="myName" select="
'{$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/ @model}/{$x0}.xml'
" />


As for keeping track of your loaded models, I suggest creating a unique
variable for each loaded model, and store the variable name as an
annotation on the model element used to load the model:...

<%-- create a unique variable for the model load and
store is as the @cmodelVar attribute on $c --%>
<c:set select="$c" name="cmodelVar">cmodel<f:unique/></c:set>
<c:load
url=" {$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/@ model} "
var="{$c/@cmodelVar}"/>

Each time you go through the above code, you'll get a different value for
'cmodelVar': cmodel0, cmodel1, cmodel2, ...

Then, in your dump.jet (I'm making the uber-dump XML format up - adjust as
needed):


<all>
<%-- dump the main model --%>
<c:dump select="/*" format="true" entities="true"/>
<%-- dump the cmodel models' --%>
<c:iterate select="...." var="c">
<cmodel var="<c:get select="$c/@cmodelVar"/>">
<c:dump select="$ {$c/@cmodelVar}/*" format="true" entities="true"/>
</cmodel>
</c:iterate>
</all>

Paul
Re: Using 'dump.jet' for sub-files [message #64485 is a reply to message #64462] Tue, 14 July 2009 14:25 Go to previous message
aart matsinger is currently offline aart matsingerFriend
Messages: 12
Registered: July 2009
Junior Member
Paul,

Your explanation of the syntax issue is clear to me; thanks !
I implemented your proposal on how to include sub-model dumps, but this
resulted in the following error:
templates/dump.jet(7,16): <c:get select="$c/@cmodelVar">
Error: XPath expression returned no result
It seems to me that the unique identifier is inserted into the submodel at
the wrong moment, i.e. before the submodel has actually been loaded. And
also only the model in memory is extended, and not the model on disk (as
seen in the Eclipse explorer tree). I include the jet files / models
below. Maybe you can see where things have been done wrong.

*** main.jet:
<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
<c:if test="isVariableDefined('org.eclipse.jet.resource.project.name') ">
<ws:file template="templates/work.jet"
path="{$org.eclipse.jet.resource.project.name}/out/summary.txt " />
<ws:file template="templates/dump.jet"
path="{$org.eclipse.jet.resource.project.name}/out/dump.xml "/>
</c:if>
*** work.jet:
<%@taglib prefix="f" id="org.eclipse.jet.formatTags"%>
<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
<%@ jet imports="java.lang.*" %>
<f:formatNow pattern="MM/dd/yyyy - hh:mm:ss" />
<c:iterate select="/app/component" var="c" > <%-- read from profile
<c:set select="$c" name="cmodelVar">cmodel<f:unique/></c:set>
<c:load
url=" {$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/@ model} "
var="{$c/@cmodelVar}"/>
--%> <c:setVariable var="cname" select="$c/@name" /> <%--
--%> <c:setVariable var="cpath" select="$c/@model" />
cname = <c:get select="$cname" />, cpath = <c:get select="$cpath" />
<c:setVariable var="myVar"
select=" '{$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/ @model}/dump.xml' "
/>
<c:load
url=" {$org.eclipse.jet.resource.parent.projectRelativePath}/{$c/@ model} "
var="cmodel"/>
<c:iterate select="$cmodel/app/property" var="p" > <%-- read from model
--%> - property name = <c:get select="$p/@name" />, value = <c:get
select="$p/@value" />
</c:iterate>
</c:iterate>

*** dump.jet:
<all>
<?xml version="1.0" encoding="utf-8"?>
<%-- dump the main model --%>
<c:dump select="/*" format="true" entities="true"/>
<%-- dump the sub-models --%>
<c:iterate select="/app/component" var="c" >
<cmodel var="<c:get select ="$c/@cmodelVar" />"
<c:dump select="$ {$c/@cmodelVar}/*" format="true" entities="true"/>
</cmodel>
</c:iterate>
</all>

*** profile.xml:
<app name="profileA">
<component name="c1" model="component1.xml" />
<component name="c2" model="component2.xml" />
</app>

*** component1.xml:
<app name="c1">
<property name="p1" value="x"/>
<property name="p2" value="y"/>
</app>

*** component2.xml:
<app name="c2">
<property name="p10" value="x1"/>
<property name="p20" value="x2"/>
</app>

kind regards,
Aart
Previous Topic:error on context.getVariable
Next Topic:Modifying Content assist, and notifying linking service
Goto Forum:
  


Current Time: Thu Apr 25 14:01:18 GMT 2024

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

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

Back to the top