use of javax.xml.datatype.DatatypeFactory in project cxf by apache.
the class SubscriptionManagerImpl method grantExpiration.
/**
* Decide what expiration time to grant to the subscription, if
* the client did not specify any particular wish for subscription length.
*/
public XMLGregorianCalendar grantExpiration() {
try {
// by default, we grant an expiration time of 2 years
DatatypeFactory factory = DatatypeFactory.newInstance();
XMLGregorianCalendar granted = factory.newXMLGregorianCalendar(new GregorianCalendar());
granted.add(factory.newDurationYearMonth(true, 2, 0));
return granted;
} catch (DatatypeConfigurationException ex) {
throw new Error(ex);
}
}
use of javax.xml.datatype.DatatypeFactory in project Payara by payara.
the class ScheduledTimerNode method setElementValue.
@Override
public void setElementValue(XMLElement element, String value) {
if (EjbTagNames.TIMER_START.equals(element.getQName())) {
try {
DatatypeFactory dFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar xmlGreg = dFactory.newXMLGregorianCalendar(value);
GregorianCalendar cal = xmlGreg.toGregorianCalendar();
descriptor.setStart(cal.getTime());
} catch (Exception e) {
DOLUtils.getDefaultLogger().warning(e.getMessage());
}
} else if (EjbTagNames.TIMER_END.equals(element.getQName())) {
try {
DatatypeFactory dFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar xmlGreg = dFactory.newXMLGregorianCalendar(value);
GregorianCalendar cal = xmlGreg.toGregorianCalendar();
descriptor.setEnd(cal.getTime());
} catch (Exception e) {
DOLUtils.getDefaultLogger().warning(e.getMessage());
}
} else {
super.setElementValue(element, value);
}
}
use of javax.xml.datatype.DatatypeFactory in project jackson-module-afterburner by FasterXML.
the class JavaxTypesTest method testGregorianCalendar.
public void testGregorianCalendar() throws Exception {
DatatypeFactory 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());
}
use of javax.xml.datatype.DatatypeFactory in project OpenMEAP by OpenMEAP.
the class BankingService method submitTransfer.
public synchronized Error submitTransfer(String userName, String srcAcct, String destAcct, Date date, double amount) {
DatatypeFactory df = null;
try {
df = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException dce) {
throw new RuntimeException(dce);
}
Account src = null, dest = null;
src = findAccount(userName, srcAcct);
dest = findAccount(userName, destAcct);
if (src == null || dest == null) {
Error err = new Error();
err.setCode(ErrorType.PARAM_BAD);
err.setMessage("Could not find either the source or destination account.");
return err;
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(date.getTime());
submitTransfer(src, dest, df.newXMLGregorianCalendar(cal), amount);
return null;
}
use of javax.xml.datatype.DatatypeFactory in project OpenMEAP by OpenMEAP.
the class TransactionDateComparatorTest method testDateComparator.
@Test
public void testDateComparator() {
DatatypeFactory df = null;
try {
df = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException dce) {
throw new RuntimeException(dce);
}
List<Transaction> tl = new ArrayList<Transaction>();
Transaction t = new Transaction();
t.setAcctNumber("1");
t.setDate(df.newXMLGregorianCalendar("2011-03-03T12:00:00+03:00"));
tl.add(t);
t = new Transaction();
t.setAcctNumber("2");
t.setDate(df.newXMLGregorianCalendar("2011-03-03T12:00:00+03:00"));
tl.add(t);
t = new Transaction();
t.setAcctNumber("3");
t.setDate(df.newXMLGregorianCalendar("2011-03-04T12:00:00+03:00"));
tl.add(t);
t = new Transaction();
t.setAcctNumber("4");
t.setDate(df.newXMLGregorianCalendar("2011-03-01T12:00:00+03:00"));
tl.add(t);
Collections.sort(tl, new TransactionDateComparator());
Assert.assertTrue(tl.get(0).getAcctNumber().equals("4"));
Assert.assertTrue(tl.get(1).getAcctNumber().equals("1"));
Assert.assertTrue(tl.get(2).getAcctNumber().equals("2"));
Assert.assertTrue(tl.get(3).getAcctNumber().equals("3"));
}
Aggregations