Search in sources :

Example 1 with JAXBSetMethodAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor 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 JAXBSetMethodAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method initializeXMLMapping.

private void initializeXMLMapping(XMLMapping mapping, Property property) {
    mapping.setAttributeName(property.getPropertyName());
    // handle read-only set via metadata
    if (property.isSetReadOnly()) {
        mapping.setIsReadOnly(property.isReadOnly());
    }
    // handle write-only set via metadata
    if (property.isSetWriteOnly()) {
        mapping.setIsWriteOnly(property.isWriteOnly());
    }
    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.setIsReadOnly(true);
            mapping.setSetMethodName(property.getSetMethodName());
        } else if (property.getSetMethodName() == null) {
            mapping.setGetMethodName(property.getGetMethodName());
            mapping.setIsWriteOnly(true);
        } else {
            mapping.setSetMethodName(property.getSetMethodName());
            mapping.setGetMethodName(property.getGetMethodName());
        }
    }
}
Also used : JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)

Example 3 with JAXBSetMethodAttributeAccessor

use of org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method initializeVariableXPathMapping.

private void initializeVariableXPathMapping(VariableXPathObjectMapping mapping, Property property, JavaClass actualType) {
    String variableAttributeName = property.getVariableAttributeName();
    TypeInfo refInfo = typeInfo.get(actualType.getName());
    if (refInfo == null) {
        throw JAXBException.unknownTypeForVariableNode(actualType.getName());
    }
    Property refProperty = refInfo.getProperties().get(variableAttributeName);
    while (refProperty == null) {
        JavaClass superClass = CompilerHelper.getNextMappedSuperClass(actualType, typeInfo, helper);
        if (superClass != null) {
            refInfo = typeInfo.get(superClass.getName());
            refProperty = refInfo.getProperties().get(variableAttributeName);
        } else {
            break;
        }
    }
    if (refProperty == null) {
        throw JAXBException.unknownPropertyForVariableNode(variableAttributeName, actualType.getName());
    }
    String refPropertyType = refProperty.getActualType().getQualifiedName();
    if (!(refPropertyType.equals("java.lang.String") || refPropertyType.equals("javax.xml.namespace.QName"))) {
        throw JAXBException.invalidTypeForVariableNode(variableAttributeName, refPropertyType, actualType.getName());
    }
    if (refProperty.isMethodProperty()) {
        if (refProperty.getGetMethodName() == null) {
            // handle case of set with no get method
            String paramTypeAsString = refProperty.getType().getName();
            JAXBSetMethodAttributeAccessor accessor = new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader());
            accessor.setIsReadOnly(true);
            accessor.setSetMethodName(refProperty.getSetMethodName());
            mapping.setIsReadOnly(true);
            accessor.setAttributeName("thingBLAH");
            mapping.setVariableAttributeAccessor(accessor);
        } else if (refProperty.getSetMethodName() == null) {
            mapping.setVariableGetMethodName(refProperty.getGetMethodName());
        } else {
            mapping.setVariableGetMethodName(refProperty.getGetMethodName());
            mapping.setVariableSetMethodName(refProperty.getSetMethodName());
        }
    } else {
        mapping.setVariableAttributeName(property.getVariableAttributeName());
    }
    if (property.getVariableClassName() != null) {
        mapping.setReferenceClassName(property.getVariableClassName());
    } else {
        mapping.setReferenceClassName(actualType.getQualifiedName());
    }
    mapping.setAttribute(property.isVariableNodeAttribute());
}
Also used : JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)

Aggregations

JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)3 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 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 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)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 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)1 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)1