Search in sources :

Example 11 with XPathNode

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

the class JAXBValueStore method getJAXBMappingForProperty.

/**
 * Return the JAXB mapping for the SDO property.  They are matched
 * on their XML schema representation.
 */
Mapping getJAXBMappingForProperty(SDOProperty sdoProperty) {
    DatabaseMapping sdoMapping = sdoProperty.getXmlMapping();
    XMLField field;
    if (sdoMapping instanceof XMLObjectReferenceMapping) {
        XMLObjectReferenceMapping referenceMapping = (XMLObjectReferenceMapping) sdoMapping;
        field = (XMLField) referenceMapping.getFields().get(0);
    } else {
        field = (XMLField) sdoMapping.getField();
    }
    TreeObjectBuilder treeObjectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder();
    XPathNode xPathNode = treeObjectBuilder.getRootXPathNode();
    XPathFragment xPathFragment = field.getXPathFragment();
    while (xPathNode != null && xPathFragment != null) {
        if (xPathFragment.isAttribute()) {
            if (sdoProperty.isMany() && !sdoProperty.isContainment() && !sdoProperty.getType().isDataType()) {
                xPathFragment = null;
                break;
            }
            Map<XPathFragment, XPathNode> attributeChildrenMap = xPathNode.getAttributeChildrenMap();
            if (null == attributeChildrenMap) {
                xPathNode = null;
            } else {
                xPathNode = attributeChildrenMap.get(xPathFragment);
            }
        } else if (xPathFragment.nameIsText()) {
            xPathNode = xPathNode.getTextNode();
        } else {
            Map<XPathFragment, XPathNode> nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
            if (null == nonAttributeChildrenMap) {
                xPathNode = null;
            } else {
                xPathNode = nonAttributeChildrenMap.get(xPathFragment);
            }
        }
        xPathFragment = xPathFragment.getNextFragment();
        if (xPathFragment != null && xPathFragment.nameIsText()) {
            if (sdoProperty.isMany() && !sdoProperty.isContainment()) {
                xPathFragment = null;
                break;
            }
        }
    }
    if (null == xPathFragment && xPathNode != null) {
        if (xPathNode.getNodeValue().isMappingNodeValue()) {
            MappingNodeValue mappingNodeValue = (MappingNodeValue) xPathNode.getNodeValue();
            return mappingNodeValue.getMapping();
        }
    }
    throw SDOException.sdoJaxbNoMappingForProperty(sdoProperty.getName(), field.getXPath());
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) TreeObjectBuilder(org.eclipse.persistence.internal.oxm.TreeObjectBuilder) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode)

Aggregations

XPathNode (org.eclipse.persistence.internal.oxm.XPathNode)11 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)8 SAXParseException (org.xml.sax.SAXParseException)5 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)4 MappingNodeValue (org.eclipse.persistence.internal.oxm.MappingNodeValue)4 NodeValue (org.eclipse.persistence.internal.oxm.NodeValue)4 TransformationMapping (org.eclipse.persistence.internal.oxm.mappings.TransformationMapping)3 HashMap (java.util.HashMap)2 ContainerValue (org.eclipse.persistence.internal.oxm.ContainerValue)2 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)2 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)2 JsonArray (jakarta.json.JsonArray)1 JsonBuilderFactory (jakarta.json.JsonBuilderFactory)1 JsonObjectBuilder (jakarta.json.JsonObjectBuilder)1 JsonString (jakarta.json.JsonString)1 JsonValue (jakarta.json.JsonValue)1 ValueType (jakarta.json.JsonValue.ValueType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1