コード例 #1
0
  /**
   * Return opaque object embedded in XQuery Item
   *
   * @param item item
   * @return type
   * @throws XQException XQException
   */
  private Object getItemValue(XQItem item) throws XQException {
    XQItemType itemType = item.getItemType();
    Object itemValue = null;

    switch (itemType.getBaseType()) {
      case XQItemType.XQBASETYPE_BOOLEAN:
        itemValue = item.getBoolean();

        break;

      case XQItemType.XQBASETYPE_DECIMAL:
        itemValue = item.getDouble();

        break;

      case XQItemType.XQBASETYPE_BYTE:
        itemValue = item.getByte();

        break;

      case XQItemType.XQBASETYPE_FLOAT:
        itemValue = item.getFloat();

        break;

      case XQItemType.XQBASETYPE_INT:
      case XQItemType.XQBASETYPE_INTEGER:
        itemValue = item.getInt();

        break;

      case XQItemType.XQBASETYPE_LONG:
        itemValue = item.getLong();

        break;

      case XQItemType.XQBASETYPE_ANYTYPE:
        itemValue = item.getNode();

        break;

      case XQItemType.XQBASETYPE_ANYURI:
        itemValue = item.getNodeUri();

        break;

      case XQItemType.XQBASETYPE_SHORT:
        itemValue = item.getShort();

        break;

      case XQItemType.XQBASETYPE_STRING:
      case XQItemType.XQBASETYPE_ANYATOMICTYPE:
        itemValue = item.getAtomicValue();

        break;
    }

    return itemValue;
  }
コード例 #2
0
  public void testGetItemType() throws XQException {
    XQExpression xqe;
    XQSequence xqs;
    XQItemType xqtype;

    xqe = xqc.createExpression();
    xqs = xqe.executeQuery("'1'");
    try {
      xqs.getItemType();
      fail("A-XQIA-6.1: getItemType() should fail when not positioned on an item");
    } catch (final XQException e) {
      // Expect an XQException
    }
    xqe.close();

    xqe = xqc.createExpression();
    xqs = xqe.executeQuery("'1'");
    xqs.next();
    xqs.close();
    try {
      xqs.getItemType();
      fail("A-XQIA-6.2: closed item accessor supports getItemType()");
    } catch (final XQException e) {
      // Expect an XQException
    }
    xqe.close();

    xqe = xqc.createExpression();
    xqs = xqe.executeQuery("'Hello world!'");
    xqs.next();
    try {
      xqtype = xqs.getItemType();
      assertNotNull("A-XQIA-6.3: getItemType() failed", xqtype);
      assertEquals(
          "A-XQIA-6.3: getItemType() failed", XQItemType.XQITEMKIND_ATOMIC, xqtype.getItemKind());
      assertEquals(
          "A-XQIA-6.3: getItemType() failed", XQItemType.XQBASETYPE_STRING, xqtype.getBaseType());
    } catch (final XQException e) {
      fail("A-XQIA-6.3: getItemType() failed with message: " + e.getMessage());
    }
    xqe.close();

    xqe = xqc.createExpression();
    xqs = xqe.executeQuery("1");
    xqs.next();
    xqs.getItem();
    try {
      xqs.getItemType();
    } catch (final XQException e) {
      fail("A-XQIA-6.4: getItemType() failed with message: " + e.getMessage());
    }
    xqe.close();
  }