Search in sources :

Example 1 with BinaryMappingContentHandler

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

the class XMLBinaryDataCollectionMappingNodeValue method startElement.

@Override
public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) {
    try {
        Field xmlField = (Field) xmlBinaryDataCollectionMapping.getField();
        XPathFragment lastFragment = xmlField.getLastXPathFragment();
        if (!lastFragment.isAttribute()) {
            // set a new content handler to deal with the Include element's event.
            BinaryMappingContentHandler handler = new BinaryMappingContentHandler(unmarshalRecord, this, this.xmlBinaryDataCollectionMapping);
            String qnameString = xPathFragment.getLocalName();
            if (xPathFragment.getPrefix() != null) {
                qnameString = xPathFragment.getPrefix() + Constants.COLON + qnameString;
            }
            handler.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), qnameString, atts);
            XMLReader xmlReader = unmarshalRecord.getXMLReader();
            xmlReader.setContentHandler(handler);
            xmlReader.setLexicalHandler(handler);
        } else if (lastFragment.isAttribute()) {
            // handle swaRef and inline attribute cases here:
            String value = atts.getValue(lastFragment.getNamespaceURI(), lastFragment.getLocalName());
            Object fieldValue = null;
            if (xmlBinaryDataCollectionMapping.isSwaRef()) {
                if (unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller() != null) {
                    if (xmlBinaryDataCollectionMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
                        fieldValue = unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller().getAttachmentAsDataHandler(value);
                    } else {
                        fieldValue = unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller().getAttachmentAsByteArray(value);
                    }
                    xmlBinaryDataCollectionMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(fieldValue, xmlBinaryDataCollectionMapping.getAttributeClassification(), unmarshalRecord.getSession(), xmlBinaryDataCollectionMapping.getContainerPolicy()));
                }
            } else {
                // value should be base64 binary string
                fieldValue = ((ConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(value);
                xmlBinaryDataCollectionMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(fieldValue, xmlBinaryDataCollectionMapping.getAttributeClassification(), unmarshalRecord.getSession(), xmlBinaryDataCollectionMapping.getContainerPolicy()));
            }
        }
        return true;
    } catch (SAXException ex) {
        throw XMLMarshalException.unmarshalException(ex);
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) BinaryMappingContentHandler(org.eclipse.persistence.internal.oxm.record.deferred.BinaryMappingContentHandler) XMLReader(org.eclipse.persistence.internal.oxm.record.XMLReader) SAXException(org.xml.sax.SAXException)

Example 2 with BinaryMappingContentHandler

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

the class XMLBinaryDataMappingNodeValue method startElement.

@Override
public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) {
    try {
        unmarshalRecord.removeNullCapableValue(this);
        Field xmlField = (Field) xmlBinaryDataMapping.getField();
        BinaryMappingContentHandler handler = new BinaryMappingContentHandler(unmarshalRecord, this, this.xmlBinaryDataMapping);
        String qnameString = xPathFragment.getLocalName();
        if (xPathFragment.getPrefix() != null) {
            qnameString = xPathFragment.getPrefix() + Constants.COLON + qnameString;
        }
        handler.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), qnameString, atts);
        XMLReader xmlReader = unmarshalRecord.getXMLReader();
        xmlReader.setContentHandler(handler);
        xmlReader.setLexicalHandler(handler);
        return true;
    } catch (SAXException ex) {
        throw XMLMarshalException.unmarshalException(ex);
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) BinaryMappingContentHandler(org.eclipse.persistence.internal.oxm.record.deferred.BinaryMappingContentHandler) XMLReader(org.eclipse.persistence.internal.oxm.record.XMLReader) SAXException(org.xml.sax.SAXException)

Aggregations

Field (org.eclipse.persistence.internal.oxm.mappings.Field)2 XMLReader (org.eclipse.persistence.internal.oxm.record.XMLReader)2 BinaryMappingContentHandler (org.eclipse.persistence.internal.oxm.record.deferred.BinaryMappingContentHandler)2 SAXException (org.xml.sax.SAXException)2