|
Val's Blog
Lots of stuff for Web 2.0 freaks and Java addicts
|
|
|
C.A.R. Hoare: "The unavoidable price of reliability is simplicity." |
[ Login ] |
|
TrackBacks[0]
Comments[0]
Posted by val on April 29, 2005 8:23:04 AM CEST
The third edition of the Java Language Specification (JLS) has just came out of the oven five years after the publication of the second edition. Needless to say that this new release contains the largest set of changes since the inception of the Java programming language. It includes all the novelties that have been incorporated in the latest Java 5 release, such as generics, enhanced for loop, autoboxing, typesafe enumerations, varargs, static imports and metadata annotations. Finally, a third breath for all Java professionnals!! You may get a feel of what's in there before the printed book hits the store by dowloading the PDF edition (6173 KB) on Sun's website. Happy reading :)
TrackBacks[0]
Comments[0]
Posted by val on April 19, 2005 5:10:06 AM CEST
In a previous installment, I wrote about the problematic of effectively piloting Microsoft Word from a Java application. The solution was a little bit clumsy but it worked fine for the needs I had at that time. The idea was to create a Word template and to define bookmarks within the document that would act as anchors that could be referenced from within my Java application. Then, Java calls would be forwarded to Word using some sort of native Word wrapper accessible as a Java proxy. That's it... A couple minutes and I could generate Word documents. Lately, I was in need of a similar solution for the Microsoft Excel application. I investigated Apache's POI project, which seemed fine at the first glance. The only problems with POI were that:
I found a cool and very powerful, yet commercial and somewhat costly, solution, called Intrinsyc's J-Integra for COM. You might wonder, "why the hell is he talking about a $200 product"? Well, $200 is not that much once you discover all the things you can do with the product. Another important thing: this is not an advertisement message, I don't have anything to do with Intrinsyc. I'm just reporting my experience. Anyway... Let's get to the real stuff...
With J-Integra's Within your Java application, you can then use the generated proxies to pilot Excel and carry out any operation that can be performed using the Excel application itself since the proxies have been automatically generated from the Excel COM components, and thus, provide all functionalities available in Excel. Concretely, you can:
Moreover, one big plus of J-Integra's COM bridge solution over Apache's POI API is that the user can interact with the Excel file while it is being generated, which means that you can get user input in real-time and handle it accordingly in your Java business logic. For instance, initiating an interaction with Excel is as simple as the following code piece: excel.Application app = new excel.Application(); excelApp.setVisible(true); Then, you can get workbooks and create a new worksheet with the following code: Workbooks workbooks = app.getWorkbooks(); Workbook workbook = workbooks.add(null); Sheets worksheets = workbook.getWorksheets(); Worksheet sheet = new Worksheet(worksheets.add(null, null, null, null)); Once you have a handle on the worksheet, you can easily populate values within a given range as denoted by the following code:
Range range = sheet.getRange("B2:D4", null);
Object[][] newValues = {
{ "Hello", new Boolean(true), new Double(Math.PI)},
{ new Date(), new Long(1234567), new Float(Math.E)},
{ new Boolean(false), "World", new Date()}
};
range.setValue2(newValues);
Finally, once you are done populating your sheet, you just close the workbook and clean the environment: workbook.close(new Boolean(false), null, null); app.quit(); com.linar.jintegra.Cleaner.releaseAll(); That's as easy as it gets, isn't it? The biggest negative point I can mention is that 80% of the method parameters in the generated Java proxy classes are of type java.lang.Object and the provided documentation doesn't say much as to what kind of object a given method is expecting as argument. To illustrate this, let's take the method we used above to add a new worksheet.
worksheets.add(null, null, null, null);
In the Worksheets class, the signature of this method is: public Object add(Object arg1, Object arg2, Object arg3, Object arg4);Not really self-explanatory as you can see... If you stick with the most commonly used functionalities, you are fine as the examples provided in the documentation are good enough. But as soon as you delve into more complicated matters, such as charting, then you are in trouble. Personally, I had to browse through their knowledge base and look for articles and white papers. I also had to swim across the 9,000+ messages available in their Yahoo discussion group in order to dig out some basic information. Plus, icing on the cake, by decompiling the generated proxies I could finally infer what a given method was expecting... Not really developer-friendly, I admit, but in a matter of one day, I could create very nice and dynamic charts in Excel. To conclude, J-Integra brings you the full power of COM right into the Java world. I would also like to mention that J-Integra not only enables Java-to-COM (i.e., C++, ATL, MFC, VB) communications but also COM-to-Java interactions, which means that your C++ and VB applications can talk to your Java programs, such as servlets, EJBs, JMS topics and queues, etc. As you can see, J-Integra allows one to join the best of both worlds into a single and homogeneous whole, which can thus benefit from COM performance and Java flexibility and elegance. Don't throw POI out of the window, though, that API is true gold as well and will probably fit many of your needs.
TrackBacks[0]
Comments[11]
Posted by val on April 7, 2005 11:06:01 AM CEST
TrackBacks[0]
Comments[1]
Posted by val on April 5, 2005 3:45:47 PM CEST
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Content © Val | Powered by Pebble 1.9.1 |