users@jaxb.java.net

JAXB 2 and xjc:dom

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 14 Jun 2006 10:38:00 +0200

Hi.

I have two questions concerning dom wildcard elements.

1. Detecting dom field outline.

Currently I use the following code to check if field is a dom field:

final CTypeInfo typeInfo = getSingleFieldTypeInfo(fieldOutline);

if (typeInfo instanceof CWildcardTypeInfo)
{
        final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();
        if (propertyInfo instanceof CReferencePropertyInfo) {
                final CReferencePropertyInfo referencePropertyInfo = (CReferencePropertyInfo)
propertyInfo;
        if (referencePropertyInfo.getWildcard() != null &&
referencePropertyInfo.getWildcard().allowDom) {
                // Ok, it's dom
        }
}

Is this correct?

2. I have troubles with the following structure:

   <xsd:complexType name="RootType">
     <xsd:sequence>
       <xsd:element name="content">
         <xsd:annotation>
           <xsd:appinfo>
             <xjc:dom/>
           </xsd:appinfo>
         </xsd:annotation>
       </xsd:element>
       <xsd:element name="contents" maxOccurs="unbounded">
         <xsd:annotation>
           <xsd:appinfo>
             <xjc:dom/>
           </xsd:appinfo>
         </xsd:annotation>
       </xsd:element>
     </xsd:sequence>
   </xsd:complexType>

What I get in Java code seems allright:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "RootType", propOrder = {
     "content",
     "contents"
})
public class RootType {

     @XmlAnyElement
     protected Element content;
     @XmlAnyElement
     protected List<Element> contents;
     @XmlAttribute
     protected Long hjid;

     public Element getContent() {
         return content;
     }

     public void setContent(Element value) {
         this.content = value;
     }

     public List<Element> getContents() {
         if (contents == null) {
             contents = new ArrayList<Element>();
         }
         return this.contents;
     }
}

But when I try unmarshalling a document with <contents>...</contents> elements,
only the content field is set. For instance, if I unmarshall:

<root>
   <content><p>test1</p></content>
   <contents><p>test2</p></contents>
   <contents><p>test3</p></contents>
</root>

I get RootType with getContent() set to <contents><p>test3</p></contents>.

Do I miss something?

Bye.
/lexi