Tuesday 15 July 2008

Code Generation with XSLT

Last week I read a nice article of my con-colleague Lucas Jellema about “PL/SQL Table-to-Java Bean (and Data to Java Bean Manager) generator - useful for data driven demos without database ” at the AMIS-blog on:http://technology.amis.nl/blog/?p=3272.

In this blog Lucas writes how he generated java-code from Pl/Sql. It drew me back to a little project I did for myself and my former employer as a BusinessDevelopment-job. I wanted to make a simple method to enable a convential custom development application, like a Designer/Developer Forms application, like we build a million times in the past. Since it is primarly aimed for the hundreds of Forms applications at our customers that are primarly build with Designer and Headstart, I could do it in pl/sql also or even create a Headstart utility for it. But for the latter option I would learn myself Headstart-utility principals again, that did not look to useful for me. Pl/Sql would do. But I would have it flexible having the ability to generate several pieces of code from one source.

The problem with the code of Lucas, that is when you see it as a problem, is that all the code generation is in pl/sql. To change the outcome would mean that you should change your pl/sql code. I would like to have a more template-based solution.

A few years ago I wrote an article on “XML using Sql” for our monthly consulting paper at Oracle. See my post: http://darwin-it.blogspot.com/2008/07/xml-using-sql.html. With this knowledge it is easy to generate XML out of the datadictionary of the database. Then based on this xml you can generate all you want using ... XSLT.

Read further (pdf).

Thursday 10 July 2008

XSLT in Java with Oracle Parser part 2

Earlier I explained how to do an XSLT transformation using the Oracle Parser: http://darwin-it.blogspot.com/2008/06/xslt-in-java-with-oracle-parser.html.
I also created a Java Swing application to do transformations. I unfortunately found that my transformations did not went as expected. I'm busy with doing an XML to HTML transformation and my HTML tags did not get transformed. It works fine when the result of the transformation is just plain text.

The problem lies in the use of a XMLDocumentFragment as a result type of the xslProcessor.processXSL XSL processing. It took me a while to find a solution, since I have the requirement that the result gets into a String.

The xslProcessor has some processXSL methods that output to for example a URL or a PrintWriter. But how to get that into a String again?

Luckily today I found the solution. You have to wrap a StringWriter into a PrintWriter. Then give the PrintWriter to processXSL. Then after closing both, you can simply do a toString of the StringWriter. It looks like this:

public String transform(XMLDocument xslDoc, XMLDocument xmlDoc) {
XSLProcessor xslProcessor = new XSLProcessor();
XSLStylesheet xslt;
String result = "";
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
xslt = xslProcessor.newXSLStylesheet(xslDoc);
xslProcessor.setXSLTVersion(xslProcessor.XSLT20);
xslProcessor.showWarnings(true);
xslProcessor.setErrorStream(System.err);
xslProcessor.processXSL(xslt, xmlDoc, pw);
pw.flush();
pw.close();
sw.close();
result = sw.toString();
} catch (XSLException e) {
pl(e.toString());
} catch (IOException e) {
pl(e.toString());
}
return result;
}


I adapted it to my XMLTester tool that I just uploaded here.

Object Oriented Pl/Sql

Another article that I wrote a few years ago is about Object Oriented Pl/Sql. It's also in Dutch and downloadable here.

XML using SQL

A few years ago already I created an article that explained how to generate XML using Oracle SQL. It works from Oracle 9iR2,10g onwards. It's in Dutch, but it contains step-by-step examples so maybe also usefull for non-Dutch.
You can download the article here.

Wednesday 9 July 2008

Total Commander, Irfanview, Notepad++ and Open Workbench in Wine

A few weeks ago I installed Wine Doors, that helps you with installing Windows applications under Wine. I found that it should install Total Commander, my favorite File management tool under Windows. I work with it for years, even bought a license for it. Unfortunately there is a bug in Wine-doors so that Total Commander and also Irfanview do not install correctly.
Luckily it is not to hard to install those tools by hand.

First Totalcommander. Download it from: http://www.ghisler.com/. Then start the installer by typing 'wine tcmdr703.exe' in the terminal. Or start tcmdr703.exe with wine.
This installs Total commander in the default wine-bottle. By default Total Commander installs in the c:\totalcmd folder. I don't like that, so I always change it to c:\Program Files\totalcmd.
The installer then turns out have difficulties in creating the menu-items. So you have to take care with that yourself. The command that you should provide in the menu-item is: 'wine ~/.wine/drive_c/Program\ Files/totalcmd/TOTALCMD.EXE'.

Irfanview was my favorite Graphics viewer under windows. It's nice to have it under Linux too.
To install irfanview is also easy. You could install it the same way you did with TotalCommander. But I found it easier to start TotalCommander and then just doubleclick on the irfanview installer. Easy does it.

The same counts for Open Workbench. Besides Microsoft Project (that is licensed) Open workbench is the only serious project managers tool that I know. I tried a few Linux tools (Ganttproject, KPlato) but they lack some basic functionalities. Like give in how much a task costs in terms of hours and doing baselining, scheduling etc. Ganttproject however does have an export to Microsoft Project, but I did not try that. It's in java so it should work in Linux aswell as under Windows (a bat file is provided).
To install Open workbench is also very simple. Double click on it from Total Commander. It appears neatly in your menu. You should also install a Java Runtime Engine. I just installed JRE 6 update 7 from http://java.sun.com/javase/downloads/index.jsp. For me there is no need to install the complete jdk. That I have available under Linux. After installing that one under Wine Open Workbench starts fine.

Now I tried to install Notepad++. A fine ascii-editor that is much more usefull then Notepad and a real advantage to have it the default editor of Total Commander.
I first tried the new 5.0 version but that aborts with an exception. But the previous version 4.9.2 works fine.

Tuesday 8 July 2008

New: the PoPoToPi!

The very main reason for me to write this blog-entry is to introduce a new word: Popotopi. I would love to see this home-made word pop-up in upcoming discussions over the world. To be honest, I used another word for it: PoJo: Plain Old Java Object. The word PoPoToPi means Plain Old Point To Point Interface. I like the word, because of its cadens, how it rolls over your lips.

Ok, another reason then: to explain one of the questions I'm currently involved in. My current customer has just celebrated the first aniversary of their EAI department. That means they have been busy with integration for quite some years. Mainly on Tibco. But now they have some projects going around introducing two other ESB/Soa platforms, one of them being Oracle SoaSuite. This drives them to think about integrating the integration platforms. How to exchange services, what is the scope of one integration environment, how to define bridges etc.

Looking into this I also discovered that they have several environments of their current Tibco Platform, because of having several domains. One of the colleagues I have in this department is catagolizing the services of one of the domains. His impression is that about 80 percent is just point to point. Although most of them are neatly defined using a so-called Canonical Data Model.

Having a Canonical Data Model is nice. It's just like the Hub-and-Spoke architecture of Oracle's Industrial Archeology Artefact: InterConnect. InterConnect was technical not a very sophisticated product. But the whole idea behind InterConnect I do like still. The Common View in InterConnect, that is the Canonical Data Model, is the abstraction on message level between end-points. It is based on Logical Entities on which you map the physical entities of your Enterrpise Information Systems (EIS).

But if you conclude that 80% of your integrations is point to point then you should think about how successfull you were in implementing EAI (Enterprise Application Integration).
A coupling is point-to-point if the two end-points are not re-used anywhere. Although the coupling uses a Canonical Data Model, the business event that is based on the CDM is not re-used. The reuse and thus the advantage of this approach only pays-off when you subscribe another end-point to the business event in the hub, if you have another application publish the business event or when you decide to replace one of the end-points without modifying the CDM.

Although the couplings are based on a CDM it is very interesting to compare the different CDM's (the message definitions) of the different integrations. As said: a CDM should be based on logical entities. This Logical Entities should also be reused over the different integrations. For example: an order in the "CreateOrder" integration should be the same in the "UpdateOrder" integration.

Drilling down in to the Logical Entities, it should also be interesting to reuse parts of the Logical Entities. For example: the address of a person, a customer, a supplier or an organization, be it a home, billing or shipping address, should be allways the same in structure. Actually a person being a customer or a supplier or a TradingPartner's contactperson is allways the same in structure.

It would be very interesting to see to what extent the standardization on CDM's is put through. Honestly, it would surprise me if there are not more then one definition of whatever Logical Entity in the different interfaces.
Every coupling, integration is defined and implemented in different projects. Only if a project-member does know of the existance of a reusable artefact and/or if there is budget to make artefacts generic enough, a project might leverage the advantage of EAI or feed the potential of it.

If every Logical Entity is neatly defined only once ever, especially when it is describe in a central library of artefacts, that would be great. Then you could say that you were quite succesfull in implementing a sufficient EAI.

If not, you can't speak of a succesfull, efficient EAI. Then, to me, you have implemented Popotopi's on a modern platform, where so-called services are not much more then simple building blocks (not services). But ask yourself and decide for yourself if it was worth the investment.

It is too bad, because a good EAI with uniquely, accurately, correctly and completely described buildingblocks, triggers, CDMs and message-object-mappings could be a very good base for the implementation of a SOA. Where a buildingblock could really be a service, a trigger could really be a Business Event in your Event Driven Architecture and the CDM's and mappings a base for your Enterprise Business Objects with their transformations.

I used to do Quick Scans on the performance of Custom Development Applications. It would be nice to do such a scan on EAI implementation to see what the impact on the implementation of SOA is in such a case. Or at least to think about it along with a customer.