<?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>Code3 &#187; Techchat</title>
	<atom:link href="http://www.code3.dk/category/techchat/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.code3.dk</link>
	<description>Techchat</description>
	<lastBuildDate>Thu, 17 Nov 2011 13:10:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using TDC&#8217;s Columbine with modern browsers</title>
		<link>http://www.code3.dk/using-tdcs-columbine-with-modern-browsers/</link>
		<comments>http://www.code3.dk/using-tdcs-columbine-with-modern-browsers/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 08:52:34 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=354</guid>
		<description><![CDATA[On columbine.tdc.dk there is a gui with tools for resellers of TDC eBSA products. These tools are crucial for interacting [...]]]></description>
			<content:encoded><![CDATA[<p>On columbine.tdc.dk there is a gui with tools for resellers of TDC eBSA products. These tools are crucial for interacting with the TDC systems, but unfortunately they only work in Internet Explorer right now. They seem pretty old and they made with hand-coded javascript. TDC seems to have plans to update the site to work with all browsers and if they ask me, I think they should just update the site to use a modern framework like <a href="http://jquery.org/">jQuery</a>.</p>
<p>I took a look at what seemed to be the problem. If I keep open the Firefox &#8220;Error Console&#8221; while browsing I see these two errors</p>
<blockquote><p>
Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.<br />
Source File: https://columbine.tdc.dk/komik/SessionServer?code=wsess&amp;pseudonym=wxvis<br />
Line: 545
</p></blockquote>
<p>and</p>
<blockquote><p>
Error: MAINFORM is not a function<br />
Source File: https://columbine.tdc.dk/komik/SessionServer?code=wsess&amp;pseudonym=wxvis<br />
Line: 545
</p></blockquote>
<p>Referencing by name in the global scope seems to be very old bad practice in form access. I can&#8217;t even find descriptions of it on the net. <a href="http://www.jibbering.com/faq/notes/form-access/">This</a> and <a href="http://www.javascripttoolbox.com/bestpractices/#forms">this</a> are the closest mentions I can find.</p>
<p>Anyway, this seemed like a problem that should be easy to fix with a <a href="https://sites.google.com/a/chromium.org/dev/developers/design-documents/user-scripts">userscript</a> / <a href="http://www.greasespot.net/">greasemonkey script</a>. So I went ahead and made one and put it on github. I&#8217;ve only used it on &#8220;Vis eksisterende BB&#8221; and &#8220;Net-info&#8221; so it is only enabled for those two pages, and it might need changes to work on other pages (patches/forks welcome).</p>
<p><a href="https://github.com/andersnorgaard/columbine-greasmonkey"><strong>https://github.com/andersnorgaard/columbine-greasmonkey</strong></a></p>
<p>It&#8217;s pretty simple. It uses the <a href="http://wiki.greasespot.net/Content_Script_Injection">content script injection</a> hack to create the required reference to &#8220;MAINFORM&#8221; in the global scope.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/using-tdcs-columbine-with-modern-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy CPE</title>
		<link>http://www.code3.dk/groovy-cpe/</link>
		<comments>http://www.code3.dk/groovy-cpe/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 19:45:19 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[tr069]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=349</guid>
		<description><![CDATA[I&#8217;ve been working quite a lot on a TR069 AutoConfigurationServer. As part of the prototyping I created a client emulator [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working quite a lot on a TR069 AutoConfigurationServer. As part of the prototyping I created a client emulator to more quickly and easily test out different parts of <a href="http://www.broadband-forum.org/cwmp.php">the TR069 spec</a>. I called the program <a href="http://code.google.com/p/groovycpe/">GroovyCPE</a> and it can be found on Google Code hosting. Hopefully it will be useful for others in initial bringup of TR069 servers, regression testing and performance testing. The code written in Groovy and it is licensed under the GPLv3.</p>
<p>The TR069 schemas which can be found at http://www.broadband-forum.org/cwmp.php define the communication. Unfortunately the CWMProtocol uses ancient technology &#8211; namely XML-RPC. One can find old libraries for XML-RPC on the web, but they look old and crusty. We decided to go with JAXB ( https://jaxb.dev.java.net ) to get Java classes from the schemas. However, JAXB doesn&#8217;t seem to handle the old XML-RPC ideas perfectly, so we have to apply some band-aid (more on the server side than on the client side, though). I&#8217;ll blog about this separately.</p>
<p>To get the JAXB processing to work at all I have deleted <code>fixed="1"</code> from the <code>soapenv:mustUnderstand</code> attributes.</p>
<p>The HTTP communication of GroovyCPE is done with the help of the <a href="http://hc.apache.org/httpclient-3.x/">Apache HttpComponents v3</a> which is a pretty OK library for HTTP communication.</p>
<p>The initial configuration content in testfiles/parameters_tg784/get*.txt is from a Thomson TG784 box.</p>
<p>GroovyCPE is built around a central store of the parameters it reads in. And as much as possible it uses the configuration parameters it self &#8211; eg. for the ManagementServer URL and the PeriodicInformInterval.</p>
<p>What it can do:</p>
<ul>
<li>Immediately send Inform messages with all event types</li>
<li>Run a thread that sends scheduled Inform messages according to the PeriodicInformInterval</li>
<li>Listen for connection requests on the ConnectionRequestURL (and send an Inform if requested</li>
<li>Accept a DownloadRequest and initiate an HTTP download session according to the contents</li>
<li>Respond to GetParameter{Names,Values,Attributes} requests.</li>
<li>Accept SetParameter{Values,Attributes} and set the values</li>
<li>Accept AddObject requests and add objects (but only if the object layout is known from the configuration parameters)</li>
</ul>
<p>I don&#8217;t have any immediate plans for improvements to GroovyCPE. At some point I will probably look at fixing the JAXB classes at generation time with a JAXB plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/groovy-cpe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing JBoss 6</title>
		<link>http://www.code3.dk/testing-jboss-6/</link>
		<comments>http://www.code3.dk/testing-jboss-6/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 12:57:53 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=346</guid>
		<description><![CDATA[So, JBoss 6.0.0 is out. And so far it looks pretty good.
Last year I was working on an JEE5 app [...]]]></description>
			<content:encoded><![CDATA[<p>So, <a href="http://in.relation.to/Bloggers/JBossAS600FinalReleased">JBoss 6.0.0 is out</a>. And so far it looks pretty good.</p>
<p>Last year I was working on an JEE5 app that runs with Seam 2 and Richfaces 3.3 on JBoss 4.2. Just for fun I tried to deploy it on JBoss 6. To make it deploy cleanly I had to fix some minor things. </p>
<ol>
<li>Only the latest Seam 2.2.1 CR3 <a href="http://seamframework.org/Seam2/Downloads">is advertised to run on JBoss 6</a>. So I grabbed that.</li>
<li>commons-httpclient, which I use in my app, was on my classpath on the JBoss 4.2 I used, but was missing on JBoss 6. But I just grabbed the one from the Seam /lib folder.</li>
<li>My app is a .ear file with a .war file inside. And the files have the same name which makes it look something like this when exploded myapp.ear/myapp.war. JBoss 6 doesn&#8217;t seem to like this, complaining that the war has already been deployed during the deployment. Renaming the .war to myappweb.war fixed it.</li>
</ol>
<p><a href="http://dow.ngra.de/2010/12/14/jee-oss-container-startup-times-apples-vs-oranges/">As expected</a>, startup is somewhat slower than JBoss 4.2.3 at around 21 secs to start JBoss 6 with my app deployed and 14 secs on JBoss 4.2.3. </p>
<p>So, to sum up; if I get the chance to do another release of the app and run it on JBoss 6 then, it is definitely possible. And I wouldn&#8217;t hesitate to do so. Taking advantage of EJB 3.1 on JBoss 6 to get rid of the silly EJB interfaces would really clean up the app.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/testing-jboss-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating, consuming and testing SOAP webservices on Grails</title>
		<link>http://www.code3.dk/creating-consuming-and-testing-soap-webservices-on-grails/</link>
		<comments>http://www.code3.dk/creating-consuming-and-testing-soap-webservices-on-grails/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 09:05:14 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=341</guid>
		<description><![CDATA[We are currently making a backend system, that has its services exposed as webservices. Since making web applications in Grails [...]]]></description>
			<content:encoded><![CDATA[<p>We are currently making a backend system, that has its services exposed as webservices. Since making web applications in Grails is pretty nice, we decided to try it for webservices.</p>
<p>Getting up and running was certainly a breeze.</p>
<p><code><br />
grails create-app ...<br />
grails install-plugin cxf<br />
</code></p>
<p>Grails is a plugin-based framework. And the <a href="http://grails.org/plugin/cxf/">cxf plugin</a> seems to be the best plugin for webservices right now. Exposing the services was then as simple as adding a</p>
<p><code>static expose=['cxf']</code></p>
<p>to the the grails service classes. We wante to allow our service interfaces to operate with complex objects. And to do that best we decided to use the <a href="http://www.grails.org/plugin/dto">DTO plugin</a> and specify our interfaces in terms of DTOs mostly generated from our domain objects. This was only a semi-good idea, I think, as the conversion to/from complex domain objects was not great out of the box (more on that in another post).</p>
<p>To consume webservices, the most straighforward way is to simply dump the <a href="http://groovy.codehaus.org/GroovyWS+installation">minimal jar of the GroovyWS module</a> in the lib folder of the project. Since we already had all the dependencies included by the cxf plugin the minimal jar is all that is needed.</p>
<p>To test the services, most of our test were simply the usual integration tests of the service classes. But for functional tests we used the <a href="http://www.grails.org/plugin/functional-test">functional-tests plugin</a> and the GroovyWS client we already had installed. </p>
<pre class="brush: java">
class MyServiceFunctionalTests extends functionaltestplugin.FunctionalTestCase {

	def myServicePort

	protected void setUp() {
		super.setUp();

		myServicePort = new WSClient(&quot;http://localhost:9091/myservice/services/my?wsdl&quot;, this.class.classLoader)
		myServicePort.initialize()
	}

	public void testAMethod(){
		final List resultVals = myServicePort.aMethod();

		assertEquals(4, resultVals.size());
	}
}
</pre>
<p>It feels a bit wrong to work with old and crufty technology like SOAP with shiny new technology like Groovy on Grails. But with that in mind it works surprisingly well. Points where I found the greatest room for improvement were.</p>
<ul>
<li>Grails has great support for Controllers as entrypoints, with interceptors for logging and authorization. For Services this seems harder if not impossible. I haven&#8217;t succeeded in using either groovys <a href="http://groovy.codehaus.org/Using+invokeMethod+and+getProperty">invokeMethod</a> or the built-in spring support for aspect-oriented-programing.</li>
<li>As mentioned above, the DTO plugin could use a more flexible mapping tool than the one it has.</li>
<li>With code that has no immediate GUI feedback, testing is extremely important. But the Grails test run so slow that it is annoying.</li>
</ul>
<p>Still, would I recommend Grails for a large SOAP project. Yes, I would.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/creating-consuming-and-testing-soap-webservices-on-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first patch to Grails accepted</title>
		<link>http://www.code3.dk/my-first-patch-to-grails-accepted/</link>
		<comments>http://www.code3.dk/my-first-patch-to-grails-accepted/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 10:58:12 +0000</pubDate>
		<dc:creator>mil</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=337</guid>
		<description><![CDATA[I recently wrote a patch for Grails to support dateCreated and lastUpdated when using mockDomain in unit tests.
This patch has [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a patch for Grails to support <code>dateCreated</code> and <code>lastUpdated</code> when using <code>mockDomain</code> in unit tests.</p>
<p>This patch has now been applied to 1.2-SNAPSHOT.</p>
<p><a rel="nofollow" href="http://jira.codehaus.org/browse/GRAILS-4540">http://jira.codehaus.org/browse/GRAILS-4540</a></p>
<p>The <code>mockDomain</code> method makes it possible to test code that uses GORMs dynamic methods, without having to use a real database.</p>
<p>IBM Developerworks has a great article on mock testing in Grails <a rel="nofollow" href="http://www.ibm.com/developerworks/java/library/j-grails10209/index.html">here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/my-first-patch-to-grails-accepted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to debug grails run-app loop</title>
		<link>http://www.code3.dk/how-to-debug-grails-run-app-loop/</link>
		<comments>http://www.code3.dk/how-to-debug-grails-run-app-loop/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 09:21:12 +0000</pubDate>
		<dc:creator>mil</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=331</guid>
		<description><![CDATA[I recently had a problem where grails run-app would start
the server, then immediately recompile 1 class, then restart&#8230; and
repeat.
Google told [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a problem where <code>grails run-app</code> would start<br />
the server, then immediately recompile 1 class, then restart&#8230; and<br />
repeat.</p>
<p>Google told me that the problem probably was an empty Java file in my<br />
project and to look in the<br />
<code>~/.grails/1.2-M4/projects/myproject/classes</code> directory to<br />
see which file kept changing timestamp.</p>
<p>However, no files did that. The solution was to modify<br />
<code>$GRAILS_HOME/scripts/_GrailsCompile.groovy</code> and add<br />
<code>listFiles:true</code> to the compile target:</p>
<pre class="brush: groovy">
ant.groovyc(destdir:classesDirPath,
classpathref:classpathId,
encoding:&quot;UTF-8&quot;,
listFiles:true,
compilerPaths.curry(classpathId, false))
</pre>
<p>And it turned out Google was right, I had a Java file with only the<br />
package specification in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/how-to-debug-grails-run-app-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Console output from Grails tests</title>
		<link>http://www.code3.dk/console-output-from-grails-tests/</link>
		<comments>http://www.code3.dk/console-output-from-grails-tests/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 07:13:30 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=328</guid>
		<description><![CDATA[For casual testing in Grails, it would be nice to be able to just have the output of the tests [...]]]></description>
			<content:encoded><![CDATA[<p>For casual testing in Grails, it would be nice to be able to just have the output of the tests dumped to the console that the tests were run from. This doesn&#8217;t seem possible in the default setup, but adding these lines </p>
<pre class="brush: java">
		if(argsMap[&#039;no-reports&#039;]){
			println testRunner.out.toString()
			println testRunner.err.toString()
		}
</pre>
<p>should do the trick, if you add them to <strong>$GRAILS_HOME/script/_GrailsTest.groovy</strong> in the &#8220;runTests&#8221; closure, right after &#8221; <code>def result = testRunner.runTests(testSuite)</code>&#8221; </p>
<p>With those lines in place you can run your test like<br />
</br><br />
<code>grails -Dserver.port=9090 test-app -integration -no-reports MyController</code><br />
</br><br />
Specifying the name of the class to test is important since only the output from the last test class will be printed. So we might as well only run one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/console-output-from-grails-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dependent dropdowns in Grails</title>
		<link>http://www.code3.dk/dependent-dropdowns-in-grails/</link>
		<comments>http://www.code3.dk/dependent-dropdowns-in-grails/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 10:46:25 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=324</guid>
		<description><![CDATA[It does really seem to be a very common problem with the dependend or chained drop-downs. At least it was [...]]]></description>
			<content:encoded><![CDATA[<p>It does really seem to be a <a href="http://www.code3.dk/dependent-dropdowns-in-seam-and-richfaces/">very common problem</a> with the dependend or chained drop-downs. At least it was one of the first problems I faced in the Grails app I&#8217;m working on now.</p>
<p>The solution is not really more or less elegant than the one for Seam and Richfaces. I followed <a href="http://www.grails.org/AJAX-Driven+SELECTs+in+GSP">the guide on Grails.org</a> but decided to make the solution a bit more general. So I pass the name of the select-element-to-update as a string to the update function. This way I can also put the function in a separate file for inclusion (updateselect.js).</p>
<pre class="brush: javascript">
function updateSelect(e, elemId) {
// The response comes back as a bunch-o-JSON
var values = eval(&quot;(&quot; + e.responseText + &quot;)&quot;) // evaluate JSON

if (values) {
updateSelectFromJSON(values, elemId);
}
}

function updateSelectFromJSON(values, elemId) {
var rselect = document.getElementById(elemId)
// 	Clear all previous options
rselect.options.length = 0

// Rebuild the select
for (var i=0; i &lt; values.length; i++) {
var opt = document.createElement(&#039;option&#039;);
opt.text = values[i].name
opt.value = values[i].id
try {
rselect.add(opt, null) // standards compliant; doesn&#039;t work in IE
} catch(ex) {
rselect.add(opt) // IE only
}
}
}
</pre>
<p>Which is then called like this</p>
<pre class="brush: xml">

...

&lt;form&gt;
optionKey=&quot;id&quot; optionValue=&quot;name&quot; name=&quot;country.name&quot; id=&quot;country.name&quot; from=&quot;${Country.list()}&quot;
onchange=&quot;${remoteFunction(
controller:&#039;country&#039;,
action:&#039;ajaxGetCities&#039;,
params:&#039;&#039;id=&#039; + escape(this.value)&#039;,
onComplete:&#039;&#039;&#039;updateSelect(e, &#039;city&#039;)&#039;&#039;&#039;)}&quot;
&gt;

&lt;/form&gt;</pre>
<p>One thing is missing from this solution, though. Unlike the solution on grails.org, the chained select is not updated based on the default value of the previous select. This can be fixed by inserting the following in the head element of the .gsp page.</p>
<pre class="brush: xml">

function init() {
document.cityform[&#039;country.name&#039;].onchange();
}
window.onload = init;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/dependent-dropdowns-in-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails bash completion</title>
		<link>http://www.code3.dk/grails-bash-completion/</link>
		<comments>http://www.code3.dk/grails-bash-completion/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 10:45:49 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[ant-deb-task]]></category>
		<category><![CDATA[bashcompletion]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=320</guid>
		<description><![CDATA[I&#8217;ve started doing some Grails development. So far it seems great. Here are a couple of notes to start with.
Grails [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started doing some Grails development. So far it seems great. Here are a couple of notes to start with.</p>
<p>Grails is not packaged officially for Ubuntu yet. And the packages that can be downloaded from grails.org don&#8217;t have bash completion. <a href="http://groups.google.com/group/groovyvan/browse_thread/thread/6a2f95ebbfa4c8ea?pli=1">This guy</a> however packaged grails for Debian/Ubuntu, and it include a bash completion script. <a href="http://code.google.com/p/ant-deb-task/">The package</a> seems to work great, and for one of my machines where I already installed grails from the usual tar.gz download, I pulled out the bash completion from the deb-package. To make it work completely with the tar.gz dowload I just had to modify the location of the grails installation (to use $GRAILS_HOME). Ahhhh.</p>
<p>Somewhat less useful (but fun), I also added the Ubuntu &#8220;notify-send&#8221; notification feature <a href="http://colinharrington.net/blog/2009/05/grails-growl-like-notifications-in-linux-ubuntu-904/">described here</a>. I feel all set for Grails development.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/grails-bash-completion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated documentation and ODFDOM</title>
		<link>http://www.code3.dk/automated-documentation-and-odfdom/</link>
		<comments>http://www.code3.dk/automated-documentation-and-odfdom/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 13:14:55 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[ODFDOM]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=310</guid>
		<description><![CDATA[Everyone hates out-of-date documentation. Unfortunately most people hate keeping documentation updated even more. So Paul Duvall has written a nice [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone hates out-of-date documentation. Unfortunately most people hate keeping documentation updated even more. So Paul Duvall has written a <a href="http://www.ibm.com/developerworks/library/j-ap06108/index.html">nice piece on developerWorks</a> about automatically generated documentation.</p>
<p>The tools used in Pauls piece don&#8217;t exactly fit my project however. I use <a href="http://code.google.com/p/google-guice/">Guice</a>, and since that can be a bit confusing it would be nice to have some overview of how Guice binds the app together. With Guice 2.0  however there is a nice <a href="http://code.google.com/p/google-guice/wiki/Grapher">Guice plugin to generate diagrams</a>. The only problem is that the Seam/Guice integration is not updated to Guice 2.0 yet. So I guess I&#8217;ll postpone this.</p>
<p>An important part of any application is the data model. So I would like to have entity diagrams generated. Since I use hibernate/JPA I thought that there would be an ant task to have entity diagram generated directly. However, lots of searching on google brought me nowhere. <a href="http://www.softwaresecretweapons.com/jspwiki/linguinemaps">Linguine maps</a> would have been a solution back in the days when one used &#8220;.hbm.xml&#8221; files to configure entity classes. But noone does that anymore. So I asked a question on <a href="http://stackoverflow.com/questions/1017997/ant-task-for-generating-er-diagram-from-jpa-hibernate-annotated-classes">Stackoverflow</a> but that didn&#8217;t help. Finally I tried a workaround that involves starting a database deploying the entities and then letting <a href="http://schemaspy.sourceforge.net/">SchemaSpy</a> generate diagrams from the database. This could definitely be more elegant.</p>
<p>I usually don&#8217;t program with deep or advanced class hierachies so I don&#8217;t see the point in doing inheritance graphs. Others do, however, and the tool <a href="http://code.google.com/p/apiviz/">API viz</a> does a nice and easy job of creating them, so I might as well include that. I could presumably also have used <a href="http://umljgraph.sourceforge.net/">UMLJGraph</a> or <a href="http://www.umlgraph.org/">UMLGraph</a> (like in the developerworks article).</p>
<p>The really fun part begins if I were to write a small ant task that could process an ODF document with <a href="http://odftoolkit.org/projects/odfdom/pages/Home">ODFDOM</a> and automatically insert the graphs in the right place. I attended the ODFDOM hands-on-lab at JavaOne, and while the api is a bit rough now, it should actually not be too much work I think (especially if I use <a href="http://groovy.codehaus.org/">Groovy</a>).  I guess the first version would just replace some placeholder string in the document with the appropriate diagram. This way it should not be too difficult to use with the different documentation template documents one encounters. Poor mans LaTeX, yay! I&#8217;ll blog it when I get it running.</p>
<p>+++++++++++++++++++++++++++++++++++++</p>
<p>The AntTask for ApiViz just requires the apiviz jar file which I put in a folder &#8220;buildlib&#8221;:</p>
<pre class="brush: xml">
&lt;target name=&quot;javadoc&quot;&gt;
 &lt;javadoc destdir=&quot;docs/api&quot;
 author=&quot;true&quot;
 version=&quot;true&quot;
 use=&quot;true&quot;
 windowtitle=&quot;TACS API&quot;
 classpathref=&quot;class.build.path&quot;
 doclet=&quot;org.jboss.apiviz.APIviz&quot;
 docletpath=&quot;buildlib/apiviz-1.3.0.GA.jar&quot;
 additionalparam=&quot;-author -version&quot;&gt;
 &lt;fileset dir=&quot;src&quot;/&gt;
 &lt;/javadoc&gt;
 &lt;/target&gt;
</pre>
<p>The not very elegant integration of SchemaSpy involves the buildtarget below which starts two tasks in parallel. The top one just executes a class that programatically start an HSQLDB and then  loads a datasource which points to that database. This then causes Hibernate to create the tables specified by the entity classes. When the database is started and the datasource loaded it sleeps 20 secs to allow the schemaspy task to connect. The bottom parallel task then sleeps 10 secs (to allow the datasource to load) and then runs schemaspy.</p>
<pre class="brush: xml">
&lt;target name=&quot;db-diagram&quot; depends=&quot;db-start&quot;&gt;
&lt;parallel&gt;
 &lt;daemons&gt;
 &lt;java dir=&quot;build/classes/test&quot; classname=&quot;TestEntityManagerProvider&quot; fork=&quot;true&quot;&gt;
 &lt;classpath&gt;
&lt;pathelement location=&quot;build/classes/test&quot;/&gt;
&lt;path refid=&quot;class.test.path&quot;/&gt;
 &lt;/classpath&gt;
 &lt;/java&gt;
 &lt;/daemons&gt;
 &lt;sequential&gt;
 &lt;sleep seconds=&quot;10&quot;/&gt;
 &lt;java jar=&quot;buildlib/schemaSpy_4.1.1.jar&quot;
 output=&quot;docs/output.log&quot;
 error=&quot;docs/error.log&quot;
 fork=&quot;true&quot;&gt;
 &lt;arg line=&quot;-t hsqldb&quot;/&gt;
 &lt;arg line=&quot;-host localhost&quot;/&gt;
 &lt;arg line=&quot;-db tacs&quot;/&gt;
 &lt;arg line=&quot;-u sa&quot;/&gt;
 &lt;arg line=&quot;-s PUBLIC&quot;/&gt;
 &lt;arg line=&quot;-cp buildlib/hsqldb.jar&quot;/&gt;
 &lt;arg line=&quot;-o docs/api&quot;/&gt;
 &lt;/java&gt;
 &lt;/sequential&gt;
 &lt;/parallel&gt;
 &lt;/target&gt;
</pre>
<pre class="brush: java">

public class TestEntityManagerProvider {

 public static void main(String[] args) throws InterruptedException {
 System.out.println(&quot;Starting hsqldb&quot;);

 new Thread(new Runnable(){
 public void run() {
 Server s = new Server();
 s.setDatabaseName(0, &quot;tacs&quot;);
 s.setDatabasePath(0, &quot;mem:test;sql.enforce_strict_size=true&quot;);
 s.start();
 }
 }).start();

 Thread.sleep(2000);

 final Map props = new HashMap();
 props.put(&quot;javax.persistence.jtaDataSource&quot;, &quot;&quot;);
 final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(&quot;tacs-diagram&quot;, props);

 final EntityManager entityManager = entityManagerFactory.createEntityManager();

 entityManager.getTransaction().begin();
 entityManager.persist(new Cpe());
 Query q = entityManager.createQuery(&quot;from Cpe&quot;);
 System.out.println(&quot;Results from cpe&quot; + q.getResultList());

 System.out.println(&quot;Sleeping 20 sec&quot;);
 Thread.sleep(200000    );
 System.out.println(&quot;Done sleeping&quot;);
 }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/automated-documentation-and-odfdom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

