Search in sources :

Example 1 with VirtualAttributeAccessor

use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor in project eclipselink by eclipse-ee4j.

the class MappingAccessor method setAccessorMethods.

/**
 * INTERNAL:
 * Set the getter and setter access methods for this accessor.
 */
protected void setAccessorMethods(DatabaseMapping mapping) {
    if (usesPropertyAccess() || usesVirtualAccess()) {
        if (usesVirtualAccess()) {
            mapping.setAttributeAccessor(new VirtualAttributeAccessor());
        }
        mapping.setGetMethodName(getGetMethodName());
        mapping.setSetMethodName(getSetMethodName());
    }
}
Also used : VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)

Example 2 with VirtualAttributeAccessor

use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateMappings.

/**
 * Generate mappings for a given TypeInfo.
 */
public void generateMappings(TypeInfo info, Descriptor descriptor, JavaClass descriptorJavaClass, NamespaceInfo namespaceInfo) {
    if (info.isAnonymousComplexType()) {
        // may need to generate inherited mappings
        generateInheritedMappingsForAnonymousType(info, descriptor, descriptorJavaClass, namespaceInfo);
    }
    List<Property> propertiesInOrder = info.getNonTransientPropertiesInPropOrder();
    for (int i = 0; i < propertiesInOrder.size(); i++) {
        Property next = propertiesInOrder.get(i);
        if (next != null && (!next.isTransient() || (next.isTransient() && next.isXmlLocation()))) {
            Mapping mapping = generateMapping(next, descriptor, descriptorJavaClass, namespaceInfo);
            if (next.isVirtual()) {
                VirtualAttributeAccessor accessor = new VirtualAttributeAccessor();
                accessor.setAttributeName(mapping.getAttributeName());
                String getMethod = info.getXmlVirtualAccessMethods().getGetMethod();
                String setMethod = info.getXmlVirtualAccessMethods().getSetMethod();
                // Check to see if get/set were overridden in the mapping
                if (mapping.getAttributeAccessor().isMethodAttributeAccessor()) {
                    getMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getGetMethodName();
                    setMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getSetMethodName();
                    accessor.setValueType(mapping.getAttributeClassification());
                }
                accessor.setGetMethodName(getMethod);
                accessor.setSetMethodName(setMethod);
                if (mapping.getAttributeAccessor() instanceof JAXBArrayAttributeAccessor) {
                    JAXBArrayAttributeAccessor jaa = (JAXBArrayAttributeAccessor) mapping.getAttributeAccessor();
                    jaa.setNestedAccessor(accessor);
                } else {
                    mapping.setAttributeAccessor(accessor);
                }
            }
            if (mapping != null) {
                descriptor.addMapping((CoreMapping) mapping);
            }
            // set user-defined properties if necessary
            if (next.isSetUserProperties()) {
                mapping.setProperties(next.getUserProperties());
            }
            // get package info
            AccessorFactoryWrapper accessorFactory = info.getXmlAccessorFactory();
            if (accessorFactory == null) {
                accessorFactory = info.getPackageLevelXmlAccessorFactory();
            }
            if (accessorFactory != null) {
                try {
                    Object accessor = CompilerHelper.createAccessorFor(descriptorJavaClass, next, helper, accessorFactory);
                    if (accessor != null) {
                        CustomAccessorAttributeAccessor attributeAccessor = new CustomAccessorAttributeAccessor(accessor);
                        mapping.setAttributeAccessor(attributeAccessor);
                    }
                } catch (Exception ex) {
                }
            }
        }
        next.postInitialize();
    }
}
Also used : VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) AccessorFactoryWrapper(org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLVariableXPathCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathCollectionMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) XMLAnyAttributeMapping(org.eclipse.persistence.oxm.mappings.XMLAnyAttributeMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLContainerMapping(org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) JAXBException(org.eclipse.persistence.exceptions.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 3 with VirtualAttributeAccessor

use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor in project eclipselink by eclipse-ee4j.

the class PreLoginMappingAdapter method copyAccessorToMapping.

/**
 * Update the targetMapping to have the same accessor as the originMapping
 */
private static void copyAccessorToMapping(DatabaseMapping originMapping, DatabaseMapping targetMapping) {
    if (originMapping.getAttributeAccessor().isVirtualAttributeAccessor()) {
        VirtualAttributeAccessor accessor = new VirtualAttributeAccessor();
        accessor.setGetMethodName(originMapping.getGetMethodName());
        accessor.setSetMethodName(originMapping.getSetMethodName());
        targetMapping.setAttributeAccessor(accessor);
    }
    if (originMapping.getAttributeAccessor().isValuesAccessor()) {
        ValuesAccessor accessor = new ValuesAccessor(originMapping);
        accessor.setAttributeName(originMapping.getAttributeAccessor().getAttributeName());
        targetMapping.setAttributeAccessor(accessor);
    } else {
        targetMapping.setAttributeName(originMapping.getAttributeName());
        targetMapping.setGetMethodName(originMapping.getGetMethodName());
        targetMapping.setSetMethodName(originMapping.getSetMethodName());
    }
}
Also used : VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) ValuesAccessor(org.eclipse.persistence.internal.dynamic.ValuesAccessor)

Example 4 with VirtualAttributeAccessor

use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor 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

VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)4 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)1 EISCompositeCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping)1 EISCompositeDirectCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping)1 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)1 JAXBException (org.eclipse.persistence.exceptions.JAXBException)1 ValuesAccessor (org.eclipse.persistence.internal.dynamic.ValuesAccessor)1 AccessorFactoryWrapper (org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper)1 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)1 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)1 AnyAttributeMapping (org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping)1 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)1 AnyObjectMapping (org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping)1 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)1 BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)1 ChoiceCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping)1 ChoiceObjectMapping (org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping)1 CollectionReferenceMapping (org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping)1 CompositeCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping)1 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)1