Java 8 XMLGregorianCalendar - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 XMLGregorianCalendar class.

This code example shows how to use the following methods:getYear, setMonth, setYear
 
    public void testGregorianCalendar() throws ExceptionDatatypeFactory f = DatatypeFactory.newInstance();
        XMLGregorianCalendar in = f.newXMLGregorianCalendar();
        in.setYear(2014);
        in.setMonth(3);
         
        String json = MAPPER.writeValueAsString(in);
        assertNotNull(json);
        XMLGregorianCalendar out = MAPPER.readValue(json, XMLGregorianCalendar.class);
        assertNotNull(out);
         
        // minor sanity check 
        assertEquals(in.getYear(), out.getYear());
    } 
 
    public void testAuthPermission() throws ExceptionAuthPermission in = new AuthPermission("foo");
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDay, getHour, getMinute, getMonth, getSecond
This code example shows how to use the following methods:setDay, setHour, setMillisecond, setMinute, setMonth
This code example shows how to use the following methods:setFractionalSecond, toXMLFormat
    } 
 
    public static synchronized String fromDate(Date date) {
        calendar.setTime(date);
        XMLGregorianCalendar xgc = XML_DATE.newXMLGregorianCalendar(calendar);
        if (calendar.get(Calendar.MILLISECOND) == 0) xgc.setFractionalSecond(null);
        return xgc.toXMLFormat();
    } 
 
    private static boolean checkLayout(String text, String pattern) {
        if (text.length() != pattern.length()) return false;
        for (int i=0; i<pattern.length(); i++) {
            char pc = pattern.charAt(i);
            char tc = text.charAt(i);
            if(pc == 'x' && tc >= '0' && tc <= '9') continue;
            else if(pc == 'x' || pc != tc) return false;
        } 
        return true; 
    } 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:toGregorianCalendar
		factory.getConverterFactory().registerConverter(new DateToXmlGregorianCalendarConverter());
		MapperFacade mapper = factory.getMapperFacade();
		 
		Date now = new Date();
		XMLGregorianCalendar xml = mapper.map(now, XMLGregorianCalendar.class);
		Assert.assertEquals(now, xml.toGregorianCalendar().getTime());
		 
		Date reverse = mapper.map(xml, Date.class);
		Assert.assertEquals(now, reverse);
	} 
	 
	@Test 
    public void testTimeToXmlGregorianCalendarConverter() { 
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(new DateToXmlGregorianCalendarConverter());
        MapperFacade mapper = factory.getMapperFacade();
         
        Time now = new Time(System.currentTimeMillis());
        XMLGregorianCalendar xml = mapper.map(now, XMLGregorianCalendar.class);
        Assert.assertEquals(now.getTime(), xml.toGregorianCalendar().getTime().getTime());
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDay, setHour, setMillisecond, setMinute, setMonth
     */ 
    private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) throws DatatypeConfigurationException {
 
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar();
        xgc.setYear(calendar.get(Calendar.YEAR));
        xgc.setMonth(calendar.get(Calendar.MONTH) + 1);
        xgc.setDay(calendar.get(Calendar.DAY_OF_MONTH));
        xgc.setHour(calendar.get(Calendar.HOUR_OF_DAY));
        xgc.setMinute(calendar.get(Calendar.MINUTE));
        xgc.setSecond(calendar.get(Calendar.SECOND));
        xgc.setMillisecond(calendar.get(Calendar.MILLISECOND));
 
        // Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds. 
        int offsetInMinutes = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
        xgc.setTimezone(offsetInMinutes);
        return xgc;
    } 
 
    public List<PerfMetricId> queryAvailablePerfMetric(ManagedObjectReference morEntity, Calendar beginTime,
        Calendar endTime, Integer intervalId) throws Exception {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDay, getMonth, getYear
    public final static LocalDate toLocalDate(XMLGregorianCalendar date) {
 
        if (date == null) {
            return null; 
        } else { 
            return new LocalDate(date.getYear(), date.getMonth(),
                date.getDay());
        } 
 
    } 
 
    /** 
     * It converts a <code>Date</code> to a <code>XMLGregorianCalendar</code> 
     * representing a <code>xsd:date</code> XML type.<br/> 
     * <br/> 
     * 
     * If the date passed as a parameter is <code>null</code>, it also returns 
     * <code>null</code>. 
     * 
     * @throws DatatypeConfigurationException 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDay, getHour, getMinute, getMonth, getSecond
		if (rev.getTimestamp() != null)
		{ 
			XMLGregorianCalendar ts = rev.getTimestamp();
			 
			this.timestamp = new GregorianCalendar();
			this.timestamp.setTimeZone(ts.getTimeZone(0));
			this.timestamp.set(
					ts.getYear(),
					ts.getMonth(),
					ts.getDay(),
					ts.getHour(),
					ts.getMinute(),
					ts.getSecond());
		} 
		else 
		{ 
			this.timestamp = new GregorianCalendar();
			this.timestamp.setTimeZone(TimeZone.getTimeZone("UST"));
			this.timestamp.setTimeInMillis(0);
		} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:toGregorianCalendar
public class XMLGregorianCalendarToDateConverter extends CustomConverterBase<XMLGregorianCalendar, Date> {
     
    public Date convert(XMLGregorianCalendar source, Class<? extends Date> destinationClass) {
        Date target = null;
        if (source != null) {
            target = source.toGregorianCalendar().getTime();
        } 
        return target;
    } 
     
    public boolean canConvert(Class<XMLGregorianCalendar> sourceClass, Class<? extends Date> destinationClass) {
        return XMLGregorianCalendar.class.isAssignableFrom(sourceClass) && Date.class.equals(destinationClass);
    } 
     
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getXMLSchemaType, toXMLFormat
	} 
 
	public ATermAppl getLiteral(Object value) {
		if( value instanceof XMLGregorianCalendar ) {
			final XMLGregorianCalendar c = (XMLGregorianCalendar) value;
			if( !schemaType.equals( c.getXMLSchemaType() ) )
				throw new IllegalArgumentException();
			return ATermUtils.makeTypedLiteral( c.toXMLFormat(), getName() );
		} 
		else 
			throw new IllegalArgumentException();
	} 
 
	public Datatype<?> getPrimitiveDatatype() { 
		return this;
	} 
 
	public XMLGregorianCalendar getValue(ATermAppl literal) throws InvalidLiteralException {
		final String lexicalForm = getLexicalForm( literal );
		try { 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 XMLGregorianCalendar Questions & Answers:

See Code Examples for Java 8 XMLGregorianCalendar Methods: