dev@jaxb.java.net

Re: Parent Pointer XJC Plugin

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 25 Jan 2007 14:39:07 -0800

Gregory Kick wrote:
> I'm working on an xjc plugin that would automatically generate parent
> pointers similar to the example (
> https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html
> ) in the jaxb guide. Obviously, since I'm trying to do it in xjc, I'm
> not trying to avoid cycles, but rather just hold on to a reference to
> the parent in order to make traversing the object tree a little
> easier.

Wonderful. I think this is very useful. Would you be interested in
hosting that on http://jaxb2-commons.dev.java.net/ ?

> I currently have a pretty simple little plugin that uses a field of
> type Object and just assigns the parent parameter of afterUnmarshal()
> to it. (By the way, doesn't there need to be a cast in the example?)
> This works pretty well, but relies on a lot of instanceof and casting.

Fixed the doc. Thanks for the problem report.

> Ideally, I would like something a little more type-safe. In a lot of
> cases, there will only be one type for the parent so something like
> "private Department parent;" would work. In the cases with more than
> one type of parent, maybe have multiple fields and the ones that
> aren't used just stay null?

... or you can compute the common base type. There's code in XJC to do
that. That's how we compute the type of the property.


> Anyway, the question at hand is how would I figure out what the
> possible parent types are from a plugin? The whole xjc
> model/codemodel thing isn't hugely documented and I can't figure it
> out.

I hope Lexi's explanation got you going. If not, let me know.

Also, if you have suggestions for doc improvements, like where you got
stuck, etc, that would be really helpful.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com