users@jaxb.java.net

Re: JAXB compilation plugin

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 14 Feb 2006 11:19:12 -0800

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