users@jaxb.java.net

AW: Re: AW: Re: SAX-like JAXB?

From: Ernst, Matthias <matthias.ernst_at_coremedia.com>
Date: Wed, 30 Aug 2006 10:23:43 +0200

Kohsuke Kawaguchi wrote:
> Also, is there any reason you chose to create XMLReader by
> yourself? The
> following code can be as simple as

> for (String arg : args) {
> unmarshaller.unmarshal(new File(arg));
> }

Right. I copied the code from the partial-unmarshalling sample and I
kind of liked that this way makes it clear we're talking
"push" here and there is no result (as from unmarshal). But in terms
of terseness #unmarshal is preferable. In general I find the JAXP APIs
too verbose. Why no static void SAXParser.parse(input, namespaces?,
ContentHandler). That would probably cover 90% of all uses. But I
digress.

> I see. What if we let you unmarshal into an existing instance of
> PurchaseOrders object? (As opposed to have the JAXB RI allocate a new
> instance.) That's a useful feature on its own.

It would be useful for some cases. But even more useful: how about you
let me create
any object in the first place? Such as

unmarshaller.setFactory(PurchaseOrders.class, new
Factory<PurchaseOrders>() {
  public PurchaseOrders newInstance() {
    return new PurchaseOrders(listener);
  }
});

That would allow me to create special implementations and inject
dependencies at any point in the object graph.

One more thing: why didn't you create an interface for the per-class
[un]marshalling hooks? Matching methods by name and signature isn't
exactly good Java style imho.

Matthias