Saturday, August 09, 2008

Visual words definition

Today I know the existence of this amazing page: Visuwords.
I think it is one of the most original things I can see in many time.

Thursday, August 07, 2008

Using JAXB to generate KML Java classes

Some days ago I write a post about using JAXB with the KML's XSD file.
Due to a comment I would like to write more explicitly how I generated the Java files.

First of all, what you need is the XSD files which defines the KML syntax (http://schemas.opengis.net/kml).
Also, you need the xjc utility, included in the JDK6 (or download the JAXB project files).

Uncompress the XSD zip file and go into the uncompressed folder. Execute:
xjc -xmlschema -verbose -extension ogckml22.xsd
and get an error similar to this:

[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 1058 of file:kml_files/ogckml22.xsd

[ERROR] (Related to above error) This is the other declaration.
line 255 of file:kml_files/ogckml22.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 350 of file:kml_files/ogckml22.xsd

[ERROR] (Related to above error) This is the other declaration.
line 261 of file:kml_files/ogckml22.xsd


The problem is there are two scale elements defined, one like 'scale' and the other with upper case 'Scale'. And the same for the snippet element.
By default, JAXB uses case insensitive which will produce duplicated class names.

To resolve this there are some solutions. One is to customize the JAXB specifying the class name to be generated for some elements. The later is a workaround (that I used) that consist to change the name for one of the duplicated elements.
In line 255 change:



by




and in line 1391 chage:



by




The same for the snippet element.

Now you can re-execute the xjc command and a set of Java classes will be generated. The only difference is the change in the scale element which produces a different class name.