Search in sources :

Example 1 with XMLTransformationRecord

use of org.eclipse.persistence.internal.oxm.record.XMLTransformationRecord 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 XMLTransformationRecord

use of org.eclipse.persistence.internal.oxm.record.XMLTransformationRecord in project eclipselink by eclipse-ee4j.

the class XMLTransformationMapping method writeFromAttributeIntoRow.

/**
 * INTERNAL:
 * Put value into a record keyed on field.
 * @since EclipseLink 2.6.0
 */
@Override
public void writeFromAttributeIntoRow(UnmarshalRecord unmarshalRecord, Field field, Object value, boolean isElement) {
    if (null == unmarshalRecord.getTransformationRecord()) {
        unmarshalRecord.setTransformationRecord(new XMLTransformationRecord("ROOT", unmarshalRecord));
    }
    Field toWrite = field;
    if (isElement) {
        boolean isCDATA = unmarshalRecord.isBufferCDATA();
        if (field.isCDATA() != isCDATA) {
            toWrite = new XMLField(field.getName());
            toWrite.setNamespaceResolver(field.getNamespaceResolver());
            toWrite.setIsCDATA(isCDATA);
        }
    }
    unmarshalRecord.getTransformationRecord().put(toWrite, value);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLTransformationRecord(org.eclipse.persistence.internal.oxm.record.XMLTransformationRecord)

Aggregations

DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 XMLTransformationRecord (org.eclipse.persistence.internal.oxm.record.XMLTransformationRecord)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 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 Field (org.eclipse.persistence.internal.oxm.mappings.Field)1 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 XmlTransformation (org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation)1 XmlReadTransformer (org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer)1 XmlWriteTransformer (org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer)1 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)1 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)1