Search in sources :

Example 6 with XPathNode

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

the class UnmarshalRecordImpl method endElement.

@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    try {
        if (null != selfRecords) {
            for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
                UnmarshalRecord selfRecord = selfRecords.get(x);
                if (selfRecord != null) {
                    selfRecord.endElement(namespaceURI, localName, qName);
                } else {
                    getFragmentBuilder().endSelfElement(namespaceURI, localName, qName);
                }
            }
        }
        if (-1 != unmappedLevel && unmappedLevel <= levelIndex) {
            if (levelIndex == unmappedLevel) {
                unmappedLevel = -1;
            }
            levelIndex--;
            return;
        }
        NodeValue unmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
        if (null != unmarshalNodeValue) {
            boolean isIncludedInAttributeGroup = true;
            if (unmarshalNodeValue.isMappingNodeValue()) {
                Mapping mapping = ((MappingNodeValue) unmarshalNodeValue).getMapping();
                isIncludedInAttributeGroup = this.unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName());
            }
            try {
                if (isIncludedInAttributeGroup) {
                    unmarshalNodeValue.endElement(xPathFragment, this);
                } else {
                    resetStringBuffer();
                }
            } catch (EclipseLinkException e) {
                if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
                    throw e;
                } else {
                    SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), getDocumentLocator(), e);
                    xmlReader.getErrorHandler().warning(saxParseException);
                }
            }
        } else {
            XPathNode textNode = xPathNode.getTextNode();
            if (null != textNode && getStringBuffer().length() == 0) {
                NodeValue textNodeUnmarshalNodeValue = textNode.getUnmarshalNodeValue();
                if (textNode.isWhitespaceAware()) {
                    if (textNodeUnmarshalNodeValue.isMappingNodeValue()) {
                        Mapping mapping = ((MappingNodeValue) textNodeUnmarshalNodeValue).getMapping();
                        if (mapping.isAbstractDirectMapping() && isNil()) {
                            Object nullValue = ((DirectMapping) mapping).getNullValue();
                            if (!(Constants.EMPTY_STRING.equals(nullValue))) {
                                setAttributeValue(null, mapping);
                                this.removeNullCapableValue((NullCapableValue) textNodeUnmarshalNodeValue);
                            }
                        } else {
                            textNodeUnmarshalNodeValue.endElement(xPathFragment, this);
                        }
                        setNil(false);
                    }
                } else {
                    // This means empty tag
                    if (textNodeUnmarshalNodeValue.isMappingNodeValue()) {
                        Mapping mapping = ((MappingNodeValue) textNodeUnmarshalNodeValue).getMapping();
                        if (mapping.isAbstractDirectMapping() && isNil()) {
                            Object nullValue = ((DirectMapping) mapping).getNullValue();
                            if (!(Constants.EMPTY_STRING.equals(nullValue))) {
                                setAttributeValue(null, mapping);
                            }
                        }
                        if (mapping.isAbstractDirectMapping() && !isNil() && ((DirectMapping) mapping).getNullPolicy().isNullRepresentedByXsiNil()) {
                            removeNullCapableValue((NullCapableValue) textNodeUnmarshalNodeValue);
                        }
                    }
                }
            }
        }
        XPathFragment xPathFragment = xPathNode.getXPathFragment();
        if ((null != xPathFragment && xPathFragment.nameIsText()) || (xpathNodeIsMixedContent && xPathNode.getParent() != null)) {
            xPathNode = xPathNode.getParent();
        }
        NodeValue xPathNodeUnmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
        if (null != xPathNodeUnmarshalNodeValue && xPathNodeUnmarshalNodeValue.isContainerValue()) {
            predictedNextXPathNode = xPathNode;
        } else {
            predictedNextXPathNode = xPathNode.getNextNode();
        }
        if (null != xPathNode.getParent()) {
            xPathNode = xPathNode.getParent();
        }
        xpathNodeIsMixedContent = false;
        unmarshalContext.endElement(this);
        typeQName = null;
        levelIndex--;
        if (isNil() && levelIndex > 0) {
            setNil(false);
        }
        if ((0 == levelIndex) && (null != parentRecord) && !isSelfRecord()) {
            endDocument();
            // don't endElement on, or pass control to, a 'self' parent
            UnmarshalRecord pRec = parentRecord;
            while (pRec.isSelfRecord()) {
                pRec = pRec.getParentRecord();
            }
            pRec.endElement(namespaceURI, localName, qName);
            xmlReader.setContentHandler(pRec);
            xmlReader.setLexicalHandler(pRec);
        }
    } catch (EclipseLinkException e) {
        if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
            throw e;
        } else {
            Locator locator = xmlReader.getLocator();
            SAXParseException saxParseException = new SAXParseException(null, getDocumentLocator(), e);
            xmlReader.getErrorHandler().warning(saxParseException);
        }
    }
}
Also used : MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue) NodeValue(org.eclipse.persistence.internal.oxm.NodeValue) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode) Locator(org.xml.sax.Locator) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) SAXParseException(org.xml.sax.SAXParseException) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue)

Example 7 with XPathNode

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

the class UnmarshalRecordImpl method startElement.

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    if (currentObject == null) {
        initializeRecord(atts);
    }
    XPathFragment xPathNodeXPathFragment = xPathNode.getXPathFragment();
    if ((null != xPathNodeXPathFragment && xPathNodeXPathFragment.nameIsText()) || xpathNodeIsMixedContent) {
        xpathNodeIsMixedContent = false;
        NodeValue xPathNodeUnmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
        if (null != xPathNodeUnmarshalNodeValue) {
            boolean isIncludedInAttributeGroup = true;
            if (xPathNodeUnmarshalNodeValue.isMappingNodeValue()) {
                Mapping mapping = ((MappingNodeValue) xPathNodeUnmarshalNodeValue).getMapping();
                isIncludedInAttributeGroup = this.unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName());
            }
            if (isIncludedInAttributeGroup) {
                xPathNodeUnmarshalNodeValue.endElement(xPathFragment, this);
                if (xPathNode.getParent() != null) {
                    xPathNode = xPathNode.getParent();
                }
            }
        }
    }
    // schema locations etc.
    if (null == rootElementName && null == rootElementLocalName && parentRecord == null) {
        rootElementLocalName = localName;
        rootElementName = qName;
        rootElementNamespaceUri = namespaceURI;
        schemaLocation = atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.SCHEMA_LOCATION);
        noNamespaceSchemaLocation = atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.NO_NS_SCHEMA_LOCATION);
    }
    try {
        if (null != selfRecords) {
            for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
                UnmarshalRecord selfRecord = selfRecords.get(x);
                if (selfRecord == null) {
                    getFragmentBuilder().startElement(namespaceURI, localName, qName, atts);
                } else {
                    selfRecord.startElement(namespaceURI, localName, qName, atts);
                }
            }
        }
        if (unmappedLevel != -1 && unmappedLevel <= levelIndex) {
            levelIndex++;
            return;
        }
        XPathNode node = null;
        if (null != predictedNextXPathNode) {
            XPathFragment xpf = predictedNextXPathNode.getXPathFragment();
            if (null != xpf && xPathNode == predictedNextXPathNode.getParent() && (localName == xpf.getLocalName() || localName.equals(xpf.getLocalName())) && (namespaceURI == xpf.getNamespaceURI() || namespaceURI.equals(xpf.getNamespaceURI())) && null == xpf.getPredicate() && !xpf.containsIndex()) {
                updateXPathFragment(qName, localName, namespaceURI);
                node = predictedNextXPathNode;
            }
        }
        if (null == node) {
            node = getNonAttributeXPathNode(namespaceURI, localName, qName, atts);
        }
        if (null == node) {
            NodeValue parentNodeValue = xPathNode.getUnmarshalNodeValue();
            if ((null == xPathNode.getXPathFragment()) && (parentNodeValue != null)) {
                XPathFragment parentFragment = new XPathFragment();
                parentFragment.setNamespaceAware(isNamespaceAware());
                if (namespaceURI != null && namespaceURI.length() == 0) {
                    parentFragment.setLocalName(qName);
                    parentFragment.setNamespaceURI(null);
                } else {
                    parentFragment.setLocalName(localName);
                    parentFragment.setNamespaceURI(namespaceURI);
                }
                if (parentNodeValue.startElement(parentFragment, this, atts)) {
                    levelIndex++;
                } else {
                    // UNMAPPED CONTENT
                    startUnmappedElement(namespaceURI, localName, qName, atts);
                    return;
                }
            } else {
                // UNMAPPED CONTENT
                levelIndex++;
                startUnmappedElement(namespaceURI, localName, qName, atts);
                return;
            }
        } else {
            xPathNode = node;
            unmarshalContext.startElement(this);
            levelIndex++;
            if (xmlReader.getMediaType().isApplicationXML()) {
                String xsiNilValue = atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.SCHEMA_NIL_ATTRIBUTE);
                if (xsiNilValue != null) {
                    setNil(xsiNilValue.equals(Constants.BOOLEAN_STRING_TRUE) || xsiNilValue.equals("1"));
                }
            }
            if (node.getNullCapableValue() != null) {
                getNullCapableValues().add(node.getNullCapableValue());
            }
            NodeValue nodeValue = node.getUnmarshalNodeValue();
            if (null != nodeValue) {
                boolean isIncludedInAttributeGroup = true;
                if (nodeValue.isMappingNodeValue()) {
                    Mapping mapping = ((MappingNodeValue) nodeValue).getMapping();
                    isIncludedInAttributeGroup = this.unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName());
                }
                if (!isIncludedInAttributeGroup || !nodeValue.startElement(xPathFragment, this, atts)) {
                    // UNMAPPED CONTENT
                    startUnmappedElement(namespaceURI, localName, qName, atts);
                    return;
                }
            }
            // Handle Attributes
            if (xPathNode.getAttributeChildren() != null || xPathNode.getAnyAttributeNodeValue() != null || selfRecords != null) {
                for (int i = 0, size = atts.getLength(); i < size; i++) {
                    String attNamespace = atts.getURI(i);
                    String attLocalName = atts.getLocalName(i);
                    String value = atts.getValue(i);
                    NodeValue attributeNodeValue = null;
                    // attributes
                    if ((attLocalName == null) || (attLocalName.length() == 0)) {
                        String qname = atts.getQName(i);
                        if (qname != null) {
                            int qnameLength = qname.length();
                            if (qnameLength > 0) {
                                int idx = qname.indexOf(Constants.COLON);
                                if (idx > 0) {
                                    attLocalName = qname.substring(idx + 1, qnameLength);
                                    String attPrefix = qname.substring(0, idx);
                                    if (attPrefix.equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) {
                                        attNamespace = javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
                                    }
                                } else {
                                    attLocalName = qname;
                                    if (attLocalName.equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) {
                                        attNamespace = javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
                                    }
                                }
                            }
                        }
                    }
                    // Look for any Self-Mapping nodes that may want this attribute.
                    if (this.selfRecords != null) {
                        for (int j = 0; j < selfRecords.size(); j++) {
                            UnmarshalRecord nestedRecord = selfRecords.get(j);
                            if (nestedRecord != null) {
                                attributeNodeValue = nestedRecord.getAttributeChildNodeValue(attNamespace, attLocalName);
                                if (attributeNodeValue != null) {
                                    attributeNodeValue.attribute(nestedRecord, attNamespace, attLocalName, value);
                                }
                            }
                        }
                    }
                    if (attributeNodeValue == null) {
                        attributeNodeValue = this.getAttributeChildNodeValue(attNamespace, attLocalName);
                        try {
                            if (attributeNodeValue != null) {
                                if (attributeNodeValue.isMappingNodeValue()) {
                                    Mapping mapping = ((MappingNodeValue) attributeNodeValue).getMapping();
                                    if (!unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName())) {
                                        continue;
                                    }
                                }
                                attributeNodeValue.attribute(this, attNamespace, attLocalName, value);
                            } else {
                                if (xPathNode.getAnyAttributeNodeValue() != null) {
                                    xPathNode.getAnyAttributeNodeValue().attribute(this, attNamespace, attLocalName, value);
                                }
                            }
                        } catch (EclipseLinkException e) {
                            if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
                                throw e;
                            } else {
                                SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), getDocumentLocator(), e);
                                xmlReader.getErrorHandler().warning(saxParseException);
                            }
                        }
                    }
                }
            }
        }
        if (prefixesForFragment != null) {
            this.prefixesForFragment.clear();
        }
    } catch (EclipseLinkException e) {
        if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
            throw e;
        } else {
            SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), getDocumentLocator(), e);
            xmlReader.getErrorHandler().error(saxParseException);
        }
    }
}
Also used : MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue) NodeValue(org.eclipse.persistence.internal.oxm.NodeValue) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) SAXParseException(org.xml.sax.SAXParseException) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode)

Example 8 with XPathNode

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

the class UnmarshalRecordImpl method getNonAttributeXPathNode.

/**
 * INTERNAL:
 */
@Override
public XPathNode getNonAttributeXPathNode(String namespaceURI, String localName, String qName, Attributes attributes) {
    if (0 == levelIndex) {
        return xPathNode;
    }
    updateXPathFragment(qName, localName, namespaceURI);
    Map<XPathFragment, XPathNode> nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
    if (null != nonAttributeChildrenMap) {
        XPathNode resultNode;
        if (unmarshaller.isCaseInsensitive()) {
            resultNode = getNodeFromLookupTable(nonAttributeChildrenMap, false);
        } else {
            resultNode = nonAttributeChildrenMap.get(xPathFragment);
        }
        XPathNode nonPredicateNode = null;
        if (resultNode != null && resultNode.hasPredicateSiblings()) {
            nonPredicateNode = resultNode;
            resultNode = null;
        }
        if (null == resultNode) {
            // POSITIONAL MAPPING
            int newIndex;
            if (null == this.indexMap) {
                this.indexMap = new HashMap();
                newIndex = 1;
            } else {
                Integer oldIndex = indexMap.get(xPathFragment);
                if (null == oldIndex) {
                    newIndex = 1;
                } else {
                    newIndex = oldIndex + 1;
                }
            }
            indexMap.put(xPathFragment, newIndex);
            XPathFragment predicateFragment = new XPathFragment();
            predicateFragment.setNamespaceAware(isNamespaceAware());
            predicateFragment.setNamespaceURI(xPathFragment.getNamespaceURI());
            predicateFragment.setLocalName(xPathFragment.getLocalName());
            predicateFragment.setIndexValue(newIndex);
            resultNode = nonAttributeChildrenMap.get(predicateFragment);
            if (null == resultNode) {
                predicateFragment.setIndexValue(-1);
                if (attributes != null) {
                    for (int x = 0, length = attributes.getLength(); x < length; x++) {
                        XPathFragment conditionFragment = new XPathFragment();
                        conditionFragment.setLocalName(attributes.getLocalName(x));
                        conditionFragment.setNamespaceURI(attributes.getURI(x));
                        conditionFragment.setAttribute(true);
                        XPathPredicate condition = new XPathPredicate(conditionFragment, attributes.getValue(x));
                        predicateFragment.setPredicate(condition);
                        resultNode = nonAttributeChildrenMap.get(predicateFragment);
                        if (null != resultNode) {
                            break;
                        }
                    }
                }
                // if json, check for text wrapper before handing off to the any
                if (null == resultNode && xPathNode.getTextNode() != null) {
                    XPathFragment textWrapperFragment = getTextWrapperFragment();
                    if (textWrapperFragment != null && localName.equals(textWrapperFragment.getLocalName())) {
                        resultNode = xPathNode.getTextNode();
                    }
                }
                if (null == resultNode && null == nonPredicateNode) {
                    // ANY MAPPING
                    resultNode = xPathNode.getAnyNode();
                }
            }
        }
        if (resultNode == null && nonPredicateNode != null) {
            return nonPredicateNode;
        }
        return resultNode;
    }
    return null;
}
Also used : XPathPredicate(org.eclipse.persistence.internal.oxm.XPathPredicate) HashMap(java.util.HashMap) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode)

Example 9 with XPathNode

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

the class UnmarshalRecordImpl method characters.

@Override
public void characters(char[] ch, int start, int length) throws SAXException {
    if (currentObject == null) {
        return;
    }
    try {
        int strBufferInitialLength = -1;
        if (null != selfRecords) {
            strBufferInitialLength = getStringBuffer().length();
            for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
                UnmarshalRecord selfRecord = selfRecords.get(x);
                if (selfRecord != null) {
                    selfRecord.characters(ch, start, length);
                } else {
                    getFragmentBuilder().characters(ch, start, length);
                }
            }
        }
        if (-1 != unmappedLevel && unmappedLevel <= levelIndex) {
            return;
        }
        XPathNode textNode = xPathNode.getTextNode();
        if (null == textNode) {
            textNode = xPathNode.getAnyNode();
            if (textNode != null) {
                xpathNodeIsMixedContent = true;
                this.xPathFragment.setLocalName(null);
                this.xPathFragment.setNamespaceURI(null);
                if (0 == length) {
                    return;
                }
            }
        }
        if (null != textNode) {
            if (textNode.getUnmarshalNodeValue().isMixedContentNodeValue()) {
                String tmpString = new String(ch, start, length);
                if (!textNode.isWhitespaceAware() && tmpString.trim().length() == 0) {
                    return;
                }
            }
            xPathNode = textNode;
            unmarshalContext.characters(this);
        }
        NodeValue unmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
        if (null != unmarshalNodeValue && !unmarshalNodeValue.isWrapperNodeValue()) {
            if (strBufferInitialLength == -1) {
                getStringBuffer().append(ch, start, length);
            } else {
                StrBuffer strBuffer = getStringBuffer();
                if (strBufferInitialLength == strBuffer.length()) {
                    strBuffer.append(ch, start, length);
                }
            }
        }
    } catch (EclipseLinkException e) {
        if (null == xmlReader.getErrorHandler()) {
            throw e;
        } else {
            SAXParseException saxParseException = new SAXParseException(null, getDocumentLocator(), e);
            xmlReader.getErrorHandler().error(saxParseException);
        }
    }
}
Also used : MappingNodeValue(org.eclipse.persistence.internal.oxm.MappingNodeValue) NodeValue(org.eclipse.persistence.internal.oxm.NodeValue) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) SAXParseException(org.xml.sax.SAXParseException) XPathNode(org.eclipse.persistence.internal.oxm.XPathNode) StrBuffer(org.eclipse.persistence.internal.oxm.StrBuffer)

Example 10 with XPathNode

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

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