users@jaxb.java.net

Re: "JAXB creates uncompilable ObjectFactory.java" OR "handling huge XML schema"

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 21 Apr 2011 17:18:49 +0200

There is evidence (
http://marxsoftware.blogspot.com/2010/01/reproducing-too-many-constants-problem.html
) that "too many constants" results from more than 65535 methods in a
class. This ObjectFactory.java doesn't have as many -- my estimate
from the line count 287163/8 = 35895 -- but there's an annotation with
each method.

The JVM defines a class header to contain (u2 = unsigned 2 bytes)
   u2 constant_pool_count;
    ...
    u2 methods_count;
So it's a hard JVM limit.

First proposal, based on the observation that many literals occur
repeatedly. Count the string literals. If they exceed 65535, try this:
replace
"xmlapi_1.0" by xmlapi_1_0 and add the declaration of a final static
String xmlapi_1_0. It's of course easy to do this with a script.

My second proposal would be to transform (using XSLT) the XML schema
itself, which would be based on the observation that many, if not all,
element names are "qualified" with something that closely resembles a
package name, e.g., "equipment.DaughterCardSlot",
"l3fwd.ServiceSite.getVrfTargets". Apparently there is more than one
XSD file, and this might simplify this task.

Actually, this naming suggests (to me) that originally there *must*
have been some form of package structure. It seems that the entire
shebang is for the representation of some (Java) API which itself is
well-structured. But, rather than dividing the generated xsd into
reasonable chunks, it all went into one package. (One might expect all
sorts of troubles when trying to program with this nasty gob of code.)

Cheers
Wolfgang


On 20 April 2011 19:01, Valentine Mayamsin <yavalek_at_gmail.com> wrote:
>
> By request, I start discussing the bug: http://java.net/jira/browse/JAXB-830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=307246#action_307246
>
> I tried to compile huge schema, there are ~13MB of XSD files. It compiles into java files fine, but I when I try to compile these files, javac crashes with the following error:
>
> $ javac -d bin/ src/x0/xmlapi1/*
> ObjectFactory.java:32: too many constants
> public class ObjectFactory {
> ^
> 1 error
>
> $ wc ObjectFactory.java
> 287163 1028666 15104373 ObjectFactory.java
>
> I tried to hack javac to increase the limits. It compiles fine, but java VM by itself doesn't recognizes this file. Obviously, hacking JVM is not a good idea.
>
> Martin Grebac suggested to customize generation of such large schema to different packages, but looks like it's impossible to split the schema into different packages without modifications since it is provided by 3d party vendor. According to the documentation (http://jaxb.java.net/guide/Customizing_Java_packages.html):
>
> "Note that this customization is per namespace. That is, even if your schema is split into multiple schema documents, you cannot put them into different packages if they are all in the same namespace."
>
> Here is a sample ObjectFactory class: http://pastebin.com/81Kn0UQs
> So, is there any way to split this ObjectFactory into several classes/packages or any other ideas?
> Thank you!