<?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; ODFDOM</title>
	<atom:link href="http://www.code3.dk/tag/odfdom/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>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>

