accessing element values of substitutionGroups
I'm having trouble retrieving a value from an unmarshalled content tree or updating this value before marshalling out to an XML document. This happens when the element belongs to a substitutionGroup and an @XmlElementRef supplies a List of classes. For example a section of the XML looks like this:
The OAGIS schema shows:
I'm assuming that the substitutionGroup causes the xjc to create a DocumentIdType class but not a CustomerDocumentId class.
The getId() and getRevision() methods are in the DocumentIdType class. The getDocumentIdType() method is in the DocumentIds class and returns a List> object. I can't figure out how to get the Id and Revision values after I unmarshall the XML. It marshalls back out OK because I tried that, so there must be someway to get to these values. Section 5.5.5 of the JAXB 2.0 specification and the related references don't supply any examples. Here's what I tried so far:
PurchaseOrderHeader poh = npo.getHeader();
DocumentIds dids = poh.getDocumentIds();
List<YYYYY> didt = dids.getDocumentIdType();
for(Iterator iterDIDT = didt.iterator(); iterDIDT.hasNext();)
XXXXX ndidt = (XXXXX)iterDIDT.next();
Revision revision = ndidt.getRevision();
System.out.println("Cust PO#: " + ndidt.getId());
The xjc generated java class, DocumentIds, states that the possible List values are DocumentIdType or PartyDocumentId.
For YYYYY and XXXXX I tried every possible combination of:
1) JAXBElement<? extends DocumentIdType>
The only value of YYYYY that javac will not bomb with "incompatible types" is 1) or 6), however, I can not use either for XXXXX.
Using 2) or 3) for XXXXX bombs on execution with a ClassCastException.
Only 3) has the getId() and getRevision() methods but I could get a successful execution by leaving these gets out and using either 4) or 5). Interesting on 4) if I used the getName() method to QName I came up with "CustomerDocumentId". Not that this helps any but it shows that this class doesn't have values it has properties.
Anybody know how to get and/or set the Id and the Revision values while in the iteration of the List? Is this supposed to somehow use the get.Superclass() method of the Class class? Would greatly appreciate an example.