Search in sources :

Example 6 with UnmarshalRecord

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

the class JsonStructureReader method parsePair.

private void parsePair(String name, JsonValue jsonValue) throws SAXException {
    if (jsonValue == null) {
        return;
    }
    ValueType valueType = jsonValue.getValueType();
    if (valueType == ValueType.ARRAY) {
        JsonArray jsonArray = (JsonArray) jsonValue;
        String parentLocalName = name;
        if (attributePrefix != null && parentLocalName.startsWith(attributePrefix)) {
            // do nothing;
            return;
        }
        String uri = Constants.EMPTY_STRING;
        if (isNamespaceAware() && namespaces != null) {
            if (parentLocalName.length() > 2) {
                int nsIndex = parentLocalName.indexOf(getNamespaceSeparator(), 1);
                if (nsIndex > -1) {
                    String prefix = parentLocalName.substring(0, nsIndex);
                    uri = namespaces.resolveNamespacePrefix(prefix);
                }
                if (uri == null || uri == Constants.EMPTY_STRING) {
                    uri = namespaces.getDefaultNamespaceURI();
                } else {
                    parentLocalName = parentLocalName.substring(nsIndex + 1);
                }
            } else {
                uri = namespaces.getDefaultNamespaceURI();
            }
        }
        boolean isTextValue;
        int arraySize = jsonArray.size();
        if (arraySize == 0) {
            if (contentHandler instanceof UnmarshalRecord || isUnmarshalRecordWithinAdapter()) {
                final UnmarshalRecord ur = this.contentHandler instanceof UnmarshalRecord ? (UnmarshalRecord) this.contentHandler : getUnmarshalRecordFromAdapter();
                XPathNode node = ur.getNonAttributeXPathNode(uri, parentLocalName, parentLocalName, null);
                if (node != null) {
                    NodeValue nv = node.getNodeValue();
                    if (nv == null && node.getTextNode() != null) {
                        nv = node.getTextNode().getUnmarshalNodeValue();
                    }
                    if (nv != null && nv.isContainerValue()) {
                        ur.getContainerInstance(((ContainerValue) nv));
                    }
                }
            }
        }
        startCollection();
        XPathFragment groupingXPathFragment = null;
        XPathFragment itemXPathFragment = null;
        if (contentHandler instanceof UnmarshalRecord || isUnmarshalRecordWithinAdapter()) {
            final UnmarshalRecord contentHandler_ = contentHandler instanceof UnmarshalRecord ? (UnmarshalRecord) contentHandler : getUnmarshalRecordFromAdapter();
            isTextValue = isTextValue(parentLocalName, contentHandler_);
            UnmarshalRecord unmarshalRecord = contentHandler_;
            if (unmarshalRecord.getUnmarshaller().isWrapperAsCollectionName()) {
                XPathNode unmarshalRecordXPathNode = unmarshalRecord.getXPathNode();
                if (null != unmarshalRecordXPathNode) {
                    XPathFragment currentFragment = new XPathFragment();
                    currentFragment.setLocalName(parentLocalName);
                    currentFragment.setNamespaceURI(uri);
                    currentFragment.setNamespaceAware(isNamespaceAware());
                    XPathNode groupingXPathNode = unmarshalRecordXPathNode.getNonAttributeChildrenMap().get(currentFragment);
                    if (groupingXPathNode != null) {
                        if (groupingXPathNode.getUnmarshalNodeValue() instanceof CollectionGroupingElementNodeValue) {
                            groupingXPathFragment = groupingXPathNode.getXPathFragment();
                            contentHandler_.startElement(uri, parentLocalName, parentLocalName, new AttributesImpl());
                            XPathNode itemXPathNode = groupingXPathNode.getNonAttributeChildren().get(0);
                            itemXPathFragment = itemXPathNode.getXPathFragment();
                        } else if (groupingXPathNode.getUnmarshalNodeValue() == null) {
                            XPathNode itemXPathNode = groupingXPathNode.getNonAttributeChildren().get(0);
                            if (itemXPathNode != null) {
                                if ((itemXPathNode.getUnmarshalNodeValue()).isContainerValue()) {
                                    groupingXPathFragment = groupingXPathNode.getXPathFragment();
                                    contentHandler_.startElement(uri, parentLocalName, parentLocalName, new AttributesImpl());
                                    itemXPathFragment = itemXPathNode.getXPathFragment();
                                }
                            }
                        }
                    }
                }
            }
            for (JsonValue nextArrayValue : jsonArray) {
                if (nextArrayValue.getValueType() == ValueType.NULL) {
                    contentHandler.setNil(true);
                }
                if (!isTextValue) {
                    if (null != itemXPathFragment) {
                        contentHandler.startElement(itemXPathFragment.getNamespaceURI(), itemXPathFragment.getLocalName(), itemXPathFragment.getLocalName(), attributes.setValue(nextArrayValue, attributePrefix, namespaces, getNamespaceSeparator(), isNamespaceAware()));
                    } else {
                        contentHandler.startElement(uri, parentLocalName, parentLocalName, attributes.setValue(nextArrayValue, attributePrefix, namespaces, getNamespaceSeparator(), isNamespaceAware()));
                    }
                }
                // Internally store each nested array it as JsonObject with name: "item"
                if (valueType == nextArrayValue.getValueType()) {
                    JsonBuilderFactory factory = Json.createBuilderFactory(null);
                    JsonObjectBuilder jsonObjectBuilder = factory.createObjectBuilder();
                    jsonObjectBuilder.add("item", nextArrayValue);
                    nextArrayValue = jsonObjectBuilder.build();
                }
                parseValue(nextArrayValue);
                if (!isTextValue) {
                    if (null != itemXPathFragment) {
                        contentHandler.endElement(itemXPathFragment.getNamespaceURI(), itemXPathFragment.getLocalName(), itemXPathFragment.getLocalName());
                    } else {
                        contentHandler.endElement(uri, parentLocalName, parentLocalName);
                    }
                }
            }
        }
        if (null != groupingXPathFragment) {
            contentHandler.endElement(uri, groupingXPathFragment.getLocalName(), groupingXPathFragment.getLocalName());
        }
        endCollection();
    } else {
        if (attributePrefix != null && name.startsWith(attributePrefix)) {
            return;
        }
        String localName = name;
        String uri = Constants.EMPTY_STRING;
        if (isNamespaceAware() && namespaces != null) {
            if (localName.length() > 2) {
                int nsIndex = localName.indexOf(getNamespaceSeparator(), 1);
                String prefix = Constants.EMPTY_STRING;
                if (nsIndex > -1) {
                    prefix = localName.substring(0, nsIndex);
                }
                uri = namespaces.resolveNamespacePrefix(prefix);
                if (uri == null || uri == Constants.EMPTY_STRING) {
                    uri = namespaces.getDefaultNamespaceURI();
                } else {
                    localName = localName.substring(nsIndex + 1);
                }
                if (localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE) && uri != null && uri.equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)) {
                    return;
                }
            } else {
                uri = namespaces.getDefaultNamespaceURI();
            }
        }
        if (contentHandler instanceof XMLRootRecord || contentHandler instanceof DeferredContentHandler) {
            if (jsonTypeCompatibility) {
                // is will be read by the xsi:type lookup
                if (!isNamespaceAware() && localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE)) {
                    return;
                }
            }
            if (textWrapper != null && textWrapper.equals(localName)) {
                parseValue(jsonValue);
                return;
            }
        } else if (contentHandler instanceof UnmarshalRecord && ((UnmarshalRecord) contentHandler).getXPathNode() != null) {
            if (jsonTypeCompatibility) {
                if (!isNamespaceAware() && localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE) && !((UnmarshalRecord) contentHandler).getXPathNode().hasTypeChild()) {
                    return;
                }
            }
            boolean isTextValue = isTextValue(localName, (UnmarshalRecord) contentHandler);
            if (isTextValue) {
                parseValue(jsonValue);
                return;
            }
            NodeValue nv = ((UnmarshalRecord) contentHandler).getAttributeChildNodeValue(uri, localName);
            if (attributePrefix == null && nv != null) {
                return;
            }
        } else if (isUnmarshalRecordWithinAdapter()) {
            @SuppressWarnings("rawtypes") final UnmarshalRecord contentHandler_ = getUnmarshalRecordFromAdapter();
            if (jsonTypeCompatibility) {
                if (!isNamespaceAware() && localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE) && !contentHandler_.getXPathNode().hasTypeChild()) {
                    return;
                }
            }
            boolean isTextValue = isTextValue(localName, contentHandler_);
            if (isTextValue) {
                parseValue(jsonValue);
                return;
            }
            NodeValue nv = contentHandler_.getAttributeChildNodeValue(uri, localName);
            if (attributePrefix == null && nv != null) {
                return;
            }
        }
        if (jsonValue.getValueType() == ValueType.NULL) {
            contentHandler.setNil(true);
        }
        contentHandler.startElement(uri, localName, localName, attributes.setValue(jsonValue, attributePrefix, namespaces, getNamespaceSeparator(), isNamespaceAware()));
        parseValue(jsonValue);
        contentHandler.endElement(uri, localName, localName);
    }
}
Also used : CollectionGroupingElementNodeValue(org.eclipse.persistence.internal.oxm.CollectionGroupingElementNodeValue) NodeValue(org.eclipse.persistence.internal.oxm.NodeValue) ValueType(jakarta.json.JsonValue.ValueType) JsonValue(jakarta.json.JsonValue) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) JsonString(jakarta.json.JsonString) CollectionGroupingElementNodeValue(org.eclipse.persistence.internal.oxm.CollectionGroupingElementNodeValue) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode) ContainerValue(org.eclipse.persistence.internal.oxm.ContainerValue) JsonArray(jakarta.json.JsonArray) AttributesImpl(org.xml.sax.helpers.AttributesImpl) JsonBuilderFactory(jakarta.json.JsonBuilderFactory) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) AbstractUnmarshalRecord(org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord) XMLRootRecord(org.eclipse.persistence.oxm.record.XMLRootRecord) JsonObjectBuilder(jakarta.json.JsonObjectBuilder) DeferredContentHandler(org.eclipse.persistence.internal.oxm.record.deferred.DeferredContentHandler)

Example 7 with UnmarshalRecord

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

the class JsonStructureReader method parseRoot.

public void parseRoot(JsonValue jsonValue) throws SAXException {
    if (namespaces != null) {
        Map<String, String> namespacePairs = namespaces.getPrefixesToNamespaces();
        for (Entry<String, String> namespacePair : namespacePairs.entrySet()) {
            contentHandler.startPrefixMapping(namespacePair.getKey(), namespacePair.getValue());
        }
    }
    if (jsonValue.getValueType() == ValueType.OBJECT) {
        contentHandler.startDocument();
        JsonObject jsonObject = (JsonObject) jsonValue;
        Set<Entry<String, JsonValue>> children = jsonObject.entrySet();
        if (children.size() == 0 && unmarshalClass == null) {
            return;
        }
        Iterator<Entry<String, JsonValue>> iter = children.iterator();
        if (includeRoot) {
            if (children.size() > 0) {
                Entry<String, JsonValue> nextEntry = iter.next();
                parsePair(nextEntry.getKey(), nextEntry.getValue());
            }
        } else {
            contentHandler.startElement(Constants.EMPTY_STRING, Constants.EMPTY_STRING, null, attributes.setValue(jsonValue, attributePrefix, namespaces, getNamespaceSeparator(), isNamespaceAware()));
            while (iter.hasNext()) {
                Entry<String, JsonValue> nextEntry = iter.next();
                parsePair(nextEntry.getKey(), nextEntry.getValue());
            }
            contentHandler.endElement(Constants.EMPTY_STRING, Constants.EMPTY_STRING, null);
        }
        contentHandler.endDocument();
    } else if (jsonValue.getValueType() == ValueType.ARRAY) {
        SAXUnmarshallerHandler rootContentHandler = null;
        if (getContentHandler() instanceof SAXUnmarshallerHandler) {
            rootContentHandler = (SAXUnmarshallerHandler) getContentHandler();
        }
        JsonArray jsonArray = (JsonArray) jsonValue;
        List<Object> list = new ArrayList<>(jsonArray.size());
        for (JsonValue aJsonArray : jsonArray) {
            parseRoot(aJsonArray);
            if (getContentHandler() instanceof SAXUnmarshallerHandler) {
                SAXUnmarshallerHandler saxUnmarshallerHandler = (SAXUnmarshallerHandler) contentHandler;
                list.add(saxUnmarshallerHandler.getObject());
                saxUnmarshallerHandler.setObject(null);
            } else if (getContentHandler() instanceof UnmarshalRecord) {
                UnmarshalRecord unmarshalRecord = (UnmarshalRecord) contentHandler;
                Object unmarshalledObject = unmarshalRecord.getCurrentObject();
                if (includeRoot && unmarshalClass != null) {
                    if (!(unmarshalledObject instanceof Root)) {
                        Root xmlRoot = unmarshalRecord.createRoot();
                        xmlRoot.setNamespaceURI(unmarshalRecord.getRootElementNamespaceUri());
                        xmlRoot.setLocalName(unmarshalRecord.getLocalName());
                        xmlRoot.setObject(unmarshalledObject);
                        unmarshalledObject = xmlRoot;
                    }
                }
                list.add(unmarshalledObject);
                unmarshalRecord.setCurrentObject(null);
                unmarshalRecord.setRootElementName(null);
                unmarshalRecord.setLocalName(null);
            }
        }
        if (getContentHandler() instanceof SAXUnmarshallerHandler) {
            ((SAXUnmarshallerHandler) getContentHandler()).setObject(list);
        } else if (getContentHandler() instanceof UnmarshalRecord) {
            ((UnmarshalRecord) getContentHandler()).setCurrentObject(list);
            ((UnmarshalRecord) getContentHandler()).setRootElementName(Constants.EMPTY_STRING);
            ((UnmarshalRecord) getContentHandler()).setLocalName(Constants.EMPTY_STRING);
            if (rootContentHandler != null) {
                rootContentHandler.setObject(list);
            }
        }
    } else {
        getContentHandler().startDocument();
        parseValue(jsonValue);
    }
}
Also used : SAXUnmarshallerHandler(org.eclipse.persistence.internal.oxm.record.SAXUnmarshallerHandler) Root(org.eclipse.persistence.internal.oxm.Root) JsonValue(jakarta.json.JsonValue) JsonObject(jakarta.json.JsonObject) JsonString(jakarta.json.JsonString) JsonArray(jakarta.json.JsonArray) Entry(java.util.Map.Entry) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) AbstractUnmarshalRecord(org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(jakarta.json.JsonObject)

Example 8 with UnmarshalRecord

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

the class MappingsGenerator method generateXMLObjectReferenceMapping.

/**
 * Create an XMLObjectReferenceMapping and add it to the descriptor.
 */
public ObjectReferenceMapping generateXMLObjectReferenceMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass referenceClass) {
    ObjectReferenceMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, UnmarshalRecord, XMLField, XMLRecord> mapping = new XMLObjectReferenceMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    mapping.setReferenceClassName(referenceClass.getQualifiedName());
    // here we need to setup source/target key field associations
    if (property.isSetXmlJoinNodes()) {
        for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
            validateJoinNode(descriptor.getJavaClassName(), property, xmlJoinNode.getReferencedXmlPath(), referenceClass);
            mapping.addSourceToTargetKeyFieldAssociation(xmlJoinNode.getXmlPath(), xmlJoinNode.getReferencedXmlPath());
        }
    } else {
        String tgtXPath = null;
        TypeInfo referenceType = typeInfo.get(referenceClass.getQualifiedName());
        if (null != referenceType && referenceType.isIDSet()) {
            Property prop = referenceType.getIDProperty();
            tgtXPath = getXPathForField(prop, namespaceInfo, !prop.isAttribute(), false).getXPath();
        }
        // if the XPath is set (via xml-path) use it, otherwise figure it out
        Field srcXPath;
        if (property.getXmlPath() != null) {
            srcXPath = new XMLField(property.getXmlPath());
        } else {
            srcXPath = getXPathForField(property, namespaceInfo, true, false);
        }
        mapping.addSourceToTargetKeyFieldAssociation(srcXPath.getXPath(), tgtXPath);
    }
    if (property.getInverseReferencePropertyName() != null) {
        mapping.getInverseReferenceMapping().setAttributeName(property.getInverseReferencePropertyName());
        JavaClass backPointerPropertyType = null;
        if (property.getInverseReferencePropertyGetMethodName() != null && property.getInverseReferencePropertySetMethodName() != null && !property.getInverseReferencePropertyGetMethodName().equals("") && !property.getInverseReferencePropertySetMethodName().equals("")) {
            mapping.getInverseReferenceMapping().setGetMethodName(property.getInverseReferencePropertySetMethodName());
            mapping.getInverseReferenceMapping().setSetMethodName(property.getInverseReferencePropertySetMethodName());
            JavaMethod getMethod = referenceClass.getDeclaredMethod(mapping.getInverseReferenceMapping().getGetMethodName(), new JavaClass[] {});
            if (getMethod != null) {
                backPointerPropertyType = getMethod.getReturnType();
            }
        } else {
            JavaField backpointerField = referenceClass.getDeclaredField(property.getInverseReferencePropertyName());
            if (backpointerField != null) {
                backPointerPropertyType = backpointerField.getResolvedType();
            }
        }
        if (helper.isCollectionType(backPointerPropertyType)) {
            mapping.getInverseReferenceMapping().setContainerPolicy(ContainerPolicy.buildDefaultPolicy());
        }
    }
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) XmlJoinNode(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) 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) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 9 with UnmarshalRecord

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

the class MappingsGenerator method generateXMLCollectionReferenceMapping.

/**
 * Create an XMLCollectionReferenceMapping and add it to the descriptor.
 */
public CollectionReferenceMapping generateXMLCollectionReferenceMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass referenceClass) {
    CollectionReferenceMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, UnmarshalRecord, XMLField, XMLRecord> mapping = new XMLCollectionReferenceMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    initializeXMLContainerMapping(mapping, property.getType().isArray());
    mapping.setUsesSingleNode(property.isXmlList() || (property.isAttribute() && (property.getXmlPath() == null || !property.getXmlPath().contains("/"))));
    String referenceClassName = referenceClass.getQualifiedName();
    JavaClass collectionType = property.getType();
    if (collectionType.isArray()) {
        JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
        JavaClass componentType = collectionType.getComponentType();
        if (componentType.isArray()) {
            Class<?> adaptedClass = classToGeneratedClasses.get(componentType.getName());
            referenceClassName = adaptedClass.getName();
            accessor.setAdaptedClassName(referenceClassName);
            JavaClass baseComponentType = getBaseComponentType(componentType);
            if (baseComponentType.isPrimitive()) {
                Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(baseComponentType.getRawName());
                accessor.setComponentClass(primitiveClass);
            } else {
                accessor.setComponentClassName(baseComponentType.getQualifiedName());
            }
        } else {
            accessor.setComponentClassName(componentType.getQualifiedName());
        }
        mapping.setAttributeAccessor(accessor);
    }
    collectionType = containerClassImpl(collectionType);
    mapping.useCollectionClassName(collectionType.getRawName());
    mapping.setReferenceClassName(referenceClassName);
    // here we need to setup source/target key field associations
    if (property.isSetXmlJoinNodes()) {
        for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
            validateJoinNode(descriptor.getJavaClassName(), property, xmlJoinNode.getReferencedXmlPath(), referenceClass);
            mapping.addSourceToTargetKeyFieldAssociation(xmlJoinNode.getXmlPath(), xmlJoinNode.getReferencedXmlPath());
        }
    } else {
        // here we need to setup source/target key field associations
        TypeInfo referenceType = typeInfo.get(referenceClass.getQualifiedName());
        String tgtXPath = null;
        if (null != referenceType && referenceType.isIDSet()) {
            Property prop = referenceType.getIDProperty();
            tgtXPath = getXPathForField(prop, namespaceInfo, !prop.isAttribute(), false).getXPath();
        }
        // if the XPath is set (via xml-path) use it
        Field srcXPath;
        if (property.getXmlPath() != null) {
            srcXPath = new XMLField(property.getXmlPath());
        } else {
            srcXPath = getXPathForField(property, namespaceInfo, true, false);
        }
        mapping.addSourceToTargetKeyFieldAssociation(srcXPath.getXPath(), tgtXPath);
    }
    if (property.getInverseReferencePropertyName() != null) {
        mapping.getInverseReferenceMapping().setAttributeName(property.getInverseReferencePropertyName());
        JavaClass backPointerPropertyType = null;
        if (property.getInverseReferencePropertyGetMethodName() != null && property.getInverseReferencePropertySetMethodName() != null && !property.getInverseReferencePropertyGetMethodName().equals("") && !property.getInverseReferencePropertySetMethodName().equals("")) {
            mapping.getInverseReferenceMapping().setGetMethodName(property.getInverseReferencePropertySetMethodName());
            mapping.getInverseReferenceMapping().setSetMethodName(property.getInverseReferencePropertySetMethodName());
            JavaMethod getMethod = referenceClass.getDeclaredMethod(mapping.getInverseReferenceMapping().getGetMethodName(), new JavaClass[] {});
            if (getMethod != null) {
                backPointerPropertyType = getMethod.getReturnType();
            }
        } else {
            JavaField backpointerField = referenceClass.getDeclaredField(property.getInverseReferencePropertyName());
            if (backpointerField != null) {
                backPointerPropertyType = backpointerField.getResolvedType();
            }
        }
        if (helper.isCollectionType(backPointerPropertyType)) {
            mapping.getInverseReferenceMapping().setContainerPolicy(ContainerPolicy.buildDefaultPolicy());
        }
    }
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) XmlJoinNode(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) 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) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Aggregations

UnmarshalRecord (org.eclipse.persistence.internal.oxm.record.UnmarshalRecord)9 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)3 JsonArray (jakarta.json.JsonArray)2 JsonString (jakarta.json.JsonString)2 JsonValue (jakarta.json.JsonValue)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)2 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)2 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)2 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)2 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)2 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)2 Field (org.eclipse.persistence.internal.oxm.mappings.Field)2 UnmarshalKeepAsElementPolicy (org.eclipse.persistence.internal.oxm.mappings.UnmarshalKeepAsElementPolicy)2 AbstractUnmarshalRecord (org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord)2 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)2 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2