<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Graversen &#187; groovy</title>
	<atom:link href="http://graversen.org/tag/groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://graversen.org</link>
	<description>Daniels comments</description>
	<lastBuildDate>Wed, 04 Apr 2012 09:47:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating Google wave robots in Grails</title>
		<link>http://graversen.org/2009/07/22/creating-google-wave-robots-in-grails/</link>
		<comments>http://graversen.org/2009/07/22/creating-google-wave-robots-in-grails/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 06:49:02 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[app-engine]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[wave]]></category>

		<guid isPermaLink="false">http://graversen.org/?p=168</guid>
		<description><![CDATA[Updated 17/11: A grails plugin for Wave have been released see MasteringWave for more information. I just got access to Google wave, where I would like to create a robot. A robot is a participant in the wave conversation and can do the same as everyone else in the wave. Wave robots can currently only [...]]]></description>
			<content:encoded><![CDATA[<p><b>Updated 17/11: A grails plugin for Wave have been released see <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.masteringwave.com%2F2009%2F11%2Fwave-robots-with-grails-plugin%2F&sref=rss">MasteringWave </a>for more information.</b></p>
<p>I just got access to <a href="http://redirectingat.com?id=10371X688478&xs=1&url=https%3A%2F%2Fwave.google.com%2F&sref=rss">Google wave</a>, where I would like to create a <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fcode.google.com%2Fapis%2Fwave%2Fextensions%2Frobots%2Findex.html&sref=rss">robot</a>. A robot is a participant in the wave conversation and can do the same as everyone else in the wave.  Wave robots can currently only be used by applications running on Google App-engine, so you need access to App-Engine. You can get this access <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fappengine.google.com%2F&sref=rss">here</a>.
</p>
<p>The application that I&#8217;m using is running grails, so it needs to fit into that application. When you read the robot functional specification, robots should extend AbstractRobotServlet. In grails Apps you have Controllers and no servlets, so this is a bit tricky. But really easy, when you find the trick.
</p>
<p>To create your app, you need to create a grails app, to be deployed in app-engine using the Grails <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.grails.org%2Fplugin%2Fapp-engine&sref=rss">app-engine plugin</a>. Follow the guide on the page and you should have an app running on app-engine.
</p>
<p>I&#8217;ll use the <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fcode.google.com%2Fapis%2Fwave%2Fextensions%2Frobots%2Fjava-tutorial.html&sref=rss">wave robot tutorial</a> as starting point for the app. The first thing you need is to <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fcode.google.com%2Fp%2Fwave-robot-java-client%2Fdownloads%2Flist&sref=rss">download</a> the following files and place them in the ./lib folder of your project.
</p>
<ul>
<li><span style="font-family:Courier New; font-size:10pt">wave-robot-api.jar</span><span style="font-family:Times New Roman; font-size:12pt"><br />
			</span></li>
<li><span style="font-family:Courier New; font-size:10pt">json.jar</span><span style="font-family:Times New Roman; font-size:12pt"><br />
			</span></li>
<li><span style="font-family:Courier New; font-size:10pt">jsonrpc.jar</span><span style="font-family:Times New Roman; font-size:12pt"><br />
			</span></li>
</ul>
<p>The you need to create a capabilities.xml file. This is a configuration file, telling wave what your app responds to.  capabilities.xml should be placed in the folder ./web-app/_wave/
</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:robot</span> <span style="color: #000066;">xmlns:w</span>=<span style="color: #ff0000;">&quot;http://wave.google.com/extensions/robots/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:capabilities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:capability</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;blip_submitted&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/w:capabilities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/w:version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/w:robot<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>You can add as many capabilities as you want. Remember the version element should correspond to you application appspot version.
</p>
<p><strong>Update: For a clarification on the version numbering see <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.masteringwave.com%2F2009%2F08%2Fcapabilities-xml&sref=rss">http://www.masteringwave.com/2009/08/capabilities-xml</a></strong></p>
<p>You can add the servlet file that need to be extended. This is done by placing the file in the ./src/groovy or ./src/java in your project. If it is a groovy file, it should probably be place4d in the groovy folder. You should maintain the package path within these folders. Create the following file ./src/groovy/com/wave/ParrotyServlet.groovy. (It is not very groovy code, but it is a start)
</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.wave</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.wave.api.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> ParrotyServlet <span style="color: #000000; font-weight: bold;">extends</span> &nbsp;AbstractRobotServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> processEvents<span style="color: #009900;">&#40;</span>RobotMessageBundle bundle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Wavelet wavelet <span style="color: #339933;">=</span> bundle.<span style="color: #006633;">getWavelet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>bundle.<span style="color: #006633;">wasSelfAdded</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Blip blip <span style="color: #339933;">=</span> wavelet.<span style="color: #006633;">appendBlip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextView textView <span style="color: #339933;">=</span> blip.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; textView.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I'm alive!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.google.com%2Fsearch%3Fhl%3Den%26amp%3Bq%3Dallinurl%253Aevent%2Bjava.sun.com%26amp%3BbtnI%3DI%2527m%2520Feeling%2520Lucky&sref=rss"><span style="color: #003399;">Event</span></a> e<span style="color: #339933;">:</span> bundle.<span style="color: #006633;">getEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> EventType.<span style="color: #006633;">BLIP_SUBMITTED</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Blip blip <span style="color: #339933;">=</span> wavelet.<span style="color: #006633;">appendBlip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextView textView <span style="color: #339933;">=</span> blip.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textView.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Copying: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getBlip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Then you need to add the servlet mapping this is done by installing the template. Run the following command, when you are in your project.
</p>
<p><span style="font-family:Courier New; font-size:10pt">grails install-templates<br />
</span></p>
<p>Then you can edit the file ./src/templates/war/web.xml and add the servlet and the serveletmapping. This is done with the following elements. Remember that two elements should be placed after corresponding elements; otherwise the XML is not valid.
</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Parroty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.wave.ParrotyServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Parroty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/_wave/robot/jsonrpc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Deploy the service, and you can test you application. Create a new wave. Add you robot with the name &lt;yourappspotname&gt;@appspot.com. Try to add a comment and you should get something like <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.screencast.com%2Fusers%2FDaniel_Graversen%2Ffolders%2FJing%2Fmedia%2Fed2f5c51-964b-4bf2-9e2c-fccd5f4d02f2&sref=rss">this screencast</a>.
</p>
<p>This is not a very functional robot, but it works. To store data you can use a service, which can be called from the servlet.</p>

<div class="skimlinks-disclosure-button"><p><script class="skimlinks_ref_script" type="text/javascript" src="http://static.skimlinks.com/api/ref.js?p=10371&amp;d=688478&amp;t=1"></script></p></div>
]]></content:encoded>
			<wfw:commentRss>http://graversen.org/2009/07/22/creating-google-wave-robots-in-grails/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>SAP PI XML Mappings using groovy</title>
		<link>http://graversen.org/2009/07/03/sap-pi-xml-mappings-using-groovy/</link>
		<comments>http://graversen.org/2009/07/03/sap-pi-xml-mappings-using-groovy/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 11:50:42 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[pi]]></category>
		<category><![CDATA[pi71]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[process integration]]></category>
		<category><![CDATA[sap]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[transformation]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://graversen.org/2009/07/03/sap-pi-xml-mappings-using-groovy/</guid>
		<description><![CDATA[Using Groovy as java mappings for transformation of XML documents in the SAP PI or XI. ]]></description>
			<content:encoded><![CDATA[<p>Creating XML mapping in Java have for me always been difficult, it has been possible but I would prefer other tools. I was looking at scripting languages like Ruby/JRuby or Groovy for creating some web apps. Those languages seem quite hot right now. On the <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwiki.sdn.sap.com%2Fwiki%2Fdisplay%2Fevents%2FComposition%2Bon%2BGrails%2B-%2BComposition%2BEvolved&sref=rss">SCN Wiki</a> a group has implemented the Grails (groovy on Rails) on the Netweaver system, as Composition on Grails. With this tool it is possible to applications with a Webdynpro look and feel.  Grails is a framework for creating webapps with less coding.</p>
<p><a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fgroovy.codehaus.org%2FGetting%2BStarted%2BGuide&sref=rss">Groovy</a> is a scripting language designed on the basis of Java. Groovy script is compiled into Java classes, and both Java and Groovy can be mixed. This makes the implementation easier, just start writing Java and when you feel like use some of the smarter features of Groovy you can use them.</p>
<p>While I was looking at Grails, I thought that I would be possible to use it in PI. One place could be in java mappings. I&#8217;ll describe the steps that I have taken to implement this.</p>
<ol>
<li><a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fgroovy.codehaus.org%2FDownload&sref=rss">Download</a> and install the groovy library</li>
<li>Get the <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fgroovy.codehaus.org%2FEclipse%2BPlugin&sref=rss">Groovy plugin</a> to Eclipse, this make developing much easier.</li>
<li>Create a new Eclipse project</li>
<li>Insert the aii_map_api.jar in the project, to be able to implement Streamtransformation service.</li>
<li>Create a new Groovy file in the source folder, with the name GroovyMapIdoc.groovy, then Eclipse know that it is a groovy file.</li>
<li>Create the mapping of your file. I have attached my example code bellow.</li>
<li>Compile the Groovy files using the context menu on the GroovyMapIdoc.groovy file.</li>
<li>Zip the content of the bin-groovy in the project folder and upload it, as an imported archive in the Integration builder. Alternative use <a href="http://redirectingat.com?id=10371X688478&xs=1&url=https%3A%2F%2Fwww.sdn.sap.com%2Firj%2Fscn%2Fweblogs%3Fblog%3D%2Fpub%2Fwlg%2F5341&sref=rss">ant build</a> to create the zip files.</li>
<li>Upload the two files Groovy-1.6.1.jar and asm-2.2.3.jar as imported archives. They can be found in &lt;GROOVY_HOME&gt;\lib</li>
<li>Activate and use the mapping.</li>
</ol>
<p>I would expect people trying this to have a good knowledge of using XI or PI Java mappings, because it is a requirement for the development of mappings.</p>
<p>One example I always have considered, was my first challenging mapping experience. Posting financial post with more than 1000 lines to the FIDCCP02 idoc. The FIDCCP02 only accepts 999 lines. The posting can be created multiply idocs with 998 lines and the post a balance on each item. This way all documents will balance.</p>
<p>The document is transformed from the left document to the right. I have for this example used a max size of 3 to make testing easier.</p>
<p><img src="http://graversen.org/wp-content/070309_1150_SAPPIXMLMap1.png" alt="" height="265" /><img src="http://graversen.org/wp-content/070309_1150_SAPPIXMLMap2.png" alt="" height="265" /></p>
<p>The code that I have used for the mapping is.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.figaf.mapping<br />
<br />
import com.sap.aii.mapping.api.StreamTransformation;<br />
import java.io.InputStream;<br />
import java.io.OutputStream;<br />
import java.util.Map;<br />
<br />
import groovy.xml.MarkupBuilder<br />
<br />
class GroovyMapIdoc implements StreamTransformation{<br />
<br />
&nbsp; &nbsp;Map param;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; void setParameter(Map param) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; this.param = param;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; // Number of lines pr idoc<br />
&nbsp; &nbsp; def step=3 <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Implementation of the execution method<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; void execute(InputStream input, OutputStream out) {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Parse the input using the XMLSlurper<br />
&nbsp; &nbsp; &nbsp; &nbsp; def FICCP01 = new XmlSlurper().parse(input)<br />
&nbsp; &nbsp; &nbsp; &nbsp; // get the different lines using the GPath<br />
&nbsp; &nbsp; &nbsp; &nbsp; def Lines = FICCP01.IDOC.LINE<br />
&nbsp; &nbsp; &nbsp; &nbsp; // create a writer example <br />
&nbsp; &nbsp; &nbsp; &nbsp; def writer = new OutputStreamWriter(out)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; def xml = new MarkupBuilder(writer)<br />
&nbsp; &nbsp; &nbsp; &nbsp; // create the root element and fill data into it. <br />
&nbsp; &nbsp; &nbsp; &nbsp; xml.FICCP01(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // get the number of idocs to be created. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def numIdocs = &nbsp; Lines.size()/step + (Lines.size()%step&gt;0?1:0) &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // loop for each idoc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for ( i in 0..numIdocs-1 ) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // find the limit for the current idoc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def max = Math.min( Lines.size(), i* step+2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // create sum ellement to create balances<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def sum = 0.0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;def lineno=1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IDOC(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // create the number segment, using GPATH<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NR(FICCP01.IDOC.NR )<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // for each line in the range do the following<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Lines[i*step..max].each{oldline-&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// create a &nbsp;new Line node, in the out put element<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// with the following content<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LINE(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NO(lineno++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Text(oldline.Text.text())<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Amount(oldline.Amount.toBigDecimal())<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// update the sum<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum +=oldline.Amount.toBigDecimal()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // create a balancing line, with balances the result<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LINE(){<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NO(step+1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Text('Balance')<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Amount(-sum)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // write the xml to output<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.flush()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.close()<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
}</div></div>
<p>Behind the scenes the Groovy file is changed in to java classes. Because Java does not support Closures natively different subclasses are created. Try to have a look on them using a decompiler like <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.varaneckas.com%2Fjad&sref=rss">jad</a>.</p>
<p><strong>Conclusion</strong></p>
<p>Groovy could be a way to improve the how java mappings are created. The XML generation is easier to handle then how it would have been created in Java and it is more powerful than XSLT. It takes some effort to get use to the closures concept of Groovy and the other notation, but it seems to work real well.</p>
<p>I don&#8217;t think the performance issue with the mapping is a problem. There is an overhead to load the groovy libraries and the code is probably not as optimized if it was written directly in java. I have not made any measurements for this.</p>

<div class="skimlinks-disclosure-button"><p><script class="skimlinks_ref_script" type="text/javascript" src="http://static.skimlinks.com/api/ref.js?p=10371&amp;d=688478&amp;t=1"></script></p></div>
]]></content:encoded>
			<wfw:commentRss>http://graversen.org/2009/07/03/sap-pi-xml-mappings-using-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

