Examples of XMLGregorianCalendar


Examples of javax.xml.datatype.XMLGregorianCalendar

  }

  @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());
    assertEquals(MONTH + 1, xmlCalendar.getMonth());
    assertEquals(DAY, xmlCalendar.getDay());
  }
View Full Code Here

Examples of javax.xml.datatype.XMLGregorianCalendar

                dt2 = (DateTimeValue) v2;
            } else {
                d1 = (DurationValue) v2;
                dt2 = (DateTimeValue) v1;
            }
            XMLGregorianCalendar cal2 = dt2.getValue();
            cal2.add(d1.getValue());
            return new DateTimeValue(cal2, dt2.getDateTimeType());
        }
View Full Code Here

Examples of javax.xml.datatype.XMLGregorianCalendar

        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

Examples of javax.xml.datatype.XMLGregorianCalendar

        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

Examples of javax.xml.datatype.XMLGregorianCalendar

    public DateTimeValue eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        if(previous.first == dynEnv) {
            return previous.second;
        } else {
            final XMLGregorianCalendar cal = XsDatatypeFactory.createXMLGregorianCalendar(dynEnv.currentDateTime());
            DateTimeBaseType casttoType = getReturnType();
            final DateTimeValue date = new DateTimeValue(cal, casttoType);
            previous.first = dynEnv;
            previous.second = date;
            return date;
View Full Code Here

Examples of javax.xml.datatype.XMLGregorianCalendar

                dt2 = (DateTimeValue) v2;
            } else {
                d1 = (DurationValue) v2;
                dt2 = (DateTimeValue) v1;
            }
            XMLGregorianCalendar cal2 = dt2.getValue();
            cal2.add(d1.getValue().negate());
            return new DateTimeValue(cal2, dt2.getDateTimeType());
        }
View Full Code Here

Examples of javax.xml.datatype.XMLGregorianCalendar

            throws XQueryException {
        Item arg1 = argv.getItem(0);
        Item arg2 = argv.getItem(1);
        DateTimeValue date = (DateTimeValue) arg1;
        DateTimeValue time = (DateTimeValue) arg2;
        XMLGregorianCalendar dateValue = date.getValue();
        XMLGregorianCalendar newValue = (XMLGregorianCalendar) dateValue.clone();
        XMLGregorianCalendar timeValue = time.getValue();
        final int timeTz = timeValue.getTimezone();
        if(timeTz != DatatypeConstants.FIELD_UNDEFINED) {
            final int dateTz = newValue.getTimezone();
            if(dateTz != DatatypeConstants.FIELD_UNDEFINED && dateTz != timeTz) {
                throw new DynamicError("err:FORG0008", "fn:dateTime(" + date + ", " + time
                        + ") for `" + dateValue.getTimeZone(dateTz).getID() + " and `"
                        + timeValue.getTimeZone(timeTz).getID() + "` is not allowed.");
            }
            newValue.setTimezone(timeTz);
        }
        newValue.setTime(timeValue.getHour(), timeValue.getMinute(), timeValue.getSecond(), timeValue.getMillisecond());
        DateTimeValue dt = new DateTimeValue(newValue, DateTimeType.DATETIME);
        return dt;
    }
View Full Code Here

Examples of javax.xml.datatype.XMLGregorianCalendar

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        final int arglen = argv.size();
        Item first = argv.getItem(0);
        DateTimeValue arg = (DateTimeValue) first;
        XMLGregorianCalendar cal = arg.getValue();
        final long utcOffsetInMillis;
        if(arglen == 1) {
            TimeZone tz = dynEnv.implicitTimezone();
            utcOffsetInMillis = tz.getRawOffset();
        } else if(arglen == 2) {
            Item sec = argv.getItem(1);
            if(sec.isEmpty()) {
                cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
                return arg;
            } else {
                Type secType = sec.getType();
                if(!TypeUtil.subtypeOf(secType, DayTimeDurationType.DAYTIME_DURATION)) {
                    throw new IllegalStateException("second argument is expected to be xdt:dayTimeDuration, but was "
                            + secType);
                }
                DurationValue dv = (DurationValue) sec;
                utcOffsetInMillis = dv.getTimeInMillis();
            }
        } else {
            throw new IllegalStateException("Illegal argument length: " + arglen);
        }
        final int offsetInMinutes = (int) (utcOffsetInMillis / 60000);
        final int origTimeZoneInMinutes = cal.getTimezone();
        if(origTimeZoneInMinutes == DatatypeConstants.FIELD_UNDEFINED) {
            cal.setTimezone(offsetInMinutes);
        } else if(offsetInMinutes != origTimeZoneInMinutes) {
            int origMillis = cal.getMillisecond();
            int diffInMinutes = offsetInMinutes - origTimeZoneInMinutes;
            long diffInMills = diffInMinutes * 60000;
            cal.add(XsDatatypeFactory.createDuration(diffInMills));
            cal.setMillisecond(origMillis); // workaround           
            cal.setTimezone(offsetInMinutes);
            cal.normalize();
        }
        return arg;
    }
View Full Code Here

Examples of javax.xml.datatype.XMLGregorianCalendar

    public int compareTo(Item trg) {
        if(!(trg instanceof DateTimeValue)) {
            throw new XQRTException("err:XPTY0004", "Imcomparable "
                    + trg.getClass().getSimpleName() + " with DateTimeValue");
        }
        XMLGregorianCalendar trgUri = ((DateTimeValue) trg).value;
        return value.compare(trgUri);
    }
View Full Code Here

Examples of javax.xml.datatype.XMLGregorianCalendar

       
        readerControl.replay();
       
        XMLGregorianCalendarType xType = (XMLGregorianCalendarType) tm.getType(XMLGregorianCalendar.class);
        assertNotNull(xType);
        XMLGregorianCalendar cal = (XMLGregorianCalendar) xType.readObject(reader, new MessageContext());
        assertEquals(28, cal.getDay());
       
        readerControl.verify();
       
        // test writing
        MockControl writerControl = MockControl.createControl(MessageWriter.class);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.