Esempio n. 1
0
  public static void main(String[] args) {

    try {
      // DAO
      DAO dao = new DAO("172.31.101.225", "8080", "admin", "dionis");

      // Creamos una coleccion de nombre SergiPruebaDao
      dao.crearColeccio("SergiPruebaDao");

      // Le anyadimos un recurso
      dao.afegirRecurs("factbook.xml", "SergiPruebaDao");

      // Hacemos una consulta Xpath sobre ese recurso (Todos los paises del XML, en este caso);
      System.out.println("\nConsulta XPath \n------------------------");
      System.out.println(dao.consulta("collection('SergiPruebaDao')/factbook/record/country"));

      // Hacemos una consulta XQuery ese recurso
      System.out.println("\nConsulta Xquery \n------------------------");
      System.out.println(
          dao.consulta(
              "for $city in doc('SergiPruebaDao/factbook.xml')/factbook/record/country return $city"));

      // Elimina un recurso
      dao.eliminarRecurs("SergiPruebaDao", "factbook.xml");

      // Elimina la colección
      dao.eliminarColeccio("SergiPruebaDao");

    } catch (XMLDBException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (XQException e) {
      e.printStackTrace();
    }
  }
Esempio n. 2
0
  public void testGetObject_AllTypes() throws XQException {
    XQExpression xqe;
    XQSequence xqs;

    xqe = xqc.createExpression();
    xqs =
        xqe.executeQuery(
            "xs:anyURI('http://www.foo.org'),"
                + "xs:base64Binary('AAAA'),"
                + "xs:boolean('true'),"
                + "xs:byte('1'),"
                + "xs:date('2000-12-31'),"
                + "xs:dateTime('2000-12-31T12:00:00'),"
                + "xs:decimal('1'),"
                + "xs:double('1'),"
                +
                //                           "xs:duration()" +
                "xs:ENTITY('AAA'),"
                + "xs:float('1'),"
                + "xs:gDay('---11'),"
                + "xs:gMonth('--11'),"
                + "xs:gMonthDay('--01-01'),"
                + "xs:gYear('2000'),"
                + "xs:gYearMonth('2000-01'),"
                + "xs:hexBinary('AA'),"
                + "xs:ID('AA'),"
                + "xs:IDREF('AA'),"
                + "xs:int('1'),"
                + "xs:integer('1'),"
                + "xs:language('en-US'),"
                + "xs:long('1'),"
                + "xs:Name('AAA'),"
                + "xs:NCName('AAA'),"
                + "xs:negativeInteger('-1'),"
                + "xs:NMTOKEN('AAA'),"
                + "xs:nonNegativeInteger('1'),"
                + "xs:nonPositiveInteger('-1'),"
                + "xs:normalizedString('AAA'),"
                +
                //                           "xs:NOTATION()," +
                "xs:positiveInteger('1'),"
                + "xs:QName('AAA'),"
                + "xs:short('1'),"
                + "xs:string('AAA'),"
                + "xs:time('12:12:12'),"
                + "xs:token('AAA'),"
                + "xs:unsignedByte('1'),"
                + "xs:unsignedInt('1'),"
                + "xs:unsignedLong('1'),"
                + "xs:unsignedShort('1'),"
                + "xs:dayTimeDuration('PT5H'),"
                + "xs:untypedAtomic('AAA'),"
                + "xs:yearMonthDuration('P1M'),"
                + "<e a=\"{''}\"/>/@a,"
                + "<!-- comment -->, "
                + "document{<e/>},"
                + "<e/>, "
                + "processing-instruction {'a'} {'b'},"
                + "<e>text</e>/text()");
    Class xmlGregorianCalendar = null;
    Class duration = null;
    try {
      xmlGregorianCalendar = Class.forName("javax.xml.datatype.XMLGregorianCalendar");
      duration = Class.forName("javax.xml.datatype.Duration");
    } catch (final Exception e) {
      // assume JDK 1.4
    }
    try {
      final String msg =
          "A-XQIA-4.1: getObject implements casting rules of '14.4 Mapping an XQuery Atomic Value to a Java Object Type' ";
      xqs.next();
      assertTrue(msg + "for xs:anyURI", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:base64Binary", xqs.getObject() instanceof byte[]);
      xqs.next();
      assertTrue(msg + "for xs:boolean", xqs.getObject() instanceof Boolean);
      xqs.next();
      assertTrue(msg + "for xs:byte", xqs.getObject() instanceof Byte);
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:date", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:dateTime", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      assertTrue(msg + "for xs:decimal", xqs.getObject() instanceof BigDecimal);
      xqs.next();
      assertTrue(msg + "for xs:double", xqs.getObject() instanceof Double);
      xqs.next();
      assertTrue(msg + "for xs:ENTITY", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:float", xqs.getObject() instanceof Float);
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:gDay", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:gMonth", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:MonthDay", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:Year", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:YearMonth", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      assertTrue(msg + "for xs:hexBinary", xqs.getObject() instanceof byte[]);
      xqs.next();
      assertTrue(msg + "for xs:ID", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:IDREF", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:int", xqs.getObject() instanceof Integer);
      xqs.next();
      assertTrue(msg + "for xs:integer", xqs.getObject() instanceof BigInteger);
      xqs.next();
      assertTrue(msg + "for xs:language", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:long", xqs.getObject() instanceof Long);
      xqs.next();
      assertTrue(msg + "for xs:Name", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:NCName", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:negativeInteger", xqs.getObject() instanceof BigInteger);
      xqs.next();
      assertTrue(msg + "for xs:NMTOKEN", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:nonNegativeInteger", xqs.getObject() instanceof BigInteger);
      xqs.next();
      assertTrue(msg + "for xs:nonPostiveInteger", xqs.getObject() instanceof BigInteger);
      xqs.next();
      assertTrue(msg + "for xs:normalizedString", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:postiveInteger", xqs.getObject() instanceof BigInteger);
      xqs.next();
      assertTrue(msg + "for xs:QName", xqs.getObject() instanceof QName);
      xqs.next();
      assertTrue(msg + "for xs:short", xqs.getObject() instanceof Short);
      xqs.next();
      assertTrue(msg + "for xs:string", xqs.getObject() instanceof String);
      xqs.next();
      if (xmlGregorianCalendar != null)
        assertTrue(msg + "for xs:time", xmlGregorianCalendar.isInstance(xqs.getObject()));
      xqs.next();
      assertTrue(msg + "for xs:token", xqs.getObject() instanceof String);
      xqs.next();
      assertTrue(msg + "for xs:unsignedByte", xqs.getObject() instanceof Short);
      xqs.next();
      assertTrue(msg + "for xs:unsignedInt", xqs.getObject() instanceof Long);
      xqs.next();
      assertTrue(msg + "for xs:unsignedLong", xqs.getObject() instanceof BigInteger);
      xqs.next();
      assertTrue(msg + "for xs:unsignedShort", xqs.getObject() instanceof Integer);
      xqs.next();
      if (duration != null)
        assertTrue(msg + "for xs:dayTimeDuration", duration.isInstance(xqs.getObject()));
      xqs.next();
      assertTrue(msg + "for xs:untypedAtomic", xqs.getObject() instanceof String);
      xqs.next();
      if (duration != null)
        assertTrue(msg + "for xs:yearMonthDuration", duration.isInstance(xqs.getObject()));
      xqs.next();
      assertTrue(msg + "for attribute", xqs.getObject() instanceof org.w3c.dom.Attr);
      xqs.next();
      assertTrue(msg + "for comment", xqs.getObject() instanceof org.w3c.dom.Comment);
      xqs.next();
      assertTrue(msg + "for document", xqs.getObject() instanceof org.w3c.dom.Document);
      xqs.next();
      assertTrue(msg + "for element", xqs.getObject() instanceof org.w3c.dom.Element);
      xqs.next();
      assertTrue(
          msg + "for processing instruction",
          xqs.getObject() instanceof org.w3c.dom.ProcessingInstruction);
      xqs.next();
      assertTrue(msg + "for text", xqs.getObject() instanceof org.w3c.dom.Text);
    } catch (final XQException e) {
      e.printStackTrace();
      fail("A-XQIA-4.1: getObject on element() failed with message: " + e.getMessage());
    }
  }