gpt4 book ai didi

org.eclipse.persistence.platform.xml.XMLPlatform.validate()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-21 03:01:05 26 4
gpt4 key购买 nike

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

XMLPlatform.validate介绍

[英]Validates a document fragment against a complex type or element in the XML schema
[中]根据XML模式中的复杂类型或元素验证文档片段

代码示例

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

/**
* Validate the given object.
* @param object A single object to validate
* @return true if this is a valid object, otherwise false
*/
public boolean validate(Object object) throws XMLMarshalException {
  if (object == null) {
    throw XMLMarshalException.nullArgumentException();
  }
  try {
    // Create a new XML Record using the object's class name (not fully qualified) as the root            
    String name = ((XMLDescriptor)xmlContext.getSession(object).getDescriptor(object)).getDefaultRootElement();
    if (name == null) {
      String qualifiedName = object.getClass().getName();
      int idx = qualifiedName.lastIndexOf('.');
      name = qualifiedName.substring(idx + 1);
    }
    XMLDescriptor descriptor = marshaller.getDescriptor(object);
    XMLRoot root = new XMLRoot();
    root.setObject(object);
    root.setLocalName(name);
    
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    Document doc = xmlPlatform.createDocument();
    marshaller.marshal(root, doc);
    return xmlPlatform.validate(doc.getDocumentElement(), descriptor, getErrorHandler());
  } catch (XMLPlatformException e) {
    throw XMLMarshalException.validateException(e);
  }
}

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

/**
* Validate the given object.
* @param object A single object to validate
* @return true if this is a valid object, otherwise false
*/
public boolean validate(Object object) throws XMLMarshalException {
  if (object == null) {
    throw XMLMarshalException.nullArgumentException();
  }
  try {
    // Create a new XML Record using the object's class name (not fully qualified) as the root
    String name = ((XMLDescriptor)xmlContext.getSession(object).getDescriptor(object)).getDefaultRootElement();
    if (name == null) {
      String qualifiedName = object.getClass().getName();
      int idx = qualifiedName.lastIndexOf('.');
      name = qualifiedName.substring(idx + 1);
    }
    XMLDescriptor descriptor = marshaller.getDescriptor(object);
    Root root = new Root();
    root.setObject(object);
    root.setLocalName(name);
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    Document doc = xmlPlatform.createDocument();
    marshaller.marshal(root, doc);
    return xmlPlatform.validate(doc.getDocumentElement(), descriptor, getErrorHandler());
  } catch (XMLPlatformException e) {
    throw XMLMarshalException.validateException(e);
  }
}

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

/**
* Validate the given object.
* @param object A single object to validate
* @return true if this is a valid object, otherwise false
*/
public boolean validate(Object object) throws XMLMarshalException {
  if (object == null) {
    throw XMLMarshalException.nullArgumentException();
  }
  try {
    // Create a new XML Record using the object's class name (not fully qualified) as the root            
    String name = ((XMLDescriptor)xmlContext.getSession(object).getDescriptor(object)).getDefaultRootElement();
    if (name == null) {
      String qualifiedName = object.getClass().getName();
      int idx = qualifiedName.lastIndexOf('.');
      name = qualifiedName.substring(idx + 1);
    }
    XMLDescriptor descriptor = marshaller.getDescriptor(object);
    Root root = new Root();
    root.setObject(object);
    root.setLocalName(name);
    
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    Document doc = xmlPlatform.createDocument();
    marshaller.marshal(root, doc);
    return xmlPlatform.validate(doc.getDocumentElement(), descriptor, getErrorHandler());
  } catch (XMLPlatformException e) {
    throw XMLMarshalException.validateException(e);
  }
}

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