[Tutor] python and java report writers

Oxymoron moron.oxy at gmail.com
Mon Aug 17 22:00:23 CEST 2009


(Sent to John only by mistake, now sending to list. Sorry John!)

On Tue, Aug 18, 2009 at 5:48 AM, Oxymoron<moron.oxy at gmail.com> wrote:
> Hi John,
>
> On Tue, Aug 18, 2009 at 4:31 AM, John<jfabiani at yolo.com> wrote:
>>
>> I'd like to understand how python can integrate with Java in general and then
>> how it would work with the Java report writers.  I have read a little about
>> jPython but do not understand how to make that work with my python programs.
>> It would appear to me it is a way to replace python.  I don't want to replace
>> my python code.  I want to just call a java report writer.  Passing either
>
> I can't comment on Python reporting libs - best to google around -
> since I have not worked with them. Hopefully someone more experienced
> can give alternatives for this. It's definitely worth the effort if
> you can use (C)Python natively.
>
> Since you mentioned Java and Jython however, a few things to consider
> on the Java side of the equation (may be a little off topic, I
> apologise):
>
> 1. Jasper is a java library for reporting as you have discovered. It
> is meant to be fairly declarative - there should be minimal
> boilerplate code or config or wrapper objects for basic cases, the
> bulk of the work would be in designing your report -- an XML report
> definition file.
>
> One complication I can think of with Jasper (best to check doco and
> ask on the Jasper list for more!), is that it has the idea of
> datasources - essentially classes representing data to display on the
> report, Jasper provides some default ones - if you need something
> specialised, then you will need to write your own (implement an
> interface or extend a Jasper base class), you can do this using
> Jython. My use case at the time was that I had to much data (from an
> RDBMS) to load up into memory at one go - and Jython's default source
> implementations did not help, so we had to write our own, again not
> too nasty, just not out of the box. Things may have changed.
>
> 2. Jython is a Python _language_ implementation in Java, and as such
> allows calling Java code seamlessly in both directions. To be more
> precise, both Java and Jython code are compiled to JVM bytecode, and
> share JVM semantics, it is no longer about the language at that point
> - just what the runtime understands - needless to say Jython will have
> various 'tricks' so that the more dynamic side of Python can fit into
> the statically typed JVM model.
>
> Another way of looking at it is that Jython is an alternative Python
> syntax on top of Java libraries (and of course, to write Jython code).
> In other words, you can rely on Jython being Pythonic as far as the
> language is concerned, but it may not support the standard library (or
> only partially support it or is work in progress!) as you see on
> CPython docs. It is meant to leverage off the existing Java libraries.
> Native python types such as lists are automatically converted to the
> JDK standard collection libraries (such java.util.List/Map impls,
> etc.) while retaining (obviously) Python syntax and behaviour (as far
> as possible) for the core language.
>
> Essentially if you wish to use a Java library (and I have only ever
> used Jasper, so caveat emptor):
>
> 1. See if there already is a Java wrapper someone has written that you
> can call as an external process - reports can be very simple or crazy,
> so not sure how feasible this is, especially considering the diversity
> of data sources and presentation, or maybe a GUI Jasper (or whatever
> else) report designer of sorts that does this, generates config, etc.
> - sourceforge may be a good place to search.
>
> 2. You could call Java libraries using Jython (and thus not have a
> syntax barrier at least), and create your reporting process that you
> can use as an external process, passing in params, and getting out a
> value etc. It will take some effort for sure, because most examples
> for using Jasper will be Java-based, and you would need to translate
> this to Jython (or copy and paste). Having said that, once you get a
> basic test harness up and running, Jasper's complexity will be in
> defining reports in XML, nothing very Java specific.
>
> You _may_ need to be aware of things like Javabean conventions (also
> called properties, where tooling considers x.getFoo() and
> x.setFoo(bar) to have the shorthand notation to x.foo -- these may
> impact the Jython classes you write - method names will need to follow
> conventions to be referred to from the XML as properties (it's been a
> while since I used Jasper, so do read up again if you go down this
> path - can't remember if it was just something we did). Java to Python
> translation is straightforward for most cases, just ignore the type
> prefix on Java variable declarations (except of course to refer to the
> Javadoc!) :-).
>
> So yes, you cannot call Jython/JVM bytecode from Python or vice versa
> as easily as you would your own Python modules, since they are in
> different formats, interpreted by different processes (python vs JVM).
> Jython is nice however in that it supports on the fly compilation as
> per regular Python code, you will not need an explicit compilation
> step as with regular Java code. Java environment-wise, it has the
> notion of classpath -- you will need to ensure that the Jasper
> libraries (JAR files) and any dependencies (other JAR files!) and your
> own files, are on the classpath (Java and Jython files are converted
> to 'class files' containing the JVM bytecode). Basic Java tutorials
> will explain how to set-up the classpath.
>
> Enough about Java on a Python list before I get banned :-).
>
>
> Regards
> Kamal
>



-- 
There is more to life than increasing its speed.
 -- Mahatma Gandhi


More information about the Tutor mailing list