Friday, July 16, 2010

XML & Swing... pita

Well, going through this leads to a conlcusion : client / server with Swing & JEE is a bit like crossing the Death Vallyey wihout a bottle of water.

Dream is not reality

Well I tried to build a web service returning a JFrame... isn't that the cool thing about Java reflexion / serialization.....

SEVERE: Cannot initialize endpoint  : error is : Unable to create JAXBContext

Blah blah

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 21 counts of IllegalAnnotationExceptions
java.awt.LayoutManager is an interface, and JAXB can't handle interfaces.

Well the least I can say, making Swing and Server based Java is not always simple...

Thursday, July 15, 2010

My solution to the XmlID XmlIDREF and the object graph reconstruction

At the previous stage, I stopped with a situation where I could  get an entity (a patient) but nothing about a related entity (a doctor). The reason being that to break the serialization loop I used the XmldID and XmlIDREF annotations.

In the soap response I can see the doctor id (2). In Java the doctor field of the patient points to null (because as shown in the previous post, the doctor is not transfered).

By the way in Open ERP I would get not the doctor but at least the in id in the Python object. One more shame on Oracle/Sun stuff.

Anyway, I created another web service that does not return a single patient record but a compound of entities (a collection of patients and doctors) :

public class wsbr {
    private Collection patientCollection;
    private Collection doctorCollection;
    public Collection getPatientCollection() { return patientCollection ;};
    public void setPatientCollection(Collection p ) {  patientCollection = p;};

    public Collection getDoctorCollection() { return doctorCollection ;};
    public void setDoctorCollection(Collection p ) {  doctorCollection = p;};


Building a web service that returns such object and populating properly the two collection makes possible to transfer the entire graph which is rebuilt properly at the client side (automatically).

Here is the soap :

So my solution is to build a big compound referencing object that will ensure that all references will be carried properly.

Wednesday, July 14, 2010

JPA, JAXB ... not finished yet

I could indeed load one entity... but

Here is my result

Clearly the actor is not passed in the response and so my graph of object is not passed...

Here is the thing I overlooked...

"There are a few things to consider when you do this. First, the object to be referenced must have an ID that is unique within the whole document. You'd also need to ensure that the referenced objects are contained somewhere else (like in the Root class in this case), or else Bar objects will never be marshalled. This technique can be used to remove the cyclic references, but it's only possible when your object model has an easy cut point."


GlassFish - JPA & Jaxb

So I am preparing a major rewriting of our last Major App in Delphi. The client side will be in Java - we need at least one Java component for text manipulation. I will come back later on the client as I looked at a lot of nice stuff.

One the server side things are also difficult. My intention is to go to JPA as it is now the standard ORM and will give us portability between DB and probably also a much cleaner code.

The JPA classes were created automatically by Netbeans. Next I created a stateless session bean and finally a Soap Web service (Netbeans created that one from the session bean). It is a lot of artifact... A good thing again, I suppose done by Netbeans, your web service also generate a small web base tester for the service.

Unfortunately I hitted the first issue yesterday...

Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: com.adins.testNISFusion.jpa.Patient[id=1] -> com.adins.testNISFusion.jpa.Actor[id=1] -> com.adins.testNISFusion.jpa.Patient[id=1]]
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(
        at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(
        at com.sun.xml.bind.api.Bridge.marshal(
        ... 56 more

So the session bean works fine but the web service cannot serialize the answer properly because there is a loop in the references (which by the way is the most common things you get in a relational database and these references have been created by Netbeans/JPA).

The solutions are listed here ...

The first one is to make the referenced entity XmlTransient  so basically not referenced any more. It is difficult for me to see this as a solution. May be if your DB is made of non used entities...

The second is to use XMLID and XMLIDREF directive. So instead of serializing recursively JAXB will point to the ID of the other entity.

In my case - I think a common one. The entity being passed through the web service are in fact my JPA entities. So your JPA entitiy gets fields annotated with@ID and @XmlID.

Unfortunately combining JPA and JAXB   creates another issue.

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "id"


I foud a solution here :

Basically, you will put the JAXB annotation on the accessor not on the variable where you put the JPA ones.

So something like :


public class Patient implements Serializable {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)

    public String getId() {
        return id;

Conclusion at this time...
1) It works for now.
2) Netbeans is great and generates plenty of stuff that I will have to modify by hands... :-(
3) JPA stuff is very static but JAXB builds XML at runtime. So you get the worst combination : modification requires compiling and compiling does not shield you from syntax error...
4) I don't like that much annotation. The syntax is ugly. In the case of the transient 'solution', it is hard to imagine that you can solve all the real cases statically. Sometines you need the element, sometines not...
5) A stack is just a stack of boxes as drawn on the marketing docs. It seems little people spend time to make these boxes working really together.  
6) I have been trough a lot of readings, an entire stack of books... Building a web service to pass persistent entity is just basic and yet nobody mentions this issue...This is in my opinion the key drama of this industry. Book writers (as tools builder) rarely  build appications,...
7) It would be great to have a single option for JAXB to tell that we want to use ID and REF...Who knows...

Sunday, July 11, 2010

Welcome to the Online Joomla Community Magazine & What is typekit

A new place to look at for those interested in Joomla :

It is just started and already plenty of well presented resources about web-design and my still favorite CMS for small to medium business.

Yet a good thing I learn via the magazine - Typekit a solution to embed legally and precisely fonts and thus use great typography on your web site - this is not only for Joomla - find the idea behind it on the typekit web site : Not only it solves a need, it is also a great web based business model.

Saturday, July 10, 2010


What can be that script ?

/usr/share/doc/libdvdread4$ sudo ./

Thursday, July 08, 2010

Java RIA... getting impressed by... Apache Pivot

More than a year ago, I wrote a few articles on Apache Pivot. Well, my enthusiasm was very limited.

We are now in the process of re-writting a Delphi based application. Ideally using Java...

We could use simply Swing. But note, that the Swing application framework went back to life before to re-die again...

We checked OpenSwing. It is a good library, which adds a lot of good things on top of Swing. Useful but the look & feel... and a lot of code for just a little app.

To ease things, I looked at Netbeans as a platform. Overkill in many cases and it solved many problem we don't have and ignore those we have... Including we need a short learning curve and  among the big issue dynamic localization - language switching

Also I spent a bit of time reading about JavaFX. Nice little language, but I cannot find anything that looks like an enterprise feature. Again the old Sun syndrom, we found a nice idea, lets market it against inacessible competition and consider our installed based as supreme idiots... bringing them features they never asked.

So I checked again Pivot - now version 1.5 and I AM IMPRESSED.

Documentation is very much improved, so that makes the purpose very much understandable.  Plus you have a bunch of very good examples.

The graphical glitches are gone ! Performance looks pretty good.

Most of the things are there and well designed, Web services, binding, event handling, scripting in the UI definition (any JVM language...).

And yes, a good looking mechanism for static localization.

The design is clean and nice (not very fancy but it is good loooking). It is designed to be skinnable, so we can expect much more funny things sooner or later.

You can build GUI using a straightforward XML based language (the layout can then get transferred to the client and transformed into GUI -> yes in fact this what Open ERP Python APP does...) .

So it is a cool toolkit and it appears much more oriented towards enterprise apps than FX. So my new acronym Rich Enterprise Internet Application that fits for Pivot but no go for FX.

The unfortunate thing... it is not compatible with Swing (I can live with that) but I need a minimal kind of word processor for my app (that I have with Swing and EditorKit stuff). Too bad, nothing is perfect... But keep going Apache Pivot you are heading to the right direction. At least I am getting convinced!

Just a link so you can check (you need Java plugin to get the examples running):

Comments - policy change

I found plenty of comments written in Chineese on my blog. As of now you need to be member to post comment. Also comments are not displayed, so no interest in spamming...

Installing Java Plugin for Ubuntu on 64 bits install

By default Ubuntu will install the Open-JDK in principles it is fine but practically it seems not that well working. What about the Java plugin ... hm not so easy.

The Java plugins for 64 bits architectrue is not in the default repository...

1) So enable the alternate repositories... see the link to info on what to change in Synaptic

2) Then follow the isntruction for java in the following link

3) Close all Firefox Windows
Publier le message

4) good trick for the road... enter in the url text box: about:plugins

Java should now be listed...

Why that? Hm, I swapped the damned fan noisy Vaio CS/31 against an HP Elitebook 8540w. Dual boot + shared /gome using vmware under Windows 7 - I love it... And I am back to evaluation of Java GUI alternatives.

Saturday, July 03, 2010

A Brief, Incomplete, and Mostly Wrong History of Programming Languages

Good IT jokes are not that frequent. So in this starting holidays period, I can recommend you the following blog post from James Iry. I love it

A Brief, Incomplete, and Mostly Wrong History of Programming Languages