<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8820733374008593966</id><updated>2011-04-21T14:48:38.289-04:00</updated><category term='java reporting'/><category term='birt'/><title type='text'>Along Came Betty</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://darevay.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8820733374008593966/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://darevay.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>dr</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8820733374008593966.post-7929279715721988417</id><published>2008-11-24T10:34:00.000-05:00</published><updated>2008-11-24T10:36:28.371-05:00</updated><title type='text'>Moving</title><content type='html'>I'm moving this blog to &lt;a href="http://blog.darevay.com"&gt;http://blog.darevay.com&lt;/a&gt;.  Bye blogger.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8820733374008593966-7929279715721988417?l=darevay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://darevay.blogspot.com/feeds/7929279715721988417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8820733374008593966&amp;postID=7929279715721988417' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8820733374008593966/posts/default/7929279715721988417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8820733374008593966/posts/default/7929279715721988417'/><link rel='alternate' type='text/html' href='http://darevay.blogspot.com/2008/11/moving.html' title='Moving'/><author><name>dr</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8820733374008593966.post-8692034355266232432</id><published>2007-11-01T08:42:00.000-04:00</published><updated>2007-11-01T22:29:19.293-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java reporting'/><category scheme='http://www.blogger.com/atom/ns#' term='birt'/><title type='text'>Scripted Data Sources with BIRT</title><content type='html'>I recently started experimenting with the &lt;a href="http://www.eclipse.org/birt/phoenix/"&gt;BIRT &lt;/a&gt;reporting engine for Java. It seems pretty powerful, well-designed, and has a nice report design tool implemented in Eclipse.  Since the project I'm working on doesn't have a database, I decided to use BIRT's &lt;a href="http://wiki.eclipse.org/index.php/BIRT/FAQ/Scripting"&gt;scripting data sources&lt;/a&gt;. These allow you to create a (hopefully) small JavaScript glue layer between the reporting engine and your &lt;a href="http://en.wikipedia.org/wiki/POJO"&gt;plain old Java objects&lt;/a&gt;.  The purpose of this post is to cover some of the gotchas I've encountered so far.&lt;br /&gt;&lt;br /&gt;The basic idea is that you implement a few JavaScript callback methods that feed row-like back to the reporting engine. BIRT uses Mozilla's &lt;a href="http://www.mozilla.org/rhino/"&gt;Rhino&lt;/a&gt; JavaScript engine. Since the typical use case for BIRT is a database backend, the documentation for the scripting interface seems harder to come by. The FAQ helped, but didn't answer all of my questions.&lt;br /&gt;&lt;br /&gt;First, all of the &lt;a href="http://tools.osmosis.gr/blog/archives/2005/06/birt_and_object.html"&gt;examples&lt;/a&gt; retrieve their "model" from a static factory method called from JavaScript. This isn't that realistic. How do I pass my model in to the JavaScript? Or at least a parameter like a filename?  I think part of the reason all the examples take this approach is so that it's possible to run the report at design time with the preview window. I did some &lt;a href="http://www.google.com/codesearch"&gt;digging&lt;/a&gt; and eventually found the right calls:&lt;br /&gt;&lt;pre&gt;   MyModel model = ...;&lt;br /&gt;  IRunAndRenderTask task = engine.createRunAndRenderTask(design);&lt;br /&gt;  Map parameters = new HashMap();&lt;br /&gt;  parameters.put("model", model);&lt;br /&gt;  task.setParameterValues(parameters);&lt;br /&gt;&lt;/pre&gt;Cool. Now my model's being passed to the engine. But wait. How does BIRT find my classes? I know it's built on top of Eclipse which means the classpath is not as simple as you'd like. In some examples I found, you have to manually copy your compiled class files to a directory in one of the BIRT plugins. Uggh. This is a pain, but acceptable for deployment. But during development? I might as well go back to C++ if I want to waste that much time.&lt;br /&gt;&lt;br /&gt;Some more searching dug up this &lt;a href="http://wiki.eclipse.org/index.php/BIRT/FAQ/Scripting#Q:_Where_do_I_have_to_put_my_classes_in_order_to_access_them_by_JavaScript.3F"&gt;FAQ&lt;/a&gt; question. It lists too yucky solutions and then has a tacked on snippet of code that looks promising.&lt;br /&gt;&lt;pre&gt;   config = new EngineConfig();&lt;br /&gt;  HashMap hm = config.getAppContext();&lt;br /&gt;  hm.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,MyClass.class.getClassLoader());&lt;br /&gt;  config.setAppContext(hm);&lt;br /&gt;&lt;/pre&gt;However, I guess I think this is for the version of BIRT I'm not using because it doesn't work. Some more digging and I come up with this:&lt;br /&gt;&lt;pre&gt;   IRunAndRenderTask task = engine.createRunAndRenderTask(design);&lt;br /&gt;  HashMap contextMap = new HashMap();&lt;br /&gt;  contextMap.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,&lt;br /&gt;                 MyModel.class.getClassLoader());&lt;br /&gt;  task.setAppContext(contextMap);&lt;br /&gt;&lt;/pre&gt;I guess the app context stuff moved from the task to the engine at some point. Anyway, now we can finally try it out.  I set up my &lt;span style="font-weight: bold;"&gt;open&lt;/span&gt; callback in Java and... wait, how do I actually get to my model in the JavaScript code? This wasn't too tricky to figure out. The parameters passed to the engine above are passed to the JavaScript code in a global (?) parameter aptly named &lt;span style="font-weight: bold;"&gt;params&lt;/span&gt;:&lt;br /&gt;&lt;pre&gt;    model = params["model"];&lt;br /&gt;&lt;/pre&gt;Nice. Now I write some more code to call some methods on the model and run it and... &lt;span style="font-weight: bold;"&gt;NullPointerException.&lt;/span&gt; This is where I was stuck for a little while. I thought that I had screwed up the class loader stuff or something so I fiddled with that stuff for a while. Eventually, when I was about to give up, I stumbled upon &lt;a href="http://dev.eclipse.org/mhonarc/lists/birt-dev/msg04771.html"&gt;this bug report&lt;/a&gt; which, although it doesn't mention a NullPointerException, does mention a "display name" which I had noticed references to while poking around in the debugger after my crash.&lt;br /&gt;&lt;br /&gt;The trick is that the &lt;span style="font-weight: bold;"&gt;params&lt;/span&gt; variable in JavaScript doesn't hold just my model, but an extra wrapper object with a display name and &lt;span style="font-weight: bold;"&gt;value&lt;/span&gt; is stuck in there. I revise my code to look like this:&lt;br /&gt;&lt;pre&gt;    model = params["model"].value&lt;br /&gt;&lt;/pre&gt;and voila, I run it again and my report is generated as expected.&lt;br /&gt;&lt;br /&gt;Hope this is helpful to someone else out there.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8820733374008593966-8692034355266232432?l=darevay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://darevay.blogspot.com/feeds/8692034355266232432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8820733374008593966&amp;postID=8692034355266232432' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8820733374008593966/posts/default/8692034355266232432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8820733374008593966/posts/default/8692034355266232432'/><link rel='alternate' type='text/html' href='http://darevay.blogspot.com/2007/11/scripted-data-sources-with-birt.html' title='Scripted Data Sources with BIRT'/><author><name>dr</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry></feed>
