Package javax.xml.datatype

Examples of javax.xml.datatype.XMLGregorianCalendar


            return NodeValue.makeNodeDuration(d3, n) ;
        }
       
        if ( isDT(vs1) && isDT(vs2) )
        {
            XMLGregorianCalendar cal1 = nv1.getDateTime() ;
            XMLGregorianCalendar cal2 = nv2.getDateTime() ;
            boolean isDef1 = ( cal1.getTimezone() == FIELD_UNDEFINED ) ;
            boolean isDef2 = ( cal2.getTimezone() == FIELD_UNDEFINED ) ;
            if ( ( isDef1 && !isDef2 ) || ( !isDef1 && isDef2 ) )
                throw new ExprEvalTypeException("Operator '-': can't substract timezone/non-timezone values") ;
            // Inspect duration and force to better type? xsd:dayTimeDuration
            return NodeValue.makeDuration(xsd_substract(cal1, cal2));
        }
       
        // Loose style. Subtract any duration to any date or time value.
        if ( vs1.equals(VSPACE_DATETIME) && vs2.equals(VSPACE_DURATION) )
        {
            XMLGregorianCalendar cal = nv1.getDateTime() ;
            // add-negation
            XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
            NodeValue r = NodeValue.makeDateTime(result) ;
            return r ;
        }
        if ( vs1.equals(VSPACE_DATE) && vs2.equals(VSPACE_DURATION) )
        {
            XMLGregorianCalendar cal = nv1.getDateTime() ;
            // add-negation
            XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
            NodeValue r = NodeValue.makeDate(result) ;
            return r ;
        }
        if ( vs1.equals(VSPACE_TIME) && vs2.equals(VSPACE_DURATION) )
        {
            XMLGregorianCalendar cal = nv1.getDateTime() ;
            // add-negation
            XMLGregorianCalendar result = xsd_subtract(cal, nv2.getDuration()) ;
            NodeValue r = NodeValue.makeNode(result.toXMLFormat(), XSDDatatype.XSDtime) ;
            return r ;
        }
       
        throw new ExprEvalTypeException("Operator '-' : Undefined subtraction: "+nv1+" and "+nv2) ;
    }
View Full Code Here


   
    private static XMLGregorianCalendar xsd_add(XMLGregorianCalendar cal, Duration duration)
    {
        //if ( ! isYearMonth(duration) && ! isDayTime(duration) )

        XMLGregorianCalendar result = (XMLGregorianCalendar)cal.clone() ;
        result.add(duration) ;
        return result ;
    }
View Full Code Here

   
    public static final String defaultTimezone = "Z" ;
   
    private static int compareDateTimeFO(NodeValue nv1, NodeValue nv2)
    {
        XMLGregorianCalendar dt1 = nv1.getDateTime() ;
        XMLGregorianCalendar dt2 = nv2.getDateTime() ;
       
        int x = compareXSDDateTime(dt1, dt2) ;
       
        if ( x == XSDDateTime.INDETERMINATE )
        {
            NodeValue nv3 = fixupDateTime(nv1) ;
            if ( nv3 != null )
            {
                XMLGregorianCalendar dt3 = nv3.getDateTime() ;
                x =  compareXSDDateTime(dt3, dt2) ;
                if ( x == XSDDateTime.INDETERMINATE )
                    throw new ARQInternalErrorException("Still get indeterminate comparison") ;
                return x ;
            }
           
            nv3 = fixupDateTime(nv2) ;
            if ( nv3 != null )
            {
                XMLGregorianCalendar dt3 = nv3.getDateTime() ;
                x =  compareXSDDateTime(dt1, dt3) ;
                if ( x == XSDDateTime.INDETERMINATE )
                    throw new ARQInternalErrorException("Still get indeterminate comparison") ;
                return x ;
            }
View Full Code Here

    {
        // http://www.w3.org/TR/xpath-functions/#casting-to-datetimes
        if ( ! nv.hasDateTime() )
            throw new ExprEvalTypeException("Not a date/time type: "+nv) ;
       
        XMLGregorianCalendar xsdDT = nv.getDateTime() ;
       
        if ( XSDDatatype.XSDdateTime.equals(xsd) )
        {
            // ==> DateTime
            if ( nv.isDateTime() ) return nv ;
            if ( ! nv.isDate() ) throw new ExprEvalTypeException("Can't cast to XSD:dateTime: "+nv) ;
            // DateTime with time 00:00:00
            String x = String.format("%04d-%02d-%02dT00:00:00", xsdDT.getYear(), xsdDT.getMonth(),xsdDT.getDay()) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        if ( XSDDatatype.XSDdate.equals(xsd) )
        {
            // ==> Date
            if ( nv.isDate() ) return nv ;
            if ( ! nv.isDateTime() ) throw new ExprEvalTypeException("Can't cast to XSD:date: "+nv) ;
            String x = String.format("%04d-%02d-%02d", xsdDT.getYear(), xsdDT.getMonth(),xsdDT.getDay()) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        if ( XSDDatatype.XSDtime.equals(xsd) )
        {
            // ==> time
            if ( nv.isTime() ) return nv ;
            if ( ! nv.isDateTime() ) throw new ExprEvalTypeException("Can't cast to XSD:time: "+nv) ;
            // Careful foratting
            DecimalFormat nf = new DecimalFormat("00.####") ;
            nf.setDecimalSeparatorAlwaysShown(false) ;
            String x = nf.format(xsdDT.getSecond()) ;
            x = String.format("%02d:%02d:%s", xsdDT.getHour(), xsdDT.getMinute(),x) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        if ( XSDDatatype.XSDgYear.equals(xsd) )
        {
            // ==> Year
            if ( nv.isGYear() ) return nv ;
            if ( ! nv.isDateTime() && ! nv.isDate() ) throw new ExprEvalTypeException("Can't cast to XSD:gYear: "+nv) ;
            String x = String.format("%04d", xsdDT.getYear()) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        if ( XSDDatatype.XSDgYearMonth.equals(xsd) )
        {
            // ==> YearMonth
            if ( nv.isGYearMonth() ) return nv ;
            if ( ! nv.isDateTime() && ! nv.isDate() ) throw new ExprEvalTypeException("Can't cast to XSD:gYearMonth: "+nv) ;
            String x = String.format("%04d-%02d", xsdDT.getYear(), xsdDT.getMonth()) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        if ( XSDDatatype.XSDgMonth.equals(xsd) )
        {
            // ==> Month
            if ( nv.isGMonth() ) return nv ;
            if ( ! nv.isDateTime() && ! nv.isDate() ) throw new ExprEvalTypeException("Can't cast to XSD:gMonth: "+nv) ;
            String x = String.format("--%02d", xsdDT.getMonth()) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        if ( XSDDatatype.XSDgMonthDay.equals(xsd) )
        {
            // ==> MonthDay
            if ( nv.isGMonthDay() ) return nv ;
            if ( ! nv.isDateTime() && ! nv.isDate() ) throw new ExprEvalTypeException("Can't cast to XSD:gMonthDay: "+nv) ;
            String x = String.format("--%02d-%02d", xsdDT.getMonth(), xsdDT.getDay()) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        if ( XSDDatatype.XSDgDay.equals(xsd) )
        {
            // Day
            if ( nv.isGDay() ) return nv ;
            if ( ! nv.isDateTime() && ! nv.isDate() ) throw new ExprEvalTypeException("Can't cast to XSD:gDay: "+nv) ;
            String x = String.format("---%02d", xsdDT.getDay()) ;
            return NodeValue.makeNode(x, xsd) ;
        }
   
        throw new ExprEvalTypeException("Can't case to <"+xsd.getURI()+">: "+nv) ;
    }
View Full Code Here

    }

    public static boolean hasAssertionExpired(AssertionType assertion) {
        ConditionsType conditionsType = assertion.getConditions();
        if (conditionsType != null) {
            XMLGregorianCalendar now = getXMLGregorianCalendarNow();
            XMLGregorianCalendar notBefore = conditionsType.getNotBefore();
            XMLGregorianCalendar notOnOrAfter = conditionsType.getNotOnOrAfter();

            if (notBefore != null) {
                int val = notBefore.compare(now);
                if (val == DatatypeConstants.INDETERMINATE || val == DatatypeConstants.GREATER) {
                    return true;
                }
            }

            if (notOnOrAfter != null) {
                int val = notOnOrAfter.compare(now);
                if (val != DatatypeConstants.GREATER) {
                    return true;
                }
            }
View Full Code Here

   
    BlockingQueue<Packet> getQueue() { return this.packets; }
  }
 
  protected OadrDistributeEvent createEventPayload() {
    final XMLGregorianCalendar startDttm = xmlDataTypeFac.newXMLGregorianCalendar("2012-01-01T00:00:00Z");
    final ObjectFactory oadrTypes = new ObjectFactory();
   
    return new OadrDistributeEvent()
      .withRequestID("test-123")
      .withVtnID("vtn-123")
View Full Code Here

    BlockingQueue<Packet> getQueue() { return this.packets; }
  }
 
  @SuppressWarnings("unchecked")
    protected OadrSignedObject createEventPayload() {
    final XMLGregorianCalendar startDttm = xmlDataTypeFac.newXMLGregorianCalendar("2012-01-01T00:00:00Z");
    final ObjectFactory eiObjectFactory = new ObjectFactory();
   
    return new OadrSignedObject()
        .withOadrDistributeEvent( new OadrDistributeEvent()
            .withRequestID( "test 1234" )
View Full Code Here

  @Test
  public void testIsSameDate() throws Exception {
    DateTime cal = new DateTime();

    XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance()
        .newXMLGregorianCalendarDate(1, 1, 1, 1);
    assertFalse(isSameDate(cal, xmlCal));

    cal = new DateTime(1, 1, 1, 0, 0, 0, 0);
    assertTrue(isSameDate(cal, xmlCal));
View Full Code Here

    assertFalse(isSameMonthInYear(dateTime, dateTime.toLocalDate().plusYears(1)));
  }

  @Test
  public void testToLocalDate() {
    XMLGregorianCalendar cal = toXmlDate(new DateTime());
    LocalDate date = toLocalDate(cal);
    assertEquals(cal.getYear(), date.getYear());
    assertEquals(cal.getMonth(), date.getMonthOfYear());
    assertEquals(cal.getDay(), date.getDayOfMonth());
  }
View Full Code Here

  @Test
  public void testToXmlDate_fromDateTime() {

    DateTime cal = new DateTime();
    XMLGregorianCalendar xmlCal = toXmlDate(cal);

    assertEquals(cal.getYear(), xmlCal.getYear());
    // Calendar.MONTH is zero based, xmlCal is one based.
    assertEquals(cal.getMonthOfYear(), xmlCal.getMonth());
    assertEquals(cal.getDayOfMonth(), xmlCal.getDay());
  }
View Full Code Here

TOP

Related Classes of javax.xml.datatype.XMLGregorianCalendar

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.