List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:net.javacrumbs.airline.client.AirlineClient.java
private XMLGregorianCalendar time(String time) { try {//from w w w . ja va 2s . c o m return DatatypeFactory.newInstance().newXMLGregorianCalendar(time); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:py.una.pol.karaku.services.util.ServiceUtil.java
/** * // w ww. j ava 2 s . co m */ public ServiceUtil() { // Creamos un DataTypeFactory para las conversiones a // XMLGregorianCalendar try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException dce) { throw new IllegalStateException("Exception while obtaining DatatypeFactory instance", dce); } }
From source file:net.orpiske.dcd.dispatcher.impl.WebServicesConversor.java
private static XMLGregorianCalendar newXmlGregorianCalendar(final Date date) { GregorianCalendar reportDate = new GregorianCalendar(); reportDate.setTime(date);/*from w w w .j a v a 2s . c o m*/ XMLGregorianCalendar ret = null; try { ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(reportDate); } catch (DatatypeConfigurationException e) { logger.error("Unable to properly transform a date for XML data transfer: " + e.getMessage(), e); } return ret; }
From source file:com.himanshu.um.impl.user.db.dao.UserDaoTest.java
@Test public void createUser() throws UserCreationException, DatatypeConfigurationException, InterruptedException { ApplicationContext context = new ClassPathXmlApplicationContext("um-spring.xml"); IManager manager = context.getBean(DatabaseManagerImpl.class); com.himanshu.um.api.model.User user = new com.himanshu.um.api.model.User(); user.setUsername("himanshu"); user.setPassword("password"); user.setStatus(true);//from w w w. j a va2s.co m GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(new Date().getTime()); try { user.setCreatedDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal)); } catch (DatatypeConfigurationException e) { e.printStackTrace(); throw e; } Thread.sleep(3000); //3 seconds sleep to demonstrate last modified date lag cal.setTimeInMillis(new Date().getTime()); try { user.setLastModifiedDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal)); } catch (DatatypeConfigurationException e) { e.printStackTrace(); throw e; } manager.addNewUser(user); }
From source file:com.adaptris.core.services.metadata.timestamp.OffsetTimestampGenerator.java
@Override public Date generateTimestamp(AdaptrisMessage msg) throws ServiceException { Date timestamp = new Date(); try {//from w ww . ja v a 2 s . c o m if (!isBlank(offset)) { Duration duration; duration = DatatypeFactory.newInstance().newDuration(msg.resolve(offset)); duration.addTo(timestamp); } } catch (Exception e) { throw new ServiceException("Failed to parse " + offset + " using ISO8601", e); } return timestamp; }
From source file:ma.glasnost.orika.test.converter.CloneableConverterTestCase.java
@Test public void cloneableConverter() throws DatatypeConfigurationException { CloneableConverter cc = new CloneableConverter(SampleCloneable.class); MapperFactory factory = MappingUtil.getMapperFactory(); factory.getConverterFactory().registerConverter(cc); GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.YEAR, 10);/* www . j a v a2s.c o m*/ XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance() .newXMLGregorianCalendar((GregorianCalendar) cal); cal.add(Calendar.MONTH, 3); ClonableHolder source = new ClonableHolder(); source.value = new SampleCloneable(); source.value.id = 5L; source.date = new Date(System.currentTimeMillis() + 100000); source.timestamp = new Timestamp(System.currentTimeMillis() + 50000); source.calendar = cal; source.xmlCalendar = xmlCal; ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class); Assert.assertEquals(source.value, dest.value); Assert.assertNotSame(source.value, dest.value); Assert.assertEquals(source.date, dest.date); Assert.assertNotSame(source.date, dest.date); Assert.assertEquals(source.timestamp, dest.timestamp); Assert.assertNotSame(source.timestamp, dest.timestamp); Assert.assertEquals(source.calendar, dest.calendar); Assert.assertNotSame(source.calendar, dest.calendar); Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar); Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar); }
From source file:org.jboss.fuse.wsdl2rest.test.doclit.CamelRestDocLitTest.java
@Test public void testRestEndpoint() throws Exception { URL resourceUrl = getClass().getResource("/doclit/doclit-camel-context.xml"); CamelContext camelctx = SpringCamelContextFactory.createSingleCamelContext(resourceUrl, null); camelctx.start();//from ww w . ja v a 2 s . c o m try { Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus()); Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class); XMLGregorianCalendar dob = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(1968, 11, 11, 0); Item kermit = new ItemBuilder().name("Kermit").dateOfBirth(dob).build(); Item frog = new ItemBuilder().id(1).name("Frog").dateOfBirth(dob).build(); // GET @Address#listAddresses() ListAddressesResponse res1 = client.target(CONTEXT_URL + "/addresses").request() .get(ListAddressesResponse.class); Assert.assertEquals("[]", res1.getReturn()); // POST @Address#addAddress(String) AddAddress req2 = new AddAddress(); req2.setArg0(kermit); String payload = new ObjectMapper().writeValueAsString(req2); AddAddressResponse res2 = client.target(CONTEXT_URL + "/address").request() .post(Entity.entity(payload, MediaType.APPLICATION_JSON), AddAddressResponse.class); Assert.assertEquals(new Integer(1), res2.getReturn()); // GET @Address#getAddress(int) GetAddressResponse res3 = client.target(CONTEXT_URL + "/address/1").request() .get(GetAddressResponse.class); Assert.assertEquals("Kermit", res3.getReturn().getName()); // PUT @Address#updAddress(int, String) UpdAddress req4 = new UpdAddress(); req4.setArg0(frog); payload = new ObjectMapper().writeValueAsString(req4); UpdAddressResponse res4 = client.target(CONTEXT_URL + "/address").request() .put(Entity.entity(payload, MediaType.APPLICATION_JSON), UpdAddressResponse.class); Assert.assertEquals(new Integer(1), res4.getReturn()); // DEL @Address#delAddress(int) DelAddressResponse res5 = client.target(CONTEXT_URL + "/address/1").request() .delete(DelAddressResponse.class); Assert.assertEquals("Frog", res5.getReturn().getName()); } finally { camelctx.stop(); } }
From source file:net.javacrumbs.airline.server.VanillaTest.java
@Test public void testGetFlights() throws AirlineException, DatatypeConfigurationException { GetFlightsRequest request = new GetFlightsRequest(); request.setFrom("PRG"); request.setTo("DUB"); request.setServiceClass(ServiceClass.BUSINESS); request.setDepartureDate(DatatypeFactory.newInstance().newXMLGregorianCalendarDate(2011, 02, 23, 0)); //more setter calls could be here GetFlightsResponse response = endpoint.getFlights(request); List<Flight> flights = response.getFlight(); assertEquals(1, flights.size());/*from www.j av a2s . c om*/ assertEquals(ServiceClass.BUSINESS, flights.get(0).getServiceClass()); //more assertions here }
From source file:Main.java
public static XMLGregorianCalendar getXMLDate(final Date dateAndTime) { GregorianCalendar c = new GregorianCalendar(); c.setTimeZone(UTC);// w w w . ja v a 2s. c om c.setTime(dateAndTime); try { XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); return ret; } catch (DatatypeConfigurationException e) { return null; } }
From source file:org.jboss.fuse.wsdl2rest.test.rpclit.CamelRestRpcLitTest.java
@Test public void testRestEndpoint() throws Exception { URL resourceUrl = getClass().getResource("/rpclit/rpclit-camel-context.xml"); CamelContext camelctx = SpringCamelContextFactory.createSingleCamelContext(resourceUrl, null); camelctx.start();//from www . j a va 2 s. co m try { Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus()); Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class); XMLGregorianCalendar dob = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(1968, 11, 11, 0); Item kermit = new ItemBuilder().name("Kermit").dateOfBirth(dob).build(); Item frog = new ItemBuilder().id(1).name("Frog").dateOfBirth(dob).build(); // GET @Address#listAddresses() String res1 = client.target(CONTEXT_URL + "/addresses").request().get(String.class); Assert.assertEquals("[]", res1); // POST @Address#addAddress(Item) String payload = new ObjectMapper().writeValueAsString(kermit); Integer res2 = client.target(CONTEXT_URL + "/address").request() .post(Entity.entity(payload, MediaType.APPLICATION_JSON), Integer.class); Assert.assertEquals(new Integer(1), res2); // GET @Address#getAddress(int) Item res3 = client.target(CONTEXT_URL + "/address/1").request().get(Item.class); Assert.assertEquals("Kermit", res3.getName()); // PUT @Address#updAddress(Item) payload = new ObjectMapper().writeValueAsString(frog); Integer res4 = client.target(CONTEXT_URL + "/address").request() .put(Entity.entity(payload, MediaType.APPLICATION_JSON), Integer.class); Assert.assertEquals(new Integer(1), res4); // DEL @Address#delAddress(int) Item res5 = client.target(CONTEXT_URL + "/address/1").request().delete(Item.class); Assert.assertEquals("Frog", res5.getName()); } finally { camelctx.stop(); } }