users@jaxb.java.net

Re: Supplying a custom CodeWriter

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 4 Dec 2007 11:40:54 +0100

Hi.

> I find the need to control where/how things are written by the
> CodeWriter so I'd like to be able to supply my own class that implements
> the CodeWriter interface. Looking at the Driver class (and OptionsEx) I
> can't see how I could hook in a custom CodeWriter. OptionsEx is created
> by Driver with no way to override it, and Driver calls
> OptionsEx.createCodeWriter() which has a hard-coded codewriter
> implementation it creates.
>
> This means I can't supply a custom OptionsEx to override
> createCodeWriter() and I can't set some property/argument to have
> OptionsEx use a different class.
>
> Any pointers? It seems like a deliberate (good) decision to pull out the
> functionality for controlling where/how an OutputStream/Writer is
> created for each class but seems odd that this functionality cannot be
> customized with a custom implementation. Is this just a configuration
> oversight?
>
> Is there another class other than Driver that I should be looking at for
> doing Schema to Java?


First of all, two questions. What JAXB version (1 or 2) and which
build tool/plugin (ant, maven-jaxb1-plugin, maven-jaxb2-plugin) do you
use?

In maven-jaxb2-plugin we don't use the driver. We create the code
model and then "build" it using an own code writer:

                        if (getWriteCode()) {
                                if (getVerbose())
                                        getLog().info("Writing output to: " + xjcOpts.targetDir);

                                model.codeModel.build(new JaxbCodeWriter4Mvn(xjcOpts
                                                .createCodeWriter()));
                        } else {
                                if (getVerbose())
                                        getLog().info("Code will not be written.");
                        }


Bye.
/lexi