Package javax.xml.datatype

Examples of javax.xml.datatype.DatatypeFactory


  @Test
  public void testGregorianCalendar() throws Exception{

    DateObjectSource source = new DateObjectSource();
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar();
    xmlGregorianCalendar.setTimezone(2 * 60);
    source.setRecalledDate(xmlGregorianCalendar);

    DateObjectDest dest = mapper.map(source, DateObjectDest.class);

View Full Code Here


    assertEquals(DAY, xmlCalendar.getDay());
  }

  @Test
  public void testConvert_XmlGregorianCalendar() throws Exception {
    DatatypeFactory instance = DatatypeFactory.newInstance();
    XMLGregorianCalendar calendar = instance.newXMLGregorianCalendar(new GregorianCalendar(YEAR, MONTH, DAY));

    Object result = converter.convert(XMLGregorianCalendar.class, calendar);
    XMLGregorianCalendar xmlCalendar = (XMLGregorianCalendar) result;

    assertEquals(YEAR, xmlCalendar.getYear());
View Full Code Here

            throws XQueryException {
        return new DateTimeValue(literal, this);
    }

    public DateTimeValue createInstance(XMLGregorianCalendar value) {
        final DatatypeFactory factory = XsDatatypeFactory.getDatatypeFactory();
        int hour = value.getHour();
        int minute = value.getMinute();
        int sec = value.getSecond();
        BigDecimal fsec = value.getFractionalSecond();
        int tz = value.getTimezone();
        XMLGregorianCalendar cal = factory.newXMLGregorianCalendarTime(hour, minute, sec, fsec, tz);
        return new GregorianDateTimeValue(cal, TIME);
    }
View Full Code Here

            throws XQueryException {
        return new DateTimeValue(literal, this);
    }

    public DateTimeValue createInstance(XMLGregorianCalendar value) {
        final DatatypeFactory factory = XsDatatypeFactory.getDatatypeFactory();
        int year = value.getYear();
        int month = value.getMonth();
        int day = value.getDay();
        int tz = value.getTimezone();
        XMLGregorianCalendar cal = factory.newXMLGregorianCalendarDate(year, month, day, tz);
        return new GregorianDateTimeValue(cal, DATE);
    }
View Full Code Here

    public void testSetExpires() throws DatatypeConfigurationException {
        SourceSequence seq = new SourceSequence(id);
       
        Expires expires = factory.createExpires();
       
        DatatypeFactory dbf = DatatypeFactory.newInstance();
        Duration d = dbf.newDuration(0);       
        expires.setValue(d);
        seq.setExpires(expires);
        assertTrue(!seq.isExpired());
       
        d = dbf.newDuration("PT0S");       
        expires.setValue(d);
        seq.setExpires(expires);
        assertTrue(!seq.isExpired());
       
        d = dbf.newDuration(1000);       
        expires.setValue(d);
        seq.setExpires(expires);
        assertTrue(!seq.isExpired());
       
        d = dbf.newDuration("-PT1S");       
        expires.setValue(d);
        seq.setExpires(expires);
        assertTrue(seq.isExpired());  
    }
View Full Code Here

    }

    catch (Exception e) {
      // see if its a xsd:duration
      try {
        DatatypeFactory factory = DatatypeFactory.newInstance();
        Duration d = factory.newDuration(text);
        long secs = d.getTimeInMillis(new Date()) / 1000;
        timeUnit = new TimeUnit(secs + " secs");
      } catch (Exception e1) {
        throw new java.text.ParseException(e.getMessage(), 0);
      }
View Full Code Here

    text = (text == null) ? "" : text.trim();
    td.text = text;

    try {
      DatatypeFactory factory = DatatypeFactory.newInstance();
      Duration d = factory.newDuration(text);
      long secs = d.getTimeInMillis(new Date()) / 1000;
      td.timeUnit = new TimeUnit(secs + " secs");
    } catch (Exception e) {
      throw new java.text.ParseException(e.getMessage(), 0);
    }
View Full Code Here

  @Override
  protected void setUp()
    throws Exception
  {
    DatatypeFactory factory = DatatypeFactory.newInstance();
    XMLGregorianCalendar mar = factory.newXMLGregorianCalendar("2000-03-04T20:00:00Z");
    XMLGregorianCalendar oct = factory.newXMLGregorianCalendar("2002-10-10T12:00:00-05:00");
    date1 = vf.createLiteral(mar);
    date2 = vf.createLiteral(oct);
  }
View Full Code Here

    throws Exception
  {
    String NS = "http://example.org/rdf/";
    int OFFSET = TimeZone.getDefault().getOffset(new Date(2007, Calendar.NOVEMBER, 6).getTime()) / 1000 / 60;
    String SELECT_BY_DATE = "SELECT ?s ?d WHERE { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> ?d . FILTER (?d <= ?date) }";
    DatatypeFactory data = DatatypeFactory.newInstance();
    for (int i = 1; i < 5; i++) {
      URI uri = vf.createURI(NS, "date" + i);
      XMLGregorianCalendar xcal = data.newXMLGregorianCalendar();
      xcal.setYear(2000);
      xcal.setMonth(11);
      xcal.setDay(i * 2);
      testCon.add(uri, RDF.VALUE, vf.createLiteral(xcal));
      URI uriz = vf.createURI(NS, "dateZ" + i);
      xcal = data.newXMLGregorianCalendar();
      xcal.setYear(2007);
      xcal.setMonth(11);
      xcal.setDay(i * 2);
      xcal.setTimezone(OFFSET);
      testCon.add(uriz, RDF.VALUE, vf.createLiteral(xcal));
    }
    XMLGregorianCalendar xcal = data.newXMLGregorianCalendar();
    xcal.setYear(2007);
    xcal.setMonth(11);
    xcal.setDay(6);
    xcal.setTimezone(OFFSET);
    TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, SELECT_BY_DATE);
View Full Code Here

     *
     * @throws IllegalArgumentException if {@code d} is infinite.
     */
    public static String getXMLDateStringFromDouble(double d) {
        try {
            DatatypeFactory dateFactory = DatatypeFactory.newInstance();
            if (d == Double.NEGATIVE_INFINITY) {
                return "-Infinity";
            } else if (d == Double.POSITIVE_INFINITY) {
                return "Infinity";
            }
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTimeInMillis((long) d);
            return dateFactory.newXMLGregorianCalendar(gc).toXMLFormat().substring(0, 23);
        } catch (DatatypeConfigurationException ex) {
            Exceptions.printStackTrace(ex);
            return "";
        }
    }
View Full Code Here

TOP

Related Classes of javax.xml.datatype.DatatypeFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.