Search in sources :

Example 1 with XmlWriteTransformer

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

the class MappingsGenerator method generateTransformationMapping.

/**
 * Generate an XMLTransformationMapping based on a given Property.
 */
public TransformationMapping generateTransformationMapping(Property property, Descriptor descriptor, NamespaceInfo namespace) {
    TransformationMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, XMLTransformationRecord, XMLRecord> mapping = new XMLTransformationMapping();
    if (property.isMethodProperty()) {
        if (property.getGetMethodName() == null) {
            // handle case of set with no get method
            String paramTypeAsString = property.getType().getName();
            mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader()));
            mapping.setSetMethodName(property.getSetMethodName());
        } else if (property.getSetMethodName() == null) {
            mapping.setGetMethodName(property.getGetMethodName());
        } else {
            mapping.setSetMethodName(property.getSetMethodName());
            mapping.setGetMethodName(property.getGetMethodName());
        }
    }
    // handle transformation
    if (property.isSetXmlTransformation()) {
        XmlTransformation xmlTransformation = property.getXmlTransformation();
        mapping.setIsOptional(xmlTransformation.isOptional());
        // handle transformer(s)
        if (xmlTransformation.isSetXmlReadTransformer()) {
            // handle read transformer
            mapping.setAttributeName(property.getPropertyName());
            XmlReadTransformer readTransformer = xmlTransformation.getXmlReadTransformer();
            if (readTransformer.isSetTransformerClass()) {
                mapping.setAttributeTransformerClassName(xmlTransformation.getXmlReadTransformer().getTransformerClass());
            } else {
                mapping.setAttributeTransformation(xmlTransformation.getXmlReadTransformer().getMethod());
            }
        }
        if (xmlTransformation.isSetXmlWriteTransformers()) {
            // handle write transformer(s)
            for (XmlWriteTransformer writeTransformer : xmlTransformation.getXmlWriteTransformer()) {
                if (writeTransformer.isSetTransformerClass()) {
                    mapping.addFieldTransformerClassName(writeTransformer.getXmlPath(), writeTransformer.getTransformerClass());
                } else {
                    mapping.addFieldTransformation(writeTransformer.getXmlPath(), writeTransformer.getMethod());
                }
            }
        }
    }
    return mapping;
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) XMLTransformationRecord(org.eclipse.persistence.internal.oxm.record.XMLTransformationRecord) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XmlWriteTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) MethodAttributeAccessor(org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor) InstanceVariableAttributeAccessor(org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor) XmlTransformation(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation) XmlReadTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 2 with XmlWriteTransformer

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

the class AnnotationsProcessor method buildTransformationProperty.

private Property buildTransformationProperty(JavaHasAnnotations javaHasAnnotations, JavaClass cls) {
    Property property = new Property(helper);
    org.eclipse.persistence.oxm.annotations.XmlTransformation transformationAnnotation = (org.eclipse.persistence.oxm.annotations.XmlTransformation) helper.getAnnotation(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlTransformation.class);
    XmlTransformation transformation = new XmlTransformation();
    if (transformationAnnotation != null) {
        transformation.setOptional(transformationAnnotation.optional());
    }
    // Read Transformer
    org.eclipse.persistence.oxm.annotations.XmlReadTransformer readTransformer = (org.eclipse.persistence.oxm.annotations.XmlReadTransformer) helper.getAnnotation(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlReadTransformer.class);
    if (readTransformer != null) {
        org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer xmlReadTransformer = new org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer();
        if (!(readTransformer.transformerClass() == AttributeTransformer.class)) {
            xmlReadTransformer.setTransformerClass(readTransformer.transformerClass().getName());
        } else if (!(readTransformer.method().equals(EMPTY_STRING))) {
            xmlReadTransformer.setMethod(readTransformer.method());
        }
        transformation.setXmlReadTransformer(xmlReadTransformer);
    }
    // Handle Write Transformers
    org.eclipse.persistence.oxm.annotations.XmlWriteTransformer[] transformers = null;
    if (helper.isAnnotationPresent(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlWriteTransformer.class)) {
        org.eclipse.persistence.oxm.annotations.XmlWriteTransformer writeTransformer = (org.eclipse.persistence.oxm.annotations.XmlWriteTransformer) helper.getAnnotation(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlWriteTransformer.class);
        transformers = new org.eclipse.persistence.oxm.annotations.XmlWriteTransformer[] { writeTransformer };
    } else if (helper.isAnnotationPresent(javaHasAnnotations, XmlWriteTransformers.class)) {
        XmlWriteTransformers writeTransformers = (XmlWriteTransformers) helper.getAnnotation(javaHasAnnotations, XmlWriteTransformers.class);
        transformers = writeTransformers.value();
    }
    if (transformers != null) {
        for (org.eclipse.persistence.oxm.annotations.XmlWriteTransformer next : transformers) {
            org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer xmlWriteTransformer = new org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer();
            if (!(next.transformerClass() == FieldTransformer.class)) {
                xmlWriteTransformer.setTransformerClass(next.transformerClass().getName());
            } else if (!(next.method().equals(EMPTY_STRING))) {
                xmlWriteTransformer.setMethod(next.method());
            }
            xmlWriteTransformer.setXmlPath(next.xmlPath());
            transformation.getXmlWriteTransformer().add(xmlWriteTransformer);
        }
    }
    property.setXmlTransformation(transformation);
    property.setIsXmlTransformation(true);
    return property;
}
Also used : XmlReadTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer) XmlWriteTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer) XmlWriteTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer) XmlWriteTransformers(org.eclipse.persistence.oxm.annotations.XmlWriteTransformers) XmlTransformation(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation) XmlReadTransformer(org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer) XmlProperty(org.eclipse.persistence.oxm.annotations.XmlProperty)

Aggregations

XmlTransformation (org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation)2 XmlReadTransformer (org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer)2 XmlWriteTransformer (org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)1 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)1 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)1 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)1 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)1 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)1 XMLTransformationRecord (org.eclipse.persistence.internal.oxm.record.XMLTransformationRecord)1 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)1 XmlProperty (org.eclipse.persistence.oxm.annotations.XmlProperty)1 XmlWriteTransformers (org.eclipse.persistence.oxm.annotations.XmlWriteTransformers)1 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)1 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)1