Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JAXB Generating java classes from elements with attributes ID&IDREF

843834Jul 7 2008 — edited Jul 11 2008
With reference to [Pluggable ID/IDREF handling in JAXB 2.0|http://weblogs.java.net/blog/kohsuke/archive/2005/08/pluggable_ididr.html]
@XmlRootElement
class Apple { @XmlID String id; }

@XmlRootElement
class AppleRef { @XmlIDREF Object ref; }

@XmlRootElement
class Orange { @XmlID String id; }

@XmlRootElement
class OrangeRef { @XmlIDREF Object ref; }

class Box {
  @XmlElementRef
  List fruits;
}
Above code is generated from schema that describes following xml document
<document>
  <box>
    <appleRef ref="a1" />
    <orangeRef ref="o1" />
    <apple id="a1" />
    <orange id="o1" />
  </box>
  <box>
    <apple id="a2" />
    <appleRef id="a2" />
  </box>
</document>
Extract from the article:
Where orangeRefs would only refer to oranges and appleRefs would only refer to apples. (Note that this document no longer validates with the original schema.)

+First,{color:#ff0000} you'd have to modify{color} the above classes to make it clear that AppleRef only refers to Apple:+
@XmlRootElement
class AppleRef { @XmlIDREF Apple ref; }

@XmlRootElement
class OrangeRef { @XmlIDREF Orange ref; }
Is there a binding annotation for a schema document that indicates that class Object should be replaced by Apple and Orange classes? Thus, generation of java classes can be done without any manual modifications of classes OrangeRef and AppleRef.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 8 2008
Added on Jul 7 2008
1 comment
362 views