Skip Headers

# Mapping to a Union of Unions With an XML Direct Mapping

Previous

Next

Given the XML schema in Example: Schema for XML Direct Mapping to a Union of Unions, Figure: Java Class for XML Direct Mapping to a Union of Unions illustrates a Java class that can be mapped to a corresponding XML document. Example: Java for Composite Direct Collection XML Mapping to a Subelement Sequence shows how to configure this mapping in Java.

Schema for XML Direct Mapping to a Union of Unions

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="vacation" type="unionOfUnions"/>
        <xsd:simpleType name="unionOfUnions">
            <xsd:union>
                <xsd:simpleType>
                    <xsd:union>
                        <xsd:simpleType>
                            <xsd:list itemType="xsd:date"/>
                        </xsd:simpleType>
                        <xsd:simpleType>
                            <xsd:list itemType="xsd:integer"/>
                        </xsd:simpleType>
                    </xsd:union>
                </xsd:simpleType>
                <xsd:simpleType>
                    <xsd:union>
                        <xsd:simpleType>
                            <xsd:list itemType="xsd:string"/>
                        </xsd:simpleType>
                        <xsd:simpleType>
                            <xsd:list itemType="xsd:float"/>
                        </xsd:simpleType>
                    </xsd:union>
                </xsd:simpleType>
            </xsd:union>
        </xsd:simpleType>
    </xsd:schema>

Java Class for XML Direct Mapping to a Union of Unions

Description of "Java Class for XML Direct Mapping to a Union of Unions"

Java for XML Direct Mapping to a Union of Unions

    XMLDirectMapping vacationMapping = new XMLDirectMapping();
    vacationMapping.setAttributeName("vacation");
    XMLUnionField vacationField = new XMLUnionField();
    vacationField.setXPath("vacation/text()");
    vacationField.addSchemaType(XMLConstants.DATE_QNAME);
    vacationField.addSchemaType(XMLConstants.INTEGER_QNAME);
    vacationField.addSchemaType(XMLConstants.STRING_QNAME);
    vacationField.addSchemaType(XMLConstants.FLOAT_QNAME);
    vacationMapping.setField(vacationField);