users@jaxb.java.net

RE: Avoid both JAXB2 binding as well DOM creation for a document fragment?

From: Ernst, Matthias <matthias.ernst_at_coremedia.com>
Date: Mon, 21 May 2007 17:20:06 +0200

Andreas,

I don't think this is possible right now. Internally, JAXB is push-based (stream reader is immediately
bridged onto a push API), so direct access to the StreamReader would be hard. The only possible
implementation I could imagine that wouldn't require a whole lot of work is to get JAXB (through a new
implementation of the Loader class) to push events into a user-provided SAX ContentHandler, a la

Wrapper {
  @XmlAttribute
  public String attribute;

  @XmlElement
  public MyHandler body;
}

where while unmarshalling, if MyHandler implements SaxResult, JAXB would push SAX events into it.
Access to the surrounding context and handler implementation could be established through an Unmarshaller.Listener.

Likewise, if MyHandler implements SaxSource, JAXB could use it while marshalling.

Highly handwavy, and certainly not without changes to JAXB.


Cheers
Matthias

-- 
matthias.ernst_at_coremedia.com
software architect
+49.40.32 55 87.503
CoreMedia AG
Executive Board: Sören Stamer (CEO), Dr. Klemens Kleiminger (CFO)
Supervisory Board: Prof. Dr. Joachim Schmidt (Chairman)
Trade Register: Amtsgericht Hamburg, HR B 76277
 
> -----Original Message-----
> From: Andreas.Loew_at_Sun.COM [mailto:Andreas.Loew_at_Sun.COM] 
> Sent: Monday, May 21, 2007 4:46 PM
> To: users_at_jaxb.dev.java.net
> Subject: Avoid both JAXB2 binding as well DOM creation for a 
> document fragment?
> 
> (Apologies for cross-posting to JAX-WS and JAXB - I simply 
> was unable to 
> determine which list would be the most appropriate place to post this 
> question to...)
> 
> 
> All,
> 
> I have to deal with a very specific Web Service where an 
> "outer" request 
> document (i.e. the SOAP body) kind of wraps a nested "inner" XML 
> document fragment as an xsd:any type.
> 
> I do know that I can annotate xsd:any using the jaxb:dom 
> annotation in 
> order to get the wrapped document being converted into a W3C 
> DOM instance.
> 
> As these inner documents may become quite large (several MBs), from a 
> memory consumption and performance perspective, I'd prefer 
> not to create 
> a DOM representation for the inner fragment, but rather get access to 
> the "plain XML source", such as by getting direct access to the 
> Unmarshaller's document source - ideally, the StAX XMLStreamReader or 
> XMLEventReader.
> 
> Unfortunately,
> https://jaxb.dev.java.net/guide/Avoid_strong_databinding.html
> for now seems just a work in progress... :-)
> 
> So my question is:
> 
> Is there any way to get access to the original document 
> source for the 
> inner fragment, while still using JAX-WS/JAXB2 to map the overall 
> document in order to easily process the outer part's content:
> 
> - to avoid mapping/binding of the inner fragment to Java classes
> - to avoid creation of a DOM tree representing the inner 
> fragment as well
> - but to "simply" get access to the original source/fragment 
> (as being 
> internally provided to the Unmarshaller by the JAX-WS implementation)
> 
> Many thanks in advance for any help with this!
> 
> Best regards,
> 
> Andreas
> 
> -- 
> Andreas Loew
> Java Architect
> Sun Microsystems (Germany)