gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-20 02:25:40 26 4
gpt4 key购买 nike

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

XMLMarshaller介绍

[英]Class used to marshal object to XML.

Create an XMLMarshaller from an XMLContext.
Code Sample
XMLContext context = new XMLContext("mySessionName"); XMLMarshaller marshaller = context.createMarshaller(); [[$0$]]

[[$2$]]

[[$4$]]
[[$6$]]
[中]类,用于将对象封送到XML。
从XMLContext创建XMLMarshaller。
代码示例
XMLContext context = new XMLContext("mySessionName"); XMLMarshaller marshaller = context.createMarshaller(); [[$0$]]
[[$2$]]
[[$4$]]
[[$6$]]

代码示例

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

/**
* PUBLIC:
* Convert the given object to XML and update the given contentHandler with that XML Document
* @param object the object to marshal
* @param contentHandler the contentHandler which the specified object should be marshalled to
* @throws XMLMarshalException if an error occurred during marshalling
*/
public void marshal(Object object, ContentHandler contentHandler) throws XMLMarshalException {
  marshal(object, contentHandler, null);
}

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

public void serialize(XMLDocument xmlDocument, OutputStream outputStream, Object options) throws IOException {
  XMLMarshaller xmlMarshaller = getXmlMarshaller();        
  XMLAttachmentMarshaller attachmentMarshaller = xmlMarshaller.getAttachmentMarshaller();
  //temporarily null out the attachment marshaller as it should not be used during serialization
  xmlMarshaller.setAttachmentMarshaller(null);
  OutputStreamWriter writer = new OutputStreamWriter(outputStream, xmlMarshaller.getEncoding());    	
  save(xmlDocument, writer, xmlMarshaller);        
  xmlMarshaller.setAttachmentMarshaller(attachmentMarshaller);
}

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

public void setListener(Marshaller.Listener listener) {
  if(xmlMarshaller.getMarshalListener() == null) {
    xmlMarshaller.setMarshalListener(new JAXBMarshalListener(jaxbContext, this));
  }
  ((JAXBMarshalListener) xmlMarshaller.getMarshalListener()).setListener(listener);
}

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

/**
 * Convert the given object to XML and update the given marshal record with
 * that XML Document.
 * @param object the object to marshal
 * @param marshalRecord the marshalRecord to marshal the object to
 */
protected void marshal(Object object, AbstractSession session, MarshalRecord marshalRecord) {
  boolean isXMLRoot = (object instanceof Root);
  marshal(object, marshalRecord, session, getDescriptor(object, isXMLRoot), isXMLRoot);
}

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

throw new IllegalArgumentException();
} else if (JAXB_FORMATTED_OUTPUT.equals(key)) {
  return xmlMarshaller.isFormattedOutput();
} else if (JAXB_ENCODING.equals(key)) {
  return xmlMarshaller.getEncoding();
} else if (JAXB_SCHEMA_LOCATION.equals(key)) {
  return xmlMarshaller.getSchemaLocation();
} else if (JAXB_NO_NAMESPACE_SCHEMA_LOCATION.equals(key)) {
  return xmlMarshaller.getNoNamespaceSchemaLocation();
} else if (Constants.JAXB_FRAGMENT.equals(key)) {
  return xmlMarshaller.isFragment();
} else if (MarshallerProperties.MEDIA_TYPE.equals(key)) {
  return xmlMarshaller.getMediaType();
} else if (MarshallerProperties.NAMESPACE_PREFIX_MAPPER.equals(key)) {
  return xmlMarshaller.getNamespacePrefixMapper();
} else if (MarshallerProperties.INDENT_STRING.equals(key) || SUN_INDENT_STRING.equals(key) || SUN_JSE_INDENT_STRING.equals(key)) {
  return xmlMarshaller.getIndentString();
} else if (MarshallerProperties.CHARACTER_ESCAPE_HANDLER.equals(key)) {
  return xmlMarshaller.getCharacterEscapeHandler();
} else if (XML_DECLARATION.equals(key)) {
  return !xmlMarshaller.isFragment();
} else if (XML_HEADERS.equals(key)) {
  return xmlMarshaller.getXmlHeader();
} else if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(key)) {
  return xmlMarshaller.isEqualUsingIdenity();
} else if (MarshallerProperties.JSON_ATTRIBUTE_PREFIX.equals(key)) {
  return xmlMarshaller.getAttributePrefix();
} else if (MarshallerProperties.JSON_INCLUDE_ROOT.equals(key)) {
  return xmlMarshaller.isIncludeRoot();

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

session = xmlContext.getSession(((XMLRoot)object).getObject());                
  if(session != null){
    xmlDescriptor = getDescriptor(((XMLRoot)object).getObject(), session);
  if (!isSimpleXMLRoot((XMLRoot) object)) {
    throw marshalException;    
xmlDescriptor = getDescriptor(object.getClass(), session);
contentHandlerRecord.setContentHandler(contentHandler);
contentHandlerRecord.setLexicalHandler(lexicalHandler);
marshal(object, contentHandlerRecord, session, xmlDescriptor,isXMLRoot);
return;
  xmlDocument = objectToXML(object, xmlDescriptor, isXMLRoot);
if (isFragment()) {
  FragmentContentHandler fragmentHandler = new FragmentContentHandler(contentHandler);
  reader.setContentHandler(fragmentHandler);

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

anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
anXMLMarshaller.setEncoding(xmlDocument.getEncoding());
anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation());
anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation());
if(anXMLMarshaller.isFormattedOutput()) {
  writerRecord = new FormattedWriterRecord();
} else {
writerRecord.setMarshaller(anXMLMarshaller);
SDOMarshalListener listener = ((SDOMarshalListener)anXMLMarshaller.getMarshalListener());
  anXMLMarshaller.marshal(xmlDocument, writerRecord);
  writerRecord.flush();
}catch(XMLMarshalException xme){

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

anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
anXMLMarshaller.setEncoding(xmlDocument.getEncoding());
anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation());
anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation());
SDOMarshalListener listener = ((SDOMarshalListener)anXMLMarshaller.getMarshalListener());
  marshalRecord.setMarshaller(anXMLMarshaller);
  listener.setRootMarshalRecord(marshalRecord);
  anXMLMarshaller.marshal(xmlDocument, marshalRecord);
  marshalRecord.flush();
} else if(result instanceof DOMResult) {
  marshalRecord.setMarshaller(anXMLMarshaller);
  listener.setRootMarshalRecord(marshalRecord);
  anXMLMarshaller.marshal(xmlDocument, marshalRecord);
  marshalRecord.flush();
} else {
  String xml = writer.toString();
  StreamSource source = new StreamSource(new java.io.StringReader(xml));
  anXMLMarshaller.getTransformer().transform(source, result);

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

String encoding = getEncoding();
if (object instanceof XMLRoot) {
  isXMLRoot = true;
    session = xmlContext.getSession(((XMLRoot)object).getObject());
    if(session != null){
      xmlDescriptor = getDescriptor(((XMLRoot)object).getObject(), session);
    if (!isSimpleXMLRoot((XMLRoot) object)) {
      throw marshalException;    
  xmlDescriptor = getDescriptor(object.getClass(), session);
if (isFormattedOutput()) {
  writerRecord = new FormattedWriterRecord();
} else {
  marshal(object, writerRecord, session, xmlDescriptor, isXMLRoot);    
} else {
  try {
      xmlDocument = (Node)((XMLRoot)object).getObject();
    } else {
      xmlDocument = objectToXMLNode(object, session, xmlDescriptor, isXMLRoot);
    if (isFragment()) {
      writerRecord.node(xmlDocument, xmlDescriptor.getNamespaceResolver());
    } else {

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

if (getAttachmentMarshaller() != null) {
  marshalRecord.setXOPPackage(getAttachmentMarshaller().isXOPPackage());
addDescriptorNamespacesToXMLRecord(descriptor, marshalRecord);
NamespaceResolver nr = marshalRecord.getNamespaceResolver();
XMLRoot root = null;
if (getMarshalListener() != null) {
  getMarshalListener().beforeMarshal(object);
if (!isFragment()) {
  String encoding = getEncoding();
  String version = DEFAULT_XML_VERSION;
  if (!isXMLRoot) {
XPathFragment rootFragment = buildRootFragment(object, descriptor, isXMLRoot, marshalRecord);
boolean shouldWriteTypeAttribute = shouldWriteTypeAttribute(object, descriptor, isXMLRoot);
String schemaLocation = getSchemaLocation();
String noNsSchemaLocation = getNoNamespaceSchemaLocation();
if (isXMLRoot) {
  object = root.getObject();
if ((null != getSchemaLocation()) || (null != getNoNamespaceSchemaLocation()) || shouldWriteTypeAttribute) {
  xsiPrefix = nr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
  if (null == xsiPrefix) {
      writeTypeAttribute(marshalRecord, descriptor, xsiPrefix);

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

session = context.getSession(((Root)object).getObject());
if(session != null){
  xmlDescriptor = getDescriptor(((Root)object).getObject(), session);
if (!isSimpleXMLRoot((Root) object)) {
  throw marshalException;
  for(Object o : (Collection) object) {
    if (o == null) {
      valueWrapper = this.getValueWrapper();
      if (isApplicationJSON()) {
        this.setValueWrapper("");
        writerRecord.setMarshaller(this);
      this.setValueWrapper(valueWrapper);
    } else {
      if (isApplicationJSON() && o != null && (o.getClass() == CoreClassConstants.STRING || o.getClass() == CoreClassConstants.BOOLEAN || CoreClassConstants.NUMBER.isAssignableFrom(o.getClass()))) {
        if (writerRecord.getSession() == null) {
          writerRecord.setSession((CoreAbstractSession) this.getContext().getSession());
        valueWrapper = this.getValueWrapper();
        this.setValueWrapper("");
        writerRecord.setMarshaller(this);
        writerRecord.characters(null, o, null, false);
        this.setValueWrapper(valueWrapper);
      } else {
        marshal(o, writerRecord);
  return;

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

@Override
public Object getProperty(String propName) throws PropertyException {
  if (null == propName) {
    throw new IllegalArgumentException();
  }
  if (propName.equals(Marshaller.JAXB_ENCODING)) {
    return this.xmlBinder.getMarshaller().getEncoding();
  }
  if (propName.equals(Marshaller.JAXB_FORMATTED_OUTPUT)) {
    return this.xmlBinder.getMarshaller().isFormattedOutput();
  }
  if (propName.equals(Marshaller.JAXB_FRAGMENT)) {
    return this.xmlBinder.getMarshaller().isFragment();
  }
  if (propName.equals(Marshaller.JAXB_SCHEMA_LOCATION)) {
    return this.xmlBinder.getMarshaller().getSchemaLocation();
  }
  if (propName.equals(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION)) {
    return this.xmlBinder.getMarshaller().getNoNamespaceSchemaLocation();
  }
  throw new PropertyException(propName);
}

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

anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
WriterRecord writerRecord;
if(anXMLMarshaller.isFormattedOutput()) {
  writerRecord = new FormattedWriterRecord();
} else {
writerRecord.setMarshaller(anXMLMarshaller);
SDOMarshalListener listener = ((SDOMarshalListener)anXMLMarshaller.getMarshalListener());
  anXMLMarshaller.marshal(xmlDocument, writerRecord);
  writerRecord.flush();
}catch(XMLMarshalException xme){

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

/**
* INTERNAL:
* Convert the given object to an XML Document
* @param object the object to marshal
* @return the document which the specified object has been marshalled to
* @param descriptor the XMLDescriptor for the object being marshalled
* @throws XMLMarshalException if an error occurred during marshalling
*/
protected Document objectToXML(Object object, XMLDescriptor descriptor, boolean isXMLRoot) throws XMLMarshalException {
  AbstractSession session = xmlContext.getSession(descriptor);
  DocumentPreservationPolicy docPresPolicy = xmlContext.getDocumentPreservationPolicy(session);
  if (docPresPolicy != null && docPresPolicy.shouldPreserveDocument()) {
    XMLRecord xmlRow = null;
    if (!isXMLRoot) {
      xmlRow = (XMLRecord) ((XMLObjectBuilder) descriptor.getObjectBuilder()).createRecordFor(object, xmlContext.getDocumentPreservationPolicy(session));
      xmlRow.setMarshaller(this);
      if (getAttachmentMarshaller() != null) {
        xmlRow.setXOPPackage(getAttachmentMarshaller().isXOPPackage());
      }
      addDescriptorNamespacesToXMLRecord(descriptor, xmlRow);
    }
    return objectToXML(object, descriptor, xmlRow, isXMLRoot, docPresPolicy);
  }
  MarshalRecord marshalRecord = new NodeRecord();
  marshalRecord.setMarshaller(this);
  marshal(object, marshalRecord, session, descriptor, isXMLRoot);
  return marshalRecord.getDocument();
}

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

session = xmlContext.getSession(((XMLRoot)object).getObject());
    if(session != null){
      descriptor = getDescriptor(((XMLRoot)object).getObject(), session);
    if (!isSimpleXMLRoot((XMLRoot) object)) {
      throw marshalException;    
  descriptor = getDescriptor(object, session);
  XMLRecord xmlRow = (XMLRecord) ((XMLObjectBuilder) descriptor.getObjectBuilder()).createRecord(localRootName, parent, session);
  xmlRow.setMarshaller(this);
  if (getAttachmentMarshaller() != null) {
    xmlRow.setXOPPackage(getAttachmentMarshaller().isXOPPackage());
  return objectToXML(object, descriptor, xmlRow, isXMLRoot, docPresPolicy);
marshal(object, marshalRecord, session, descriptor, isXMLRoot);
return marshalRecord.getDocument();

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

@Override
public AttachmentMarshaller getAttachmentMarshaller() {
  if (xmlMarshaller.getAttachmentMarshaller() == null) {
    return null;
  }
  return ((AttachmentMarshallerAdapter) xmlMarshaller.getAttachmentMarshaller()).getAttachmentMarshaller();
}

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

public Marshaller.Listener getListener() {
  XMLMarshalListener xmlMarshalListener = xmlMarshaller.getMarshalListener();
  if(null != xmlMarshalListener) {
    return ((JAXBMarshalListener) xmlMarshalListener).getListener();
  }
  return null;
}

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

public XMLMarshaller getXmlMarshaller() {
  XMLMarshaller marshaller = xmlMarshallerMap.get(Thread.currentThread());
  if (marshaller == null) {
    marshaller = getXmlContext().createMarshaller();
    marshaller.setMarshalListener(new SDOMarshalListener(marshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
    xmlMarshallerMap.put(Thread.currentThread(), marshaller);
  }
  XMLContext context = getXmlContext();
  if (marshaller.getXMLContext() != context) {
    marshaller.setXMLContext(context);
  }
  return marshaller;
}

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

private void addSchemaLocations(Document document, AbstractSession session) {
  Element docElement = document.getDocumentElement();
  NamespaceResolver resolver = new NamespaceResolver();
  resolver.put(javax.xml.XMLConstants.XMLNS_ATTRIBUTE, javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
  resolver.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
  if ((getSchemaLocation() != null) || (getNoNamespaceSchemaLocation() != null)) {
    XMLField field = new XMLField("@xmlns:xsi");
    field.setNamespaceResolver(resolver);
    XPathEngine.getInstance().create(field, docElement, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, session);
  }
  if (getSchemaLocation() != null) {
    XMLField field = new XMLField("@xsi:" + XMLConstants.SCHEMA_LOCATION);
    field.setNamespaceResolver(resolver);
    XPathEngine.getInstance().create(field, docElement, getSchemaLocation(), session);
  }
  if (getNoNamespaceSchemaLocation() != null) {
    XMLField field = new XMLField("@xsi:" + XMLConstants.NO_NS_SCHEMA_LOCATION);
    field.setNamespaceResolver(resolver);
    XPathEngine.getInstance().create(field, docElement, getNoNamespaceSchemaLocation(), session);
  }
}

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

private Object wrapEnumeration(Object object, Class enumerationClass) {
  Class generatedClass = this.getClassToGeneratedClasses().get(enumerationClass.getName());
  if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
    ClassDescriptor desc = xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
    Object newObject = desc.getInstantiationPolicy().buildNewInstance();
    ((WrappedValue) newObject).setValue(object);
    object = newObject;
  }
  return object;
}

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