Using JAXB to create reference-objects accordingly to an attribute

sandyoyster

New Member
Consider the following xml:\[code\]<Config> <Paths> <Path reference="WS_License"/> </Paths> <Steps> <Step id="WS_License" title="License Agreement" /> </Steps></Config>\[/code\]The following JAXB classes:\[code\]public class Path { private String _reference; public String getReference() { return _reference; } @XmlAttribute public void setReference( String reference ) { _reference = reference; }}\[/code\]And\[code\]public class Step { private String _id; private String _title; public String getId() { return _id; } @XmlAttribute public void setId( String id ) { _id = id; } public String getTitle() { return _title; } @XmlAttribute public void setTitle( String title ) { _title = title; }}\[/code\]Instead of storing the reference in the Path object as String, I'd like to hold it as a Step object. The link between those objects is the reference and id attributes. Is the @XMLJavaTypeAdapter attribute the way to go? Could anyone be so kind to provide an example of the correct usage?Thanks!EDIT:I'd also would like to do the same technique with an element.Consider the following xml:\[code\]<Config> <Step id="WS_License" title="License Agreement"> <DetailPanelReference reference="DP_License" /> </Step> <DetailPanels> <DetalPanel id="DP_License" title="License Agreement" /> </DetailPanels></Config>\[/code\]The following JAXB classes:\[code\]@XmlAccessorType(XmlAccessType.FIELD)public class Step { @XmlID @XmlAttribute(name="id") private String _id; @XmlAttribute(name="title") private String _title; @XmlIDREF @XmlElement(name="DetailPanelReference", type=DetailPanel.class) private DetailPanel[] _detailPanels; //Doesn't seem to work}@XmlAccessorType(XmlAccessType.FIELD)public class DetailPanel { @XmlID @XmlAttribute(name="id") private String _id; @XmlAttribute(name="title") private String _title;}\[/code\]The property _detailPanels in the Step-object is empty and the link doesn't seems to work. Is there any option to create a link without creating a new JAXB object holding only the reference to the DetailPanel?Thanks again : )!
 
Back
Top