Search in sources :

Example 1 with EISCompositeDirectCollectionMapping

use of org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping in project eclipselink by eclipse-ee4j.

the class DynamicXMLMetadataSource method createJAXBProperty.

/**
 * Create a JAXB property for a particular mapping.
 * This will only create JAXBProperties for mappings that are virtual - either because their
 * parent object is a dynamic class, or because the owning static class has virtual properties
 */
private JAXBElement<XmlElement> createJAXBProperty(DatabaseMapping mapping, ObjectFactory objectFactory, JavaType owningType, boolean isDynamic) {
    if (!mapping.getAttributeAccessor().isVirtualAttributeAccessor() && !isDynamic) {
        return null;
    }
    XmlElement xmlElement = new XmlElement();
    xmlElement.setJavaAttribute(mapping.getAttributeName());
    if (mapping.isObjectReferenceMapping()) {
        xmlElement.setType(((ObjectReferenceMapping) mapping).getReferenceClassName());
    } else if (mapping.isCollectionMapping()) {
        if (mapping.isEISMapping()) {
            // It will be fine for simple collections
            if (mapping instanceof EISCompositeDirectCollectionMapping) {
                xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
            } else if (mapping instanceof EISCompositeCollectionMapping) {
                xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
                xmlElement.setType(((EISCompositeCollectionMapping) mapping).getReferenceClassName());
            }
        } else {
            xmlElement.setType(((CollectionMapping) mapping).getReferenceClassName());
            xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
        }
    } else {
        xmlElement.setType(mapping.getAttributeClassification().getName());
    }
    if (mapping.getAttributeAccessor().isVirtualAttributeAccessor()) {
        VirtualAttributeAccessor jpaAccessor = (VirtualAttributeAccessor) mapping.getAttributeAccessor();
        if (owningType.getXmlVirtualAccessMethods() == null) {
            XmlVirtualAccessMethods virtualAccessMethods = new XmlVirtualAccessMethods();
            virtualAccessMethods.setGetMethod(jpaAccessor.getGetMethodName());
            virtualAccessMethods.setSetMethod(jpaAccessor.getSetMethodName());
            owningType.setXmlVirtualAccessMethods(virtualAccessMethods);
        } else if (!owningType.getXmlVirtualAccessMethods().getGetMethod().equals(jpaAccessor.getGetMethodName())) {
            XmlAccessMethods accessMethods = new XmlAccessMethods();
            accessMethods.setGetMethod(jpaAccessor.getGetMethodName());
            accessMethods.setSetMethod(jpaAccessor.getSetMethodName());
            xmlElement.setXmlAccessMethods(accessMethods);
        }
    }
    return objectFactory.createXmlElement(xmlElement);
}
Also used : EISCompositeDirectCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping) XmlAccessMethods(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessMethods) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) EISCompositeDirectCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping) XmlVirtualAccessMethods(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethods)

Aggregations

EISCompositeCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping)1 EISCompositeDirectCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping)1 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)1 XmlAccessMethods (org.eclipse.persistence.jaxb.xmlmodel.XmlAccessMethods)1 XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)1 XmlVirtualAccessMethods (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethods)1 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)1