users@jaxb.java.net

Re: Complex references

From: Jeremy Haile <jhaile_at_fastmail.fm>
Date: Fri, 15 Jul 2005 08:57:50 -0400

On Tue, 12 Jul 2005 10:01:45 -0700, "Kohsuke Kawaguchi"
<Kohsuke.Kawaguchi_at_Sun.COM> said:
> > What would be ideal (solution #2) for my situation would be if JAXB
> > basically kept a mapping from <class type, ID> to the object being
> > constructed. Then if it was setting a property like setApple( Apple
> > myApple ), it would know to only look in IDREF list under <Apple.class,
> > "myFruit"> Of course, this doesn't exactly follow the ID/IDREF
> > semantics, but other than the idea mentioned above I don't have many
> > good ideas.
>
> The problem with this is that it's too specific to your needs. It's not
> general purpose enough.

Why do you think that this solution is specific to my needs? I actually
think this is a general purpose solution.

For example, if I have a class mapped as:
@XmlIDREF Apple getApple();
void setApple( Apple myApple );

I have an Apple object with an @Id attribute "name", and an Orange
object with an @Id attribute "name".

The XML might look like:
<basket apple="myFruit" orange="myFruit"/>
<apple name="myFruit"/>
<orange name="myFruit"/>

In this case, although the apple and orange share the same ID, obviously
only one of them can legally be passed to the setApple() method. So, to
me it seems like the JAXB framework should be smart enough to know that
if two objects share the same identifier, it should choose the one that
is of a type that is assignable to the target property.

I have seen this come up in multiple situations and can imagine that
this could be a problem in many different situations. In Java domain
models, it is not unusual for an identifier to be unique across a
particular class, but not unique across all classes. This capability
would not affect anything that depended on normal ID/IDREF semantics,
but would allow for the case that different class types could share
identifiers but still resolve correctly.

Thoughts?

Jeremy Haile