コード例 #1
0
 /**
  * Return a calendar with the timezone field set, to be used for order comparison. If the original
  * calendar did not specify a timezone, set the local timezone (unadjusted for daylight savings).
  * The returned calendars will be totally ordered between themselves. We also set any missing
  * fields to ensure that normalization doesn't discard important data! (This is probably a bug in
  * the JAXP implementation, but the workaround doesn't hurt us, so it's faster to just fix it
  * here.)
  *
  * @return the calendar represented by this object, with the timezone field filled in with an
  *     implicit value if necessary
  */
 protected XMLGregorianCalendar getImplicitCalendar() {
   if (implicitCalendar == null) {
     implicitCalendar = (XMLGregorianCalendar) calendar.clone();
     if (calendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
       implicitCalendar.setTimezone(TimeUtils.getInstance().getLocalTimezoneOffsetMinutes());
     }
     // fill in fields from default reference; don't have to worry about weird combinations of
     // fields being set, since we control that on creation
     switch (getType()) {
       case Type.DATE:
         implicitCalendar.setTime(0, 0, 0);
         break;
       case Type.TIME:
         implicitCalendar.setYear(1972);
         implicitCalendar.setMonth(12);
         implicitCalendar.setDay(31);
         break;
       default:
     }
     implicitCalendar =
         implicitCalendar
             .normalize(); // the comparison routines will normalize it anyway, just do it once
                           // here
   }
   return implicitCalendar;
 }
コード例 #2
0
 private static XMLGregorianCalendar stripCalendar(XMLGregorianCalendar calendar) {
   calendar = (XMLGregorianCalendar) calendar.clone();
   calendar.setYear(DatatypeConstants.FIELD_UNDEFINED);
   calendar.setMonth(DatatypeConstants.FIELD_UNDEFINED);
   calendar.setHour(DatatypeConstants.FIELD_UNDEFINED);
   calendar.setMinute(DatatypeConstants.FIELD_UNDEFINED);
   calendar.setSecond(DatatypeConstants.FIELD_UNDEFINED);
   calendar.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
   return calendar;
 }
コード例 #3
0
  public Object toJavaObject(Class target) throws XPathException {
    if (target == Object.class || target.isAssignableFrom(DateValue.class)) return this;
    else if (target.isAssignableFrom(XMLGregorianCalendar.class)) return calendar.clone();
    else if (target.isAssignableFrom(GregorianCalendar.class))
      return calendar.toGregorianCalendar();
    else if (target == Date.class) return calendar.toGregorianCalendar().getTime();

    throw new XPathException(
        "cannot convert value of type "
            + Type.getTypeName(getType())
            + " to Java object of type "
            + target.getName());
  }
コード例 #4
0
ファイル: XMLTimeUtil.java プロジェクト: sbryzak/picketlink
  /**
   * Add additional time in miliseconds
   *
   * @param value calendar whose value needs to be updated
   * @param milis
   * @return calendar value with the addition
   * @throws ConfigurationException
   */
  public static XMLGregorianCalendar add(XMLGregorianCalendar value, long milis)
      throws ConfigurationException {
    XMLGregorianCalendar newVal = (XMLGregorianCalendar) value.clone();

    Duration duration;
    try {
      duration = newDatatypeFactory().newDuration(milis);
    } catch (DatatypeConfigurationException e) {
      throw logger.configurationError(e);
    }
    newVal.add(duration);
    return newVal;
  }
コード例 #5
0
 /**
  * Utility method that is able to clone a calendar whose year is 0 (whatever a year 0 means). It
  * looks like the JDK is unable to do that.
  *
  * @param calendar The Calendar to clone
  * @return the cloned Calendar
  */
 public static XMLGregorianCalendar cloneXMLGregorianCalendar(XMLGregorianCalendar calendar) {
   boolean hacked = false;
   if (calendar.getYear() == 0) {
     calendar.setYear(1);
     hacked = true;
   }
   XMLGregorianCalendar result = (XMLGregorianCalendar) calendar.clone();
   if (hacked) {
     // reset everything
     calendar.setYear(0);
     // -1 could also be considered
     result.setYear(0);
   }
   return result;
 }
コード例 #6
0
 public AbstractDateTimeValue adjustedToTimezone(DayTimeDurationValue offset)
     throws XPathException {
   if (offset == null)
     offset = new DayTimeDurationValue(TimeUtils.getInstance().getLocalTimezoneOffsetMillis());
   validateTimezone(offset);
   XMLGregorianCalendar xgc = (XMLGregorianCalendar) calendar.clone();
   if (xgc.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) {
     if (getType() == Type.DATE)
       xgc.setTime(0, 0, 0); // set the fields so we don't lose precision when shifting timezones
     xgc = xgc.normalize();
     xgc.add(offset.duration);
   }
   try {
     xgc.setTimezone((int) (offset.getValue() / 60));
   } catch (IllegalArgumentException e) {
     throw new XPathException("illegal timezone offset " + offset, e);
   }
   return createSameKind(xgc);
 }
コード例 #7
0
ファイル: PsiXmlCalendar.java プロジェクト: arnaudceol/psimi
 public Object clone() {
   return calendar.clone();
 }
コード例 #8
0
 public GDayValue(XMLGregorianCalendar calendar) throws XPathException {
   super(stripCalendar((XMLGregorianCalendar) calendar.clone()));
 }
コード例 #9
0
 public AbstractDateTimeValue withoutTimezone() throws XPathException {
   XMLGregorianCalendar xgc = (XMLGregorianCalendar) calendar.clone();
   xgc.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
   return createSameKind(xgc);
 }