users@jaxb.java.net

Re: JAXB 2 and xjc:dom

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 14 Jun 2006 23:32:12 -0700

Aleksei Valikov wrote:
> 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?

I'm not sure if I understand why you are doing "if (typeInfo instanceof
CWildcardTypeInfo), but the rest is 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?

This is a bug in the RI. It needs to flag this as an error. One cannot
have multiple properties bound to DOM. At most one is allowed.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com