Search in sources :

Example 6 with XMLMapping

use of org.eclipse.persistence.oxm.mappings.XMLMapping in project eclipselink by eclipse-ee4j.

the class XmlBindingsGenerator method generateJavaType.

/**
 * Process a given XMLDescriptor and return a JavaType instance.
 */
protected static JavaType generateJavaType(XMLDescriptor xdesc) {
    String defaultNamespace = null;
    if (xdesc.getNamespaceResolver() != null) {
        defaultNamespace = xdesc.getNamespaceResolver().getDefaultNamespaceURI();
    }
    String schemaContext = null;
    if (xdesc.getSchemaReference() != null) {
        schemaContext = xdesc.getSchemaReference().getSchemaContext();
    }
    JavaType jType = new JavaType();
    jType.setName(getClassName(xdesc.getJavaClassName()));
    jType.setXmlAccessorType(XmlAccessType.FIELD);
    // handle XmlType
    if (schemaContext != null) {
        XmlType xType = new XmlType();
        xType.setName(schemaContext.substring(1, schemaContext.length()));
        if (defaultNamespace != null) {
            xType.setNamespace(defaultNamespace);
        }
        jType.setXmlType(xType);
    }
    // handle XmlRootElement
    XmlRootElement xmlRootElt = new XmlRootElement();
    xmlRootElt.setName(xdesc.getDefaultRootElement());
    if (defaultNamespace != null) {
        xmlRootElt.setNamespace(defaultNamespace);
    }
    jType.setXmlRootElement(xmlRootElt);
    jType.setJavaAttributes(new JavaAttributes());
    // generate an XmlAttribute or XmlElement for each mapping
    for (Iterator<DatabaseMapping> xmapIt = xdesc.getMappings().iterator(); xmapIt.hasNext(); ) {
        XMLMapping xMap = (XMLMapping) xmapIt.next();
        if (((XMLField) xMap.getField()).getXPathFragment().isAttribute()) {
            JAXBElement<XmlAttribute> jAtt = generateXmlAttribute(xMap);
            if (jAtt != null) {
                jType.getJavaAttributes().getJavaAttribute().add(jAtt);
            }
        } else {
            JAXBElement<XmlElement> jElt = generateXmlElement(xMap);
            if (jElt != null) {
                jType.getJavaAttributes().getJavaAttribute().add(jElt);
            }
        }
    }
    return jType;
}
Also used : XmlRootElement(org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement) JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) XmlAttribute(org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XmlType(org.eclipse.persistence.jaxb.xmlmodel.XmlType)

Aggregations

XMLMapping (org.eclipse.persistence.oxm.mappings.XMLMapping)6 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)5 XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)4 BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)3 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)3 XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)3 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)2 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)2 AnyObjectMapping (org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping)2 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)2 ChoiceCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping)2 ChoiceObjectMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping)2 CollectionReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping)2 CompositeCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping)2 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)2 DirectCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping)2 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)2 InverseReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping)2