List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:name.persistent.behaviours.PURLValidationSupport.java
private XMLGregorianCalendar today() throws DatatypeConfigurationException { GregorianCalendar cal;//from w w w . j a v a 2 s . co m XMLGregorianCalendar today; int n = DatatypeConstants.FIELD_UNDEFINED; DatatypeFactory f = DatatypeFactory.newInstance(); cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); today = f.newXMLGregorianCalendar(cal); today.setTime(n, n, n, n); return today; }
From source file:edu.cornell.mannlib.semservices.util.XMLGregorianCalendarConverter.java
/** * Convert the specified input object into an output object of the specified * type./*from w w w . j a v a2s .c om*/ * * @param type * XMLGregorianCalendar type to which this value should be * converted * @param value * The input value to be converted * * @exception ConversionException * if conversion cannot be performed successfully */ @SuppressWarnings("unchecked") public Object convert(Class type, Object value) { if (value == null) { if (useDefault) { return (defaultValue); } else { throw new ConversionException("No value specified"); } } if (value instanceof XMLGregorianCalendar) { return (value); } try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(value.toString()); } catch (Exception e) { if (useDefault) { return (defaultValue); } else { throw new ConversionException(e); } } }
From source file:ma.glasnost.orika.test.converter.CloneableConverterNoSetAccessibleTestCase.java
@Test public void cloneableConverterWithoutSetAccessible() throws DatatypeConfigurationException { final SecurityManager initialSm = System.getSecurityManager(); try {//from www.j a v a 2s.c o m System.setSecurityManager(new SecurityManager() { public void checkPermission(java.security.Permission perm) { if ("suppressAccessChecks".equals(perm.getName())) { for (StackTraceElement ste : new Throwable().getStackTrace()) { if (ste.getClassName().equals(CloneableConverter.class.getCanonicalName())) { throw new SecurityException("not permitted"); } } } } }); CloneableConverter cc = new CloneableConverter(SampleCloneable.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.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); } finally { System.setSecurityManager(initialSm); } }
From source file:com.cisco.cta.taxii.adapter.AdapterTaskTest.java
@Before public void setUp() throws Exception { datatypeFactory = DatatypeFactory.newInstance(); MockitoAnnotations.initMocks(this); ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(AdapterTask.class)).addAppender(mockAppender); when(settings.getFeeds()).thenReturn(ImmutableList.of("my-collection")); task = new AdapterTask(requestFactory, responseTransformer, settings, statistics, taxiiStatusDao); when(requestFactory.createPollRequest(anyString(), any(TaxiiStatus.Feed.class))).thenReturn(request); feed = new TaxiiStatus.Feed(); feed.setName("my-collection"); }
From source file:com.rogers.ute.creditservice.util.CreditServiceUtils.java
public static XMLGregorianCalendar asXMLGregorianCalendar(Date date) { try {/*from www . j a v a 2 s . com*/ GregorianCalendar instance = new GregorianCalendar(); instance.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(instance); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:eu.prestoprime.p4gui.connection.AdminConnection.java
public static JobList monitorJobs(P4Service service, String filter) { if (filter == null || filter.equals("")) filter = "all"; JobList jobList = new JobList(); try {/* w ww . j av a2s . com*/ String path = service.getURL() + "/admin/jobs/" + filter; P4HttpClient client = new P4HttpClient(service.getUserID()); HttpRequestBase request = new HttpGet(path); HttpEntity entity = client.executeRequest(request).getEntity(); if (entity != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); String line; while ((line = reader.readLine()) != null) { String[] fields = line.split("\\t"); jobList.addJob(jobList.new Job(fields[0], // jobID StatusType.valueOf(fields[1].toUpperCase()), // status fields[2], // wfID fields[3].equals("") ? null : DatatypeFactory.newInstance().newXMLGregorianCalendar(fields[3]), // startup fields[4].equals("") ? 0L : Long.parseLong(fields[4]), // duration Integer.parseInt(fields[5]), // totalSteps Integer.parseInt(fields[6]), // lastCompletedStep fields.length < 8 ? null : fields[7])); // lastCompletedService } } } catch (Exception e) { e.printStackTrace(); } return jobList; }
From source file:eu.openminted.registry.service.generate.WorkflowOutputMetadataGenerate.java
protected MetadataHeaderInfo generateMetadataHeaderInfo(String userId) throws IOException { MetadataHeaderInfo metadataHeaderInfo = new MetadataHeaderInfo(); // Set metadata record identifier MetadataIdentifier identifier = new MetadataIdentifier(); identifier.setValue(UUID.randomUUID().toString()); identifier.setMetadataIdentifierSchemeName(MetadataIdentifierSchemeNameEnum.OMTD); metadataHeaderInfo.setMetadataRecordIdentifier(identifier); // Set creation date and last date updated XMLGregorianCalendar calendar = null; try {/* w w w . j av a 2 s . c om*/ calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregory); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } metadataHeaderInfo.setMetadataCreationDate(calendar); metadataHeaderInfo.setMetadataLastDateUpdated(calendar); // Set metadata creator metadataHeaderInfo.setMetadataCreators(new ArrayList<PersonInfo>()); PersonInfo personInfo = generatePersonInfo(userId, true); metadataHeaderInfo.getMetadataCreators().add(personInfo); logger.debug("MetadataHeaderInfo:\n" + mapper.writeValueAsString(metadataHeaderInfo) + "\n"); return metadataHeaderInfo; }
From source file:org.vincibean.salestaxes.service.implementations.ReceiptServiceImpl.java
/** * Factory method, create a {@link HeaderType}, an object containing basic informations (e.g. date of emission, * issuer, etc...)/*from w ww . j a v a2 s . co m*/ * @return a fully populated {@link HeaderType}. */ private HeaderType createHeader() { HeaderType header = new HeaderType(); header.setIssuer(ISSUER_NAME); try { header.setTimeStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar())); } catch (DatatypeConfigurationException e) { logger.debug("Unexpected error while giving the Receipt's Header a timestamp."); } return header; }
From source file:com.evolveum.midpoint.repo.sql.CleanupTest.java
License:asdf
private Duration createDuration(Calendar when, long now) throws Exception { long seconds = (now - when.getTimeInMillis()) / 1000; return DatatypeFactory.newInstance().newDuration("PT" + seconds + "S").negate(); }
From source file:com.erbjuder.logger.client.logmessage.util.LoggerToProxyObjects.java
public static XMLGregorianCalendar date2Gregorian(Date date) { DatatypeFactory dataTypeFactory; try {/*from www . j a v a2 s .co m*/ dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("UTC")); gc.setTime(date); return dataTypeFactory.newXMLGregorianCalendar(gc); }