gpt4 book ai didi

javax.xml.xquery.XQItemAccessor类的使用及代码示例

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

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

XQItemAccessor介绍

[英]This interface represents a common interface for accessing the values of an XQuery item. All the get functions raise an exception if the underlying sequence object is not positioned on an item (e.g. if the sequence is positioned before the first item or after the last item).

Example -

XQPreparedExpression expr = conn.prepareExpression("for $i .."); 
XQSequence result = expr.executeQuery(); 
// create the ItemTypes for string and integer 
XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING); 
XQItemType intType = conn.createAtomicType(XQItemType.XQBASETYPE_INTEGER); 
// posititioned before the first item 
while (result.next()) 
{ 
// If string or any of its subtypes, then get the string value out 
if (result.instanceOf(strType)) 
String str = result.getAtomicValue(); 
else if (result.instanceOf(intType)) 
// if it is exactly an int 
int intval = result.getInt(); 
... 
// Alternatively, you can get the exact type out. 
XQItemType type = result.getItemType(); 
// Now perform the comparison.. 
if (type.equals(intType)) 
{ ... }; 
}

See also:

  • Table 6 - XQuery Atomic Types and Corresponding Java Object Types, XQuery API for Java (XQJ) 1.0, for mapping of XQuery atomic types to Java object types. For example, if the XQuery value returned is of type xs:unsignedByte, then calling the getObject() method will return a Java object of type java.lang.Short.
  • Table 7 - XQuery Node Types and Corresponding Java Object Types XQuery API for Java (XQJ) 1.0, for the mapping of XQuery node types to the corresponding Java object types. For example, if the XQuery value returned is an element node, then calling the getObject() or getNode() method will return a Java object of type org.w3.dom.Element.
    [中]此接口表示用于访问XQuery项的值的公共接口。如果基础序列对象未定位在某个项上(例如,如果序列位于第一个项之前或最后一个项之后),则所有get函数都会引发异常。
    示例-
XQPreparedExpression expr = conn.prepareExpression("for $i .."); 
XQSequence result = expr.executeQuery(); 
// create the ItemTypes for string and integer 
XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING); 
XQItemType intType = conn.createAtomicType(XQItemType.XQBASETYPE_INTEGER); 
// posititioned before the first item 
while (result.next()) 
{ 
// If string or any of its subtypes, then get the string value out 
if (result.instanceOf(strType)) 
String str = result.getAtomicValue(); 
else if (result.instanceOf(intType)) 
// if it is exactly an int 
int intval = result.getInt(); 
... 
// Alternatively, you can get the exact type out. 
XQItemType type = result.getItemType(); 
// Now perform the comparison.. 
if (type.equals(intType)) 
{ ... }; 
}

另请参见:
*表6-XQuery原子类型和相应的Java对象类型,XQuery API for Java(XQJ)1.0,用于将XQuery原子类型映射到Java对象类型。例如,如果返回的XQuery值是xs:unsignedByte类型,那么调用getObject()方法将返回java.lang.Short类型的Java对象。
*表7-XQuery节点类型和相应的Java对象类型XQuery API for Java(XQJ)1.0,用于将XQuery节点类型映射到相应的Java对象类型。例如,如果返回的XQuery值是一个元素节点,那么调用getObject()getNode()方法将返回org.w3.dom.Element类型的Java对象。

代码示例

代码示例来源:origin: dsukhoroslov/bagri

protected Collection<String> fetchQueryResults(String query, Map<String, Object> params, Properties props) throws Exception {
  List<String> result = new ArrayList<>();
  try (ResultCursor<XQItemAccessor> cursor = query(query, params, props)) {
    for (XQItemAccessor item: cursor) {
      result.add(item.getAtomicValue());
    }
  }
  return result;
}

代码示例来源:origin: dsukhoroslov/bagri

if (command.equals(cmd_store_document)) {
  XQItemAccessor item = getBoundItem(params, "uri");
  String uri = item.getAtomicValue();
  item = getBoundItem(params, "doc");
  String xml = item.getItemAsString(null);
} else if (command.equals(cmd_remove_document)) {
  XQItemAccessor item = getBoundItem(params, "uri");
  String uri = item.getAtomicValue();
  dMgr.removeDocument(uri, null);
  return Collections.emptyIterator();

代码示例来源:origin: dsukhoroslov/bagri

public void run() {
    QueryManagement queryMgr = getQueryManager();
    try (ResultCursor<XQItemAccessor> cursor = queryMgr.executeQuery(params.query, params.params, params.props)) {
      int idx = 0;
      for (XQItemAccessor item: cursor) {
        if (idx > 0) {
          output.write(splitter);
        }
        String chunk = item.getItemAsString(null);
        logger.trace("postQuery; idx: {}; chunk: {}", idx, chunk);
        output.write(chunk);
        idx++;
      }
    } catch (Exception ex) {
      // XDMException, IOException. handle it somehow ?
      logger.error("postQuery.error", ex);
      throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR);
    } finally {
      try {
        output.close();
      } catch (IOException ex) {
        //
      }
    }
  }
}.start();

代码示例来源:origin: dsukhoroslov/bagri

protected void checkCursorResult(ResultCursor<XQItemAccessor> results, String expected) throws Exception {
  try {
    Iterator<XQItemAccessor> iter = results.iterator();
    assertTrue(iter.hasNext());
    if (expected == null) {
      assertNotNull(iter.next().getObject());
    } else {
      Properties props = new Properties();
      props.setProperty("method", "text");
      XQItem item = (XQItem) iter.next();
      assertEquals(expected, item.getItemAsString(props));
    }
    assertFalse(iter.hasNext());
  } finally {
    results.close();
  }
}

代码示例来源:origin: dsukhoroslov/bagri

@Override
public XQSequenceType getStaticVariableType(QName name) throws XQException {
  checkState(ex_expression_closed);
  if (name == null) {
    throw new XQException("name is null");
  }
  if (getVarNames().contains(name)) {
    // where can I get var type??
    XQItemType type;
    XQItemAccessor acc = (XQItemAccessor) getBindings().get(name);
    if (acc != null) {
      type = acc.getItemType();
    } else {
      type = connection.createItemType();
    }
    return new BagriXQSequenceType(type, OCC_ZERO_OR_MORE);
  }
  throw new XQException("Static variable [" + name + "] does not exist");
}

代码示例来源:origin: dsukhoroslov/bagri

private Collection<String> toCollection(ResultCursor<XQItemAccessor> cursor) throws BagriException {
  if (cursor == null) {
    return null;
  }
  
  try {
    List<String> result = new ArrayList<>();
    for (XQItemAccessor item: cursor) {
      result.add(item.getAtomicValue());
    }
    return result;
  } catch (XQException ex) {
    throw new BagriException(ex, BagriException.ecQuery);
  }
}

代码示例来源:origin: dsukhoroslov/bagri

DocumentKey fraKey = factory.newDocumentKey(uri, revision, version);
try {
  String fragment = item.getAtomicValue();
  String fUri = baseUri + ".r" + revision + ".v" + version + ext;
  Document doc = loadDocument(fraKey, fUri, fragment, srcFormat, createdAt, createdBy, txStart, collections, props);

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