use of javax.xml.datatype.DatatypeConfigurationException in project ddf by codice.
the class DateTimeAdapter method marshalFrom.
public static DateTimeElement marshalFrom(Attribute attribute) {
DateTimeElement element = new DateTimeElement();
element.setName(attribute.getName());
if (attribute.getValue() != null) {
for (Serializable value : attribute.getValues()) {
if (!(value instanceof Date)) {
continue;
}
Date date = (Date) value;
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
try {
((DateTimeElement) element).getValue().add(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
} catch (DatatypeConfigurationException e) {
LOGGER.debug("Could not parse Metacard Attribute. XML Date could not be generated.", e);
}
}
}
return element;
}
use of javax.xml.datatype.DatatypeConfigurationException in project ddf by codice.
the class CswQueryResponseTransformer method writeAcknowledgement.
private ByteArrayOutputStream writeAcknowledgement(GetRecordsType request) throws CatalogTransformerException {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JAXBContext jaxBContext = JAXBContext.newInstance("net.opengis.cat.csw.v_2_0_2:" + "net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1:net.opengis.ows.v_1_0_0");
Marshaller marshaller = jaxBContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
AcknowledgementType ack = new AcknowledgementType();
EchoedRequestType echoedRequest = new EchoedRequestType();
JAXBElement<GetRecordsType> jaxBRequest = new ObjectFactory().createGetRecords(request);
echoedRequest.setAny(jaxBRequest);
ack.setEchoedRequest(echoedRequest);
try {
ack.setTimeStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
} catch (DatatypeConfigurationException e) {
LOGGER.debug("Failed to set timestamp on Acknowledgement, Exception {}", e);
}
JAXBElement<AcknowledgementType> jaxBAck = new ObjectFactory().createAcknowledgement(ack);
marshaller.marshal(jaxBAck, byteArrayOutputStream);
return byteArrayOutputStream;
} catch (JAXBException e) {
throw new CatalogTransformerException(e);
}
}
use of javax.xml.datatype.DatatypeConfigurationException in project camel by apache.
the class NotificationXmlFormatter method format.
public String format(Notification aNotification) throws NotificationFormatException {
ObjectHelper.notNull(jaxbContext, "jaxbContext");
NotificationEventType jaxb;
boolean wrap = false;
if (aNotification instanceof AttributeChangeNotification) {
AttributeChangeNotification ac = (AttributeChangeNotification) aNotification;
jaxb = mObjectFactory.createAttributeChangeNotification().withAttributeName(ac.getAttributeName()).withAttributeType(ac.getAttributeType()).withNewValue(ac.getNewValue() == null ? null : String.valueOf(ac.getNewValue())).withOldValue(ac.getOldValue() == null ? null : String.valueOf(ac.getOldValue()));
} else if (aNotification instanceof JMXConnectionNotification) {
jaxb = mObjectFactory.createJMXConnectionNotification().withConnectionId(((JMXConnectionNotification) aNotification).getConnectionId());
} else if (aNotification instanceof MBeanServerNotification) {
jaxb = mObjectFactory.createMBeanServerNotification().withMBeanName(String.valueOf(((MBeanServerNotification) aNotification).getMBeanName()));
} else if (aNotification instanceof MonitorNotification) {
MonitorNotification mn = (MonitorNotification) aNotification;
jaxb = mObjectFactory.createMonitorNotification().withDerivedGauge(String.valueOf(mn.getDerivedGauge())).withObservedAttribute(mn.getObservedAttribute()).withObservedObject(String.valueOf(mn.getObservedObject())).withTrigger(String.valueOf(mn.getTrigger()));
} else if (aNotification instanceof RelationNotification) {
RelationNotification rn = (RelationNotification) aNotification;
jaxb = mObjectFactory.createRelationNotification().withObjectName(String.valueOf(rn.getObjectName())).withRelationId(rn.getRelationId()).withRelationTypeName(rn.getRelationTypeName()).withRoleName(rn.getRoleName());
if (rn.getNewRoleValue() != null) {
ObjectNamesType ont = toObjectNamesType(rn.getNewRoleValue());
((org.apache.camel.component.jmx.jaxb.RelationNotification) jaxb).withNewRoleValue(ont);
}
if (rn.getOldRoleValue() != null) {
ObjectNamesType ont = toObjectNamesType(rn.getOldRoleValue());
((org.apache.camel.component.jmx.jaxb.RelationNotification) jaxb).withOldRoleValue(ont);
}
if (rn.getMBeansToUnregister() != null) {
ObjectNamesType ont = toObjectNamesType(rn.getMBeansToUnregister());
((org.apache.camel.component.jmx.jaxb.RelationNotification) jaxb).withMBeansToUnregister(ont);
}
} else if (aNotification instanceof TimerNotification) {
jaxb = mObjectFactory.createTimerNotification().withNotificationId(((TimerNotification) aNotification).getNotificationID());
} else {
jaxb = mObjectFactory.createNotificationEventType();
wrap = true;
}
// add all of the common properties
jaxb.withMessage(aNotification.getMessage()).withSequence(aNotification.getSequenceNumber()).withSource(String.valueOf(aNotification.getSource())).withTimestamp(aNotification.getTimeStamp()).withType(aNotification.getType());
if (aNotification.getUserData() != null) {
jaxb.withUserData(String.valueOf(aNotification.getUserData()));
}
try {
DatatypeFactory df = getDatatypeFactory();
Date date = new Date(aNotification.getTimeStamp());
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
jaxb.withDateTime(df.newXMLGregorianCalendar(gc));
Object bean = wrap ? mObjectFactory.createNotificationEvent(jaxb) : jaxb;
StringWriter sw = new StringWriter();
// must create a new marshaller as its not thread safe
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(bean, sw);
return sw.toString();
} catch (JAXBException e) {
throw new NotificationFormatException(e);
} catch (DatatypeConfigurationException e) {
throw new NotificationFormatException(e);
}
}
use of javax.xml.datatype.DatatypeConfigurationException 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.DatatypeConfigurationException 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