Categories
Hints

JAXB xjc expected element of type …

If you have trouble loading Xml using classes generated by xjc tool (included in JAXB distribution), be carefull and do not define XSD main element like this:

<!-- MAIN element -->
<xs:element name="main" type="Main">
<xs:complexType name="Main">
...

The problem here is that the main element and main element type names are identical (except the first letter that is uppercased). Xjc creates a class for for both root Xml element and all complex types defined in Xsd. In this case a java class that derives from class for xsd complexType would be empty. If you still insist on having java class for xml root element then declare it as a extension without any additions.

Solutions (2):

  • declare xml root element as complexType extension (complexContent/complextType/extension) of the xsd complexType
  • do not define type for root element and define the structure directly in xs:element
Categories
Hints

Java String.isEmpty interrupts method call or thread

Does your call of String.isEmpty in your code cause strange behaviour such as:

– sudden interruption of method call (as if return was called)

– thread interruption

?

The problem is quite simple – you had build your code using JDK 1.6 with language compatibility set to previous version (1.4, 1.5) hoping the compiler would use the correct classes. This is, however, not true.

When you use the version switch the current JDK classes signatures are used. That means isEmpty is present as method of String class in 1.6. It is not present in previous releases.

Solution: Remove call of isEmpty and use the JDK you need without language compatibility to build against required version.

Categories
Software & Development

axis2 codegen wizard (Eclipse) – InvocationTargetException

There is a known problem with InvocationTargetException when you press Finish button in Eclipse’s Axis code generation wizard. I don’t know why there is no newer version available, however the steps are pretty straightforward. There is also a ready to deploy zip file available here. However, you have to register to download it.

I had trouble following the steps, because there is no backport-utils package anymore in axis2-bin/lib directory. Also, I tried to register the jar in plugin.xml over and over again just to find out that stupid PSPad didn’t save the changes, because there are windows7 permission and stuff.

By the way, funny thing is that the directory name is 1.3.0 even for version  1.4.1..

So, if you are as lazy as me, here get the fixed Axis2_Codegen_Wizard_1.4.1. Yes, it is a direct link, no more stupid forums where you need registration and wait 7 days until you are allowed to do anything.

 

DOWNLOAD

 

NOTE: please note there is a version 1.6.2 of the plugin that works just fine!

Categories
Software & Development

Xalan Xsl and Lookup tables

If you don’t know what is a lookup table in context of Xsl transformation you might like these short example articles here or here

The common way to use lookup tables in Xsl transformations is to use select=”document(”)/*/data/” syntax. If there is no path provided and the parameter of document() function is string, the function returns the reference to the stylesheet itself. However, this is not true for all Xsl transformation libraries.

In case you use Xalan and the document is loaded from database, you might get into trouble – the function will not find anything. The workaround is to load a different Xml document by calling document(‘data.xml’). Yes, there’s a but too. Xalan will look for the document in the java application startup path, not in the same location as the Xsl stylesheet, nor in the path of Xml document being transformed (it is in database, you remember, right?). In case your application is a web application running in Apache, the startup path is apache/bin