Search in sources :

Example 1 with XmlElement

use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement 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)

Example 2 with XmlElement

use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.

the class DynamicXMLMetadataSource method createJAXBType.

/**
 * Create a javaType to be used by JAXB to map a particular class.
 * For static classes, JAXB annotations, xml and defaults will be used to map the class.
 * For Dynamic classes we create properties for each JPA mapping on the class
 * thing we create is a
 */
private JavaType createJAXBType(ClassDescriptor classDescriptor, ObjectFactory objectFactory) {
    JavaType javaType = new JavaType();
    String alias = classDescriptor.getAlias();
    if (alias == null || alias.isEmpty()) {
        alias = classDescriptor.getJavaClass().getSimpleName();
    }
    javaType.setName(alias);
    javaType.setJavaAttributes(new JavaAttributes());
    boolean isDynamic = DynamicEntity.class.isAssignableFrom(classDescriptor.getJavaClass());
    for (DatabaseMapping ormMapping : classDescriptor.getMappings()) {
        JAXBElement<XmlElement> element = createJAXBProperty(ormMapping, objectFactory, javaType, isDynamic);
        if (element != null) {
            javaType.getJavaAttributes().getJavaAttribute().add(element);
        }
    }
    // Embeddables don't need Rest adapters, return if the classDescriptor is an aggregate descriptor.
    if (classDescriptor.isAggregateDescriptor()) {
        return javaType;
    }
    // Set an adapter that is a subclass of ReferenceAdapter that can adapt the class to create a link for
    // the persistence_href field that has been weaved in.
    String name = RestAdapterClassWriter.constructClassNameForReferenceAdapter(classDescriptor.getJavaClassName());
    XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter();
    adapter.setValue(name);
    adapter.setValueType(classDescriptor.getJavaClassName());
    adapter.setType(classDescriptor.getJavaClassName());
    javaType.setXmlJavaTypeAdapter(adapter);
    return javaType;
}
Also used : JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 3 with XmlElement

use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.

the class DynamicXmlV2MetadataSource method createProperty.

/**
 * Create a JAXB property for given reference mapping.
 */
private JAXBElement<XmlElement> createProperty(ForeignReferenceMapping mapping, ObjectFactory objectFactory) {
    final String referenceClassName = mapping.getReferenceClassName();
    final XmlElement xmlElement = new XmlElement();
    xmlElement.setJavaAttribute(mapping.getAttributeName());
    xmlElement.setType(referenceClassName);
    final String adapterName = RestReferenceAdapterV2ClassWriter.getClassName(referenceClassName);
    final XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter();
    adapter.setValue(adapterName);
    adapter.setType(referenceClassName);
    xmlElement.setXmlJavaTypeAdapter(adapter);
    return objectFactory.createXmlElement(xmlElement);
}
Also used : XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement)

Example 4 with XmlElement

use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.

the class DynamicXmlV2MetadataSource method createCollectionProperty.

/**
 * Create a JAXB property for given collection mapping.
 */
private JAXBElement<XmlElement> createCollectionProperty(DatabaseMapping mapping, ObjectFactory objectFactory) {
    final XmlElement xmlElement = new XmlElement();
    xmlElement.setJavaAttribute(mapping.getAttributeName());
    xmlElement.setType(((CollectionMapping) mapping).getReferenceClassName());
    final XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter();
    final String adapterName = RestCollectionAdapterClassWriter.getClassName(((CollectionMapping) mapping).getReferenceClassName());
    adapter.setValue(adapterName);
    adapter.setType(Collection.class.getName());
    xmlElement.setXmlJavaTypeAdapter(adapter);
    return objectFactory.createXmlElement(xmlElement);
}
Also used : XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) Collection(java.util.Collection)

Example 5 with XmlElement

use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.

the class DynamicXmlV2MetadataSource method createJAXBType.

/**
 * Create a javaType to be used by JAXB to map a particular class.
 */
private JavaType createJAXBType(ClassDescriptor classDescriptor, ObjectFactory objectFactory) {
    JavaType javaType = new JavaType();
    String alias = classDescriptor.getAlias();
    if (alias == null || alias.isEmpty()) {
        alias = classDescriptor.getJavaClass().getSimpleName();
    }
    javaType.setName(alias);
    final JavaAttributes javaAttributes = new JavaAttributes();
    for (DatabaseMapping ormMapping : classDescriptor.getMappings()) {
        JAXBElement<XmlElement> element = null;
        if (ormMapping instanceof DirectCollectionMapping) {
            // Direct mapping -> no adapter
            continue;
        } else if (ormMapping.isCollectionMapping()) {
            // This is a collection mapping -> create collection adapter
            element = createCollectionProperty(ormMapping, objectFactory);
        } else if (ForeignReferenceMapping.class.isAssignableFrom(ormMapping.getClass())) {
            // FK mapping -> create reference adapter
            element = createProperty((ForeignReferenceMapping) ormMapping, objectFactory);
        }
        if (element != null) {
            javaAttributes.getJavaAttribute().add(element);
        }
    }
    if (!javaAttributes.getJavaAttribute().isEmpty()) {
        javaType.setJavaAttributes(javaAttributes);
    }
    return javaType;
}
Also used : JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping)

Aggregations

XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)11 JavaAttributes (org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes)6 JavaType (org.eclipse.persistence.jaxb.xmlmodel.JavaType)5 JAXBElement (jakarta.xml.bind.JAXBElement)4 XmlAttribute (org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute)4 XmlJavaTypeAdapter (org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter)4 QName (javax.xml.namespace.QName)3 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)3 ArrayList (java.util.ArrayList)2 JavaAttribute (org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute)2 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)2 JavaTypes (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes)2 XmlProperty (org.eclipse.persistence.jaxb.xmlmodel.XmlProperties.XmlProperty)2 XmlRootElement (org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement)2 XmlSchemaType (org.eclipse.persistence.jaxb.xmlmodel.XmlSchemaType)2 XmlType (org.eclipse.persistence.jaxb.xmlmodel.XmlType)2 Collection (java.util.Collection)1 EISCompositeCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping)1 EISCompositeDirectCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping)1 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)1