当前位置: 首页>>代码示例>>Java>>正文


Java SchemaGlobalElement类代码示例

本文整理汇总了Java中org.apache.xmlbeans.SchemaGlobalElement的典型用法代码示例。如果您正苦于以下问题:Java SchemaGlobalElement类的具体用法?Java SchemaGlobalElement怎么用?Java SchemaGlobalElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SchemaGlobalElement类属于org.apache.xmlbeans包,在下文中一共展示了SchemaGlobalElement类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSampleForElement

import org.apache.xmlbeans.SchemaGlobalElement; //导入依赖的package包/类
public static String createSampleForElement( SchemaGlobalElement element )
{
	XmlObject xml = XmlObject.Factory.newInstance();

	XmlCursor c = xml.newCursor();
	c.toNextToken();
	c.beginElement( element.getName() );

	new SampleXmlUtil( false ).createSampleForType( element.getType(), c );

	c.dispose();

	XmlOptions options = new XmlOptions();
	options.put( XmlOptions.SAVE_PRETTY_PRINT );
	options.put( XmlOptions.SAVE_PRETTY_PRINT_INDENT, 3 );
	options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
	options.setSaveOuter();
	String result = xml.xmlText( options );

	return result;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:22,代码来源:SampleXmlUtil.java

示例2: validateSoapMessage

import org.apache.xmlbeans.SchemaGlobalElement; //导入依赖的package包/类
/**
 * Validate a soap message accordingly to its WSDL and linked XSD resources. The validation is
 * done for a specified message part (maybe be the input, output or fault of an operation).
 * @param partName The name of the part to validate ie. name of the input, output or fault part (ex: sayHello)
 * @param partNamespace The namespace of the part to validate (ex: http://www.mma.fr/test/service)
 * @param message The full soap message as a string
 * @param wsdlUrl The URL where we can resolve service and operation WSDL
 * @param validateMessageBody Should we validate also the body ? If false, only Soap envelope is validated.
 * @return The list of validation failures. If empty, message is valid !
 * @throws org.apache.xmlbeans.XmlException if given message is not a valid Xml document
 */
public static List<XmlError> validateSoapMessage(String partName, String partNamespace, String message, String wsdlUrl, boolean validateMessageBody) 
      throws XmlException {
   //
   WsdlContext ctx = new WsdlContext(wsdlUrl);
   List<XmlError> errors = new ArrayList<XmlError>();
   ctx.getSoapVersion().validateSoapEnvelope(message, errors);
   
   log.debug("SoapEnvelope validation errors: " + errors.size());

   if (validateMessageBody){
      // Create XmlBeans object for the soap message.
      XmlOptions xmlOptions = new XmlOptions();
      xmlOptions.setLoadLineNumbers();
      xmlOptions.setLoadLineNumbers( XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT );
      XmlObject xml = XmlUtils.createXmlObject(message, xmlOptions);

      // Build the QName string of the part name. Ex: {http://www.github.com/lbroudoux/service}sayHello
      String fullPartName = "{" + partNamespace + "}" + partName;
      
      // Extract the corresponding part from soap body.
      XmlObject[] paths = xml.selectPath( "declare namespace env='" + ctx.getSoapVersion().getEnvelopeNamespace() + "';" 
            + "declare namespace ns='" + partNamespace + "';" + "$this/env:Envelope/env:Body/ns:" + partName);
         
      SchemaGlobalElement elm;
      try {
         elm = ctx.getSchemaTypeLoader().findElement(QName.valueOf(fullPartName));
      } catch (Exception e) {
         log.error("Exception while loading schema information for " + fullPartName, e);
         throw new XmlException("Exception while loading schema information for " + fullPartName, e);
      }
      
      if ( elm != null ){
         validateMessageBody(ctx, errors, elm.getType(), paths[0]);
   
         // Ensure no other elements in body.
         NodeList children = XmlUtils.getChildElements((Element) paths[0].getDomNode().getParentNode());
         for (int c = 0; c < children.getLength(); c++){
            QName childName = XmlUtils.getQName(children.item(c));
            // Compare child QName to full part QName.
            if (!fullPartName.equals(childName.toString())){
               XmlCursor cur = paths[0].newCursor();
               cur.toParent();
               cur.toChild( childName );
               errors.add( XmlError.forCursor( "Invalid element [" + childName + "] in SOAP Body", cur ) );
               cur.dispose();
            }
         }
      }
      log.debug("SoapBody validation errors: " + errors.size());
   } 
   return errors;
}
 
开发者ID:microcks,项目名称:microcks,代码行数:64,代码来源:SoapMessageValidator.java


注:本文中的org.apache.xmlbeans.SchemaGlobalElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。