dev@jaxb.java.net

Parent Pointer XJC Plugin

From: Gregory Kick <gk5885_at_gmail.com>
Date: Wed, 24 Jan 2007 22:13:56 -0800

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.

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.

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?

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.

Thanks for any help,

-- 
Gregory Kick
gk5885_at_gmail.com