List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java
/** * <pre>//from w w w . j a v a2s . co m * YYYYMMDDHH24MISS? ?? ?? XMLGregorialCalendar ? GMT(GMT+09:00) ? . * </pre> * @param dateString * @return */ public static String convertFormattedStringToXmlGregorianCalendarStr(String dateString) { Assert.notNull(dateString, "dateString must not be null."); if (dateString.length() < 14) { dateString = StringUtils.rightPad(dateString, 14, '0'); } Assert.isTrue(dateString.length() == 14, "dateString's length must be 14."); GregorianCalendar cal = null; XMLGregorianCalendar calender = null; try { cal = convertTimezone(getDate(dateString), TimeZone.getTimeZone("ROK")); calender = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); return calender.toString(); } catch (Exception e) { throw new IllegalArgumentException( " . : [Date : " + dateString + " ]"); } }
From source file:ejava.projects.edmv.bl.DataGen.java
public void generate(Writer writer) throws JAXBException, DatatypeConfigurationException { dtf = DatatypeFactory.newInstance(); JAXBContext jaxbc = JAXBContext.newInstance(Dmv.class); Marshaller m = jaxbc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Dmv dmvDoc = new Dmv(); dmvDoc.setPeople(new PersonsType()); dmvDoc.setVehicleRegistrations(new VehicleRegistrationsType()); //get all people int index = 0; List<DMVPerson> people; do {/*w ww . ja v a2s .c om*/ people = personDAO.getPeople(index, 10); for (DMVPerson p : people) { dmvDoc.getPeople().getPerson().add(createXMLPerson(p)); } index += people.size(); } while (people.size() > 0); log.debug("found " + index + " total people"); //get all vehicle registrations index = 0; List<DMVVehicleRegistration> vRegs; do { vRegs = vehicleDAO.getRegistrations(index, 10); for (DMVVehicleRegistration vReg : vRegs) { dmvDoc.getVehicleRegistrations().getVehicleRegistration() .add(createXMLRegistration(vReg, dmvDoc.getPeople())); } index += vRegs.size(); } while (vRegs.size() > 0); log.debug("found " + index + " total registrations"); m.marshal(dmvDoc, writer); }
From source file:DateUtils.java
/** * Converts a given time in milliseconds into a {@link XMLGregorianCalendar} object. * <p>/*w w w . j av a 2s. c o m*/ * The input milliseconds value represents the specified number of milliseconds since the standard base time known * as "the epoch", namely January 1, 1970, 00:00:00 GMT. * * @param date * A given time corresponding to the number of milliseconds since January 1, 1970, 00:00:00 GMT * @return A new instance of <code>XMLGregorianCalendar</code> representing the input time */ public static XMLGregorianCalendar toXmlGregorianCalendar(final long date) { try { final GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); } catch (final DatatypeConfigurationException ex) { System.out.println("Unable to convert date '%s' to an XMLGregorianCalendar object"); } }
From source file:com.att.ajsc.csilogging.util.UtilLib.java
public static XMLGregorianCalendar epochToXmlGC(long epoch) { try {/*from www .j av a 2 s. c o m*/ DatatypeFactory dtf = DatatypeFactory.newInstance(); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(epoch); gcal.setTimeZone(TimeZone.getTimeZone("Z")); XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar(gcal); return xgc; } catch (Exception e) { // Do nothing!!! - return a null; } return null; }
From source file:org.enotron.simulator.SimulatorRestController.java
public SimulatorRestController() throws DatatypeConfigurationException { _logger.info("Starting application"); factory = DatatypeFactory.newInstance(); }
From source file:ma.glasnost.orika.test.converter.CloneableConverterTestCase.java
/** * This test method demonstrates that you can decide to treat one of the default cloneable types * as immutable if desired by registering your own PassThroughConverter for that type * //www .j av a 2s . co m * @throws DatatypeConfigurationException */ @Test public void overrideDefaultCloneableToImmutable() throws DatatypeConfigurationException { PassThroughConverter cc = new PassThroughConverter(Date.class, Calendar.class); MapperFactory factory = MappingUtil.getMapperFactory(); factory.getConverterFactory().registerConverter(cc); GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.YEAR, 10); 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.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.assertSame(source.date, dest.date); Assert.assertEquals(source.calendar, dest.calendar); Assert.assertSame(source.calendar, dest.calendar); Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar); Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar); }
From source file:gov.nih.nci.integration.caaers.CaAERSParticipantServiceClientIntegrationTest.java
/** * Testcase for marshlling participant type * // www. j a va 2s . co m * @throws JAXBException - JAXBException * @throws DatatypeConfigurationException - DatatypeConfigurationException */ @Test public void marshalParticipantType() throws JAXBException, DatatypeConfigurationException { final ParticipantType pt = new ParticipantType(); pt.setFirstName("fn"); pt.setLastName("ln"); pt.setEthnicity(EthnicityType.NOT_HISPANIC_OR_LATINO); pt.setGender(GenderType.MALE); final DatatypeFactory df = DatatypeFactory.newInstance(); final GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); pt.setBirthDate(df.newXMLGregorianCalendar(gc)); pt.setRace(RaceType.WHITE); final OrganizationAssignedIdentifierType orgId = new OrganizationAssignedIdentifierType(); orgId.setType(ParticipantIdentifierType.MRN); orgId.setValue("123456"); orgId.setPrimaryIndicator(true); final OrganizationType ot = new OrganizationType(); ot.setName("UCSF)"); ot.setNciInstituteCode("UCSF"); orgId.setOrganization(ot); final ParticipantType.Identifiers ids = new ParticipantType.Identifiers(); ids.getOrganizationAssignedIdentifier().add(orgId); pt.setIdentifiers(ids); final AssignmentType at = new AssignmentType(); at.setStudySubjectIdentifier("456"); final StudySiteType sst = new StudySiteType(); final OrganizationType ot2 = new OrganizationType(); ot2.setName("UCSF)"); ot2.setNciInstituteCode("UCSF"); sst.setOrganization(ot2); final StudyType st = new StudyType(); final ReducedIdentifierType rit = new ReducedIdentifierType(); rit.setType(StudyIdentifierType.SITE_IDENTIFIER); rit.setValue("1.2.3.4.5"); final StudyType.Identifiers sids = new StudyType.Identifiers(); sids.setIdentifier(rit); st.setIdentifiers(sids); sst.setStudy(st); at.setStudySite(sst); final Assignments ass = new Assignments(); ass.getAssignment().add(at); pt.setAssignments(ass); final QName qname = new QName("http://webservice.caaers.cabig.nci.nih.gov/participant", "participant"); final JAXBElement<ParticipantType> ptJaxbEle = new JAXBElement<ParticipantType>(qname, ParticipantType.class, pt); final StringWriter sw = new StringWriter(); getMarshaller().marshal(ptJaxbEle, sw); Assert.assertNotNull(sw.toString()); JAXBElement<ParticipantType> jaxbEle = (JAXBElement<ParticipantType>) getUnMarshaller() .unmarshal(new StreamSource(new StringReader(sw.toString())), ParticipantType.class); Assert.assertNotNull(jaxbEle); Assert.assertNotNull(jaxbEle.getValue()); jaxbEle = (JAXBElement<ParticipantType>) getUnMarshaller() .unmarshal(new StreamSource(new StringReader(getPStr())), ParticipantType.class); Assert.assertNotNull(jaxbEle); final ParticipantType ptn = jaxbEle.getValue(); Assert.assertNotNull(ptn); }
From source file:com.cisco.cta.taxii.adapter.AdapterConfiguration.java
@Bean public DatatypeFactory datatypeFactory() throws DatatypeConfigurationException { return DatatypeFactory.newInstance(); }
From source file:org.enotron.EnergySimulatorEndpoint.java
public EnergySimulatorEndpoint() { try {/* w w w. j a v a2 s.com*/ factory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { _logger.warning("Exception on XML DataFactory Creation: " + e.getMessage()); e.printStackTrace(); } }
From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java
/** * <pre>// ww w. j a v a 2s.c o m * YYYYMMDDHH24MISS? ?? ?? XMLGregorialCalendar . * </pre> * @param dateString * @return */ public static XMLGregorianCalendar convertFormattedStringToXmlGregorianCalendar(String dateString) { Assert.notNull(dateString, "dateString must not be null."); GregorianCalendar cal = null; XMLGregorianCalendar calender = null; try { cal = convertTimezone(getDate(dateString), TimeZone.getTimeZone("ROK")); calender = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); } catch (Exception e) { throw new IllegalArgumentException( " . : [Date : " + dateString + " ]"); } return calender; }