users@jaxb.java.net

RE: JAXB compilation plugin

From: Jonathan Johnson <jonjohnson_at_mail.com>
Date: Tue, 14 Feb 2006 15:02:23 -0500

Once I manually obtained jsr173_api.jar and activation.jar I was able to get
xjc to compile code using programmatic calls to XJC2Task. I'm fleshing some
of the parameters and should have a workable version posted shortly. Thanks
for working on getting those jars on the maven repository for JAXB.

I got tripped up on the subtle difference between jaxb2-sources, not
jaxb-sources but last week got the jaxb2-sources and found XJC2Task. All
set thanks.

>> The reason it takes a String and not File nor URL is because it can be
>> both URL or a file. I clarified the xjcTask.html in the docs folder to
>> say accordingly.

Why not have the method just take a URL type and require the "file://"
protocol for local files? Leaving it as a loose string leaves it open to
lots of validation problems. UniversalRL does not have to mean just remote.

>> I also updated javadoc.
Just a suggestion... The XJC2Task has a bunch of missing comments from the
javadoc. Also a few method names use non-standard naming and camel humps.
setXexplicitAnnotation, setDestdir, setFailonerror. I have other questions
about the API but was hoping a revised javadoc would answer the questions.
See
https://jaxb-architecture-document.dev.java.net/nonav/doc/com/sun/tools/xjc/
XJC2Task.html

>> What I actually meant to suggest was to use Ant's parser to parse DOM
>> into Ant task invocation directly, and not programmatically calling
>> XJC2Task methods.

If we want it to look just like Ant then why not use the Maven to Ant plugin
and invoke the Ant task to do XJC?

I was attempting a more M2 native approach by following the other M2 plugin
configuration conventions. For Maven users it might be a step backward to
following the exact Ant configuration. I think we should build on it an
follow the Maven 2 approach for setting the configuration - keeping in mind
that most users of Maven are migrating from Ant. I created a class derived
from XJC2Task that took care of the Ant project and Ant logger problem.
This way if things are fixed in XJC2Task or are added to XJC2Task then the
Maven 2 plugin will hopefully inherit those improvements. It would be
better to abstract all the XJC2Task Ant specifics and put the common
behavior in a common adapter that both the Ant and Maven adapters can use.


-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Tuesday, February 14, 2006 2:19 PM
To: users_at_jaxb.dev.java.net
Subject: Re: JAXB compilation plugin


Jonathan Johnson wrote:
> Kohsuke,
>
> In my progress for creating a JAXB compilation plugin for Maven 2 (should
be
> available in a few more evenings) I started to use the class
> com.sun.tools.xjc.XJC2Task.
>
> When calling:
>
> XJC2Task xjc = new XJC2Task();
>
xjc.setSchema("/development/JAXB-SOURCES/JAXBSample/src/main/resourc
> es/schemas/catalog.xsd");
>
> it produces this NPE inside XJC2Task.setSchema

The source code reads:

     public void setSchema( String schema ) {
         try {
             options.addGrammar( getInputSource(new URL(schema)) );
         } catch( MalformedURLException e ) {
             File f = getProject().resolveFile(schema);
             options.addGrammar(f);
             dependsSet.add(f);
         }
     }

So I suspect getProject() is returning null, hence NPE.


> When I got the cvs source for JAXB-SOURCES the class XJC2Task was not in
> there only XJCTask.

This is often a source of confusion, but JAXB 2.0 source code is in
jaxb2-sources, not jaxb-sources. Sorry for the confusion, but I don't
see any better way.


> The javadoc for XJC2Task.setSchema is a ambiguous because its not clear if
> the String parameter should be a file path name for the schema for, a URL
or
> the actual schema xsd text. The javadoc for setSchema(String schema)
reads
> "Parses the schema attribute."

The reason it takes a String and not File nor URL is because it can be
both URL or a file. I clarified the xjcTask.html in the docs folder to
say accordingly.

I also updated javadoc.

> Should I be using using XJCTask instead? Perhaps I use
> com.sun.tools.xjc.api.Driver to eliminate the ant dependency (no pun
> intendend)?

What I actually meant to suggest was to use Ant's parser to parse DOM
into Ant task invocation directly, and not programatically calling
XJC2Task methods.

But if you are frustrated with using the Ant task, It's certainly OK to
use Driver directly.

--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com