gpt4 book ai didi

org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 08:26:40 28 4
gpt4 key购买 nike

本文整理了Java中org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping类的一些代码示例,展示了XMLBinaryDataMapping类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLBinaryDataMapping类的具体详情如下:
包路径:org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping
类名称:XMLBinaryDataMapping

XMLBinaryDataMapping介绍

[英]Purpose:Provide a mapping for binary data that can be treated as either inline or as an attachment.

Responsibilities:

  • Handle converting binary types (byte[], Image etc) to base64
  • Make callbacks to AttachmentMarshaller/AttachmentUnmarshaller
  • Write out approriate attachment information (xop:include)

XMLBinaryDataMapping represents a mapping of binary data in the object model to XML. This can either be written directly as inline binary data (base64) or passed through as an MTOM or SWAREF attachment.

The following typed are allowable to be mapped using an XMLBinaryDataMapping:

  • java.awt.Image
  • byte[]
  • javax.activation.DataHandler
  • javax.xml.transform.Source
  • javax.mail.internet.MimeMultipart

Setting the XPath: TopLink XML mappings make use of XPath statements to find the relevant data in an XML document. The XPath statement is relative to the context node specified in the descriptor. The XPath may contain path and positional information; the last node in the XPath forms the local node for the binary mapping. The XPath is specified on the mapping using the setXPath method.

Inline Binary Data: Set this flag if you want to always inline binary data for this mapping. This will disable consideration for attachment handling for this mapping.

SwaRef: Set this flag in order to specify that the target node of this mapping is of type xs:swaref
[中]目的:为二进制数据提供映射,这些数据可以作为内联数据或附件处理。
责任:
*处理将二进制类型(字节[]、图像等)转换为base64的操作
*回调AttachmentMarshaller/AttachmentUnmarshaller
*写出适当的附件信息(xop:包括)
XMLBinaryDataMapping表示对象模型中的二进制数据到XML的映射。这可以直接作为内联二进制数据(base64)写入,也可以作为MTOM或SWAREF附件传递。
允许使用XMLBinaryDataMapping映射以下类型:
*爪哇。awt。形象
*字节[]
*javax。激活。数据处理器
*javax。xml。使改变来源
*javax。邮政互联网MimeMultipart
设置XPath:TopLink XML映射使用XPath语句在XML文档中查找相关数据。XPath语句与描述符中指定的上下文节点相关。XPath可能包含路径和位置信息;XPath中的最后一个节点构成二进制映射的本地节点。XPath是使用setXPath方法在映射上指定的。
内联二进制数据:如果希望始终为此映射内联二进制数据,请设置此标志。这将禁止考虑此映射的附件处理。
SwaRef:设置此标志以指定此映射的目标节点的类型为xs:SwaRef

代码示例

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

private DatabaseMapping buildXMLBinaryDataMapping(String mappingUri, MimeTypePolicy mimeTypePolicy) {
  XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
  mapping.setAttributeName(getName());
  String xpath = getQualifiedXPath(mappingUri, false);
  mapping.setMimeTypePolicy(mimeTypePolicy);
  mapping.setXPath(xpath);
  ((XMLField)mapping.getField()).setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
  
  if (shouldAddInstanceClassConverter()) {
    InstanceClassConverter converter = new InstanceClassConverter();
    converter.setCustomClass(getType().getInstanceClass());
    mapping.setConverter(converter);
  }
  // Set the null policy on the mapping
  // Use NullPolicy or IsSetNullPolicy 
  if (nullable) { // elements only
    setIsSetNillablePolicyOnMapping(mapping, propertyName);
  } else {
    // elements or attributes
    setIsSetOptionalPolicyOnMapping(mapping, propertyName);
  }
  mapping.getNullPolicy().setNullRepresentedByEmptyNode(true);
  return mapping;
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) {
  Object attributeValue = getAttributeValueFromObject(object);
  if (attributeValue == null) {
    XMLField field = (XMLField) getField();
    if(getNullPolicy() != null && !field.getXPathFragment().isSelfFragment()) {
      getNullPolicy().directMarshal((Field) this.getField(), (XMLRecord) row, object);
    }
    return;            
  }
  writeSingleValue(attributeValue, object, (XMLRecord) row, session);
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

private void addChoiceElementMapping(XMLField xmlField, Class theClass){
  if (xmlField.getLastXPathFragment().nameIsText() || xmlField.getLastXPathFragment().isAttribute()) {
    XMLDirectMapping xmlMapping = new XMLDirectMapping();
    xmlMapping.setAttributeClassification(theClass);
    xmlMapping.setAttributeAccessor(temporaryAccessor);
    xmlMapping.setField(xmlField);
    this.choiceElementMappings.put(xmlField, xmlMapping);
    this.choiceElementMappingsByClass.put(theClass, xmlMapping);
  } else {
    if(isBinaryType(theClass)) {
      XMLBinaryDataMapping xmlMapping = new XMLBinaryDataMapping();
      xmlMapping.setField(xmlField);
      xmlMapping.setAttributeClassification(theClass);
      xmlMapping.setAttributeAccessor(temporaryAccessor);
      this.choiceElementMappings.put(xmlField, xmlMapping);
      this.choiceElementMappingsByClass.put(theClass, xmlMapping);
    } else {
      XMLCompositeObjectMapping xmlMapping = new XMLCompositeObjectMapping();
      xmlMapping.setAttributeAccessor(temporaryAccessor);
      if(!theClass.equals(ClassConstants.OBJECT)){
        xmlMapping.setReferenceClass(theClass);
      }
      xmlMapping.setField(xmlField);
      this.choiceElementMappings.put(xmlField, xmlMapping);
      this.choiceElementMappingsByClass.put(theClass, xmlMapping);
    }
  }
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session) {
  Object attributeValue = getAttributeValueFromObject(object);
  if (attributeValue == null) {
    return;
  }
  writeSingleValue(attributeValue, object, (XMLRecord) row, session);
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("result");
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
mapping.setSwaRef(true);
mapping.setShouldInlineBinaryData(false);
mapping.setMimeType(attachment.getMimeType());
descriptor.addMapping(mapping);
    XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
    mapping.setAttributeName("result");
    mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
    mapping.setShouldInlineBinaryData(true);
    ((XMLField)mapping.getField()).setSchemaType(type);
    descriptor.addMapping(mapping);

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

public void writeSingleValue(Object attributeValue, Object parent, XMLRecord record, AbstractSession session) {
  XMLMarshaller marshaller = record.getMarshaller();
  attributeValue = convertObjectValueToDataValue(attributeValue, session, record.getMarshaller());
  XMLField field = (XMLField) getField();
  if (field.getLastXPathFragment().isAttribute()) {
    if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
        if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
          value = marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler) attributeValue);
        } else {
              attributeValue, marshaller, getMimeType(parent));
          byte[] bytes = data.getData();
          value = marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes, 0, bytes.length);
        throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName());
      XMLBinaryDataHelper.EncodedData data = XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue, record.getMarshaller(), getMimeType(parent));
      String base64Value = ((XMLConversionManager) session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData());
      record.put(field, base64Value);
  if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      if (getAttributeClassification() == ClassConstants.ABYTE) {
        attributeValue = ((XMLConversionManager) session.getDatasourcePlatform().getConversionManager()).convertObject(attributeValue, ClassConstants.APBYTE);
          this.getMimeType(parent),//
    } else if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object objectValue, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
  XMLMarshaller marshaller = marshalRecord.getMarshaller();
  if (xmlBinaryDataMapping.getConverter() != null) {
    Converter converter = xmlBinaryDataMapping.getConverter();
    if (converter instanceof XMLConverter) {
      objectValue = ((XMLConverter) converter).convertObjectValueToDataValue(objectValue, session, marshaller);
  if (xmlBinaryDataMapping.isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
    if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id = marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler) objectValue);
      if(c_id == null) {
            objectValue, marshaller, xmlBinaryDataMapping.getMimeType(object)).getData();
          objectValue, marshaller, xmlBinaryDataMapping.getMimeType(object));
      bytes = data.getData();
      c_id = marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes, 0, bytes.length);
  } else if (marshalRecord.isXOPPackage() && !xmlBinaryDataMapping.shouldInlineBinaryData()) {
    XPathFragment lastFrag = ((XMLField) xmlBinaryDataMapping.getField()).getLastXPathFragment();
    if (objectValue.getClass() == ClassConstants.APBYTE) {
      bytes = (byte[]) objectValue;
      c_id = marshaller.getAttachmentMarshaller().addMtomAttachment(bytes, 0, bytes.length, this.xmlBinaryDataMapping.getMimeType(object), lastFrag.getLocalName(), lastFrag.getNamespaceURI());
    } else if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      c_id = marshaller.getAttachmentMarshaller().addMtomAttachment((DataHandler) objectValue, lastFrag.getLocalName(), lastFrag.getNamespaceURI());
      if(c_id == null) {
            objectValue, marshaller, xmlBinaryDataMapping.getMimeType(object)).getData();

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.dbws

descriptor.setJavaClass(DataHandler.class);
descriptor.setInstantiationPolicy(new DataHandlerInstantiationPolicy(attachment.getMimeType()));
XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName(RESULTS_STR);
mapping.setAttributeAccessor(new AttributeAccessor() {
  @Override
  public Object getAttributeValueFromObject(Object object)
mapping.setXPath(DEFAULT_SIMPLE_XML_FORMAT_TAG + SLASH_CHAR +
  DEFAULT_SIMPLE_XML_TAG + ATTACHMENT_STR);
mapping.setSwaRef(true);
mapping.setShouldInlineBinaryData(false);
mapping.setMimeType(attachment.getMimeType());
descriptor.addMapping(mapping);
NamespaceResolver nr = new NamespaceResolver();

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

XMLUnmarshaller unmarshaller = ((XMLRecord) row).getUnmarshaller();
if (value instanceof String) {
  if (this.isSwaRef() && (unmarshaller.getAttachmentUnmarshaller() != null)) {
    if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler((String) value);
    } else {
      fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray((String) value);
  } else if (!this.isSwaRef()) {
  if (getNullPolicy().valueIsNull((Element) record.getDOM())) {
    return null;
  if ((unmarshaller.getAttachmentUnmarshaller() != null) && unmarshaller.getAttachmentUnmarshaller().isXOPPackage() && !this.isSwaRef() && !this.shouldInlineBinaryData()) {
    NamespaceResolver descriptorResolver = ((XMLDescriptor) getDescriptor()).getNamespaceResolver();
    String includeValue = (String) record.get(field);
    if (includeValue != null) {
      if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
        fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray(includeValue);
      } else {
  } else if ((unmarshaller.getAttachmentUnmarshaller() != null) && isSwaRef()) {
    String refValue = (String) record.get(XMLConstants.TEXT);
    if (refValue != null) {
Object attributeValue = convertDataValueToObjectValue(fieldValue, executionSession, unmarshaller);
attributeValue = XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(attributeValue, getAttributeClassification(), executionSession, null);

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

XMLField xmlField = (XMLField) mapping.getField();
XPathFragment frag = xmlField.getXPathFragment();
if (mapping.isSwaRef()) {
  schemaTypeString = getSchemaTypeString(XMLConstants.SWA_REF_QNAME, workingSchema);
} else {
    elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
  if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
    elem.setNillable(true);
    elem.setMinOccurs("1");
  if (mapping.getMimeType() != null) {
    elem.getAttributesMap().put(XMLConstants.EXPECTED_CONTENT_TYPES_QNAME, mapping.getMimeType());

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

XMLUnmarshaller unmarshaller = ((XMLRecord) row).getUnmarshaller();
if (value instanceof String) {
  if (this.isSwaRef() && (unmarshaller.getAttachmentUnmarshaller() != null)) {
    if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler((String) value);
    } else {
      fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray((String) value);
  } else if (!this.isSwaRef()) {
  if ((unmarshaller.getAttachmentUnmarshaller() != null) && unmarshaller.getAttachmentUnmarshaller().isXOPPackage() && !this.isSwaRef() && !this.shouldInlineBinaryData()) {
    NamespaceResolver descriptorResolver = ((XMLDescriptor) getDescriptor()).getNamespaceResolver();
    String includeValue = (String) record.get(field);
    if (includeValue != null) {
      if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
        fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray(includeValue);
      } else {
  } else if ((unmarshaller.getAttachmentUnmarshaller() != null) && isSwaRef()) {
    String refValue = (String) record.get(XMLConstants.TEXT);
    if (refValue != null) {
if (getConverter() != null) {
  if (getConverter() instanceof XMLConverter) {
    attributeValue = ((XMLConverter) getConverter()).convertDataValueToObjectValue(fieldValue, executionSession, unmarshaller);
  } else {
    attributeValue = getConverter().convertDataValueToObjectValue(fieldValue, executionSession);

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * Handle swaRef and inline attribute cases.
 */
public void attribute(UnmarshalRecord unmarshalRecord, String URI, String localName, String value) {
  unmarshalRecord.removeNullCapableValue(this);
  XMLField xmlField = (XMLField) xmlBinaryDataMapping.getField();
  XPathFragment lastFragment = xmlField.getLastXPathFragment();
  
  Object fieldValue = null;
  if (xmlBinaryDataMapping.isSwaRef()) {
    if (unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller() != null) {
      if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
        fieldValue = unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller().getAttachmentAsDataHandler(value);
      } else {
        fieldValue = unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller().getAttachmentAsByteArray(value);
      }
      xmlBinaryDataMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(fieldValue, xmlBinaryDataMapping.getAttributeClassification(), unmarshalRecord.getSession()));
    }
  } else {
    // value should be base64 binary string
    fieldValue = ((XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(value);
    xmlBinaryDataMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(fieldValue, xmlBinaryDataMapping.getAttributeClassification(), unmarshalRecord.getSession()));
  }
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.moxy

BinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("value");
mapping.setXPath(".");

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

field = (XMLField)((XMLBinaryDataCollectionMapping)mapping).getField();
} else {
  isSwaRef = ((XMLBinaryDataMapping)mapping).isSwaRef();
  field = (XMLField)((XMLBinaryDataMapping)mapping).getField();

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) {
  try {
    unmarshalRecord.removeNullCapableValue(this);
    XMLField xmlField = (XMLField) xmlBinaryDataMapping.getField();
    XPathFragment lastFragment = xmlField.getLastXPathFragment();
    BinaryMappingContentHandler handler = new BinaryMappingContentHandler(unmarshalRecord, this, this.xmlBinaryDataMapping);
    String qnameString = xPathFragment.getLocalName();
    if (xPathFragment.getPrefix() != null) {
      qnameString = xPathFragment.getPrefix() + XMLConstants.COLON + qnameString;
    }
    handler.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), qnameString, atts);
    unmarshalRecord.getXMLReader().setContentHandler(handler);
    return true;
  } catch(SAXException ex) {
    throw XMLMarshalException.unmarshalException(ex);
  }
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.dbws

XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("result");
mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
mapping.setSwaRef(true);
mapping.setShouldInlineBinaryData(false);
mapping.setMimeType(attachment.getMimeType());
descriptor.addMapping(mapping);
    XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
    mapping.setAttributeName("result");
    mapping.setXPath(SERVICE_NAMESPACE_PREFIX + ":" + "result");
    mapping.setShouldInlineBinaryData(true);
    ((XMLField)mapping.getField()).setSchemaType(type);
    descriptor.addMapping(mapping);

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

public void writeSingleValue(Object attributeValue, Object parent, XMLRecord record, AbstractSession session) {
  XMLMarshaller marshaller = record.getMarshaller();
  attributeValue = convertObjectValueToDataValue(attributeValue, session, record.getMarshaller());
  XMLField field = (XMLField) getField();
  if (field.getLastXPathFragment().isAttribute()) {
    if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
        if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
          value = marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler) attributeValue);
        } else {
              attributeValue, marshaller, getMimeType(parent));
          byte[] bytes = data.getData();
          value = marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes, 0, bytes.length);
        throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName());
      XMLBinaryDataHelper.EncodedData data = XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue, record.getMarshaller(), getMimeType(parent));
      String base64Value = ((XMLConversionManager) session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData());
      record.put(field, base64Value);
  if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      if (getAttributeClassification() == ClassConstants.ABYTE) {
        attributeValue = ((XMLConversionManager) session.getDatasourcePlatform().getConversionManager()).convertObject(attributeValue, ClassConstants.APBYTE);
          this.getMimeType(parent),//
    } else if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public void writeSingleValue(Object attributeValue, Object parent, XMLRecord record, AbstractSession session) {
  XMLMarshaller marshaller = record.getMarshaller();
  if (getConverter() != null) {
    Converter converter = getConverter();
    if (converter instanceof XMLConverter) {
      attributeValue = ((XMLConverter) converter).convertObjectValueToDataValue(attributeValue, session, record.getMarshaller());
  XMLField field = (XMLField) getField();
  if (field.getLastXPathFragment().isAttribute()) {
    if (isSwaRef() && (marshaller.getAttachmentMarshaller() != null)) {
        if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
          value = marshaller.getAttachmentMarshaller().addSwaRefAttachment((DataHandler) attributeValue);
        } else {
              attributeValue, marshaller, getMimeType(parent));
          byte[] bytes = data.getData();
          value = marshaller.getAttachmentMarshaller().addSwaRefAttachment(bytes, 0, bytes.length);
        throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName());
      XMLBinaryDataHelper.EncodedData data = XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue, record.getMarshaller(), getMimeType(parent));
      String base64Value = ((XMLConversionManager) session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData());
      record.put(field, base64Value);
  if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) {
    if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
      if (getAttributeClassification() == ClassConstants.ABYTE) {
        attributeValue = ((XMLConversionManager) session.getDatasourcePlatform().getConversionManager()).convertObject(attributeValue, ClassConstants.APBYTE);

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

descriptor.setJavaClass(DataHandler.class);
descriptor.setInstantiationPolicy(new DataHandlerInstantiationPolicy(attachment.getMimeType()));
XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName(RESULTS_STR);
mapping.setAttributeAccessor(new AttributeAccessor() {
  @Override
  public Object getAttributeValueFromObject(Object object)
mapping.setXPath(DEFAULT_SIMPLE_XML_FORMAT_TAG + SLASH_CHAR +
  DEFAULT_SIMPLE_XML_TAG + ATTACHMENT_STR);
mapping.setSwaRef(true);
mapping.setShouldInlineBinaryData(false);
mapping.setMimeType(attachment.getMimeType());
descriptor.addMapping(mapping);
NamespaceResolver nr = new NamespaceResolver();

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

XMLUnmarshaller unmarshaller = ((XMLRecord) row).getUnmarshaller();
if (value instanceof String) {
  if (this.isSwaRef() && (unmarshaller.getAttachmentUnmarshaller() != null)) {
    if (getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
      fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler((String) value);
    } else {
      fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray((String) value);
  } else if (!this.isSwaRef()) {
  if (getNullPolicy().valueIsNull((Element) record.getDOM())) {
    return null;
  if ((unmarshaller.getAttachmentUnmarshaller() != null) && unmarshaller.getAttachmentUnmarshaller().isXOPPackage() && !this.isSwaRef() && !this.shouldInlineBinaryData()) {
    NamespaceResolver descriptorResolver = ((XMLDescriptor) getDescriptor()).getNamespaceResolver();
    String includeValue = (String) record.get(field);
    if (includeValue != null) {
      if ((getAttributeClassification() == ClassConstants.ABYTE) || (getAttributeClassification() == ClassConstants.APBYTE)) {
        fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray(includeValue);
      } else {
  } else if ((unmarshaller.getAttachmentUnmarshaller() != null) && isSwaRef()) {
    String refValue = (String) record.get(XMLConstants.TEXT);
    if (refValue != null) {
Object attributeValue = convertDataValueToObjectValue(fieldValue, executionSession, unmarshaller);
attributeValue = XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(attributeValue, getAttributeClassification(), executionSession, null);

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com