Search in sources :

Example 6 with DatatypeConfigurationException

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;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Serializable(java.io.Serializable) DateTimeElement(ddf.catalog.transformer.xml.binding.DateTimeElement) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Date(java.util.Date)

Example 7 with DatatypeConfigurationException

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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) EchoedRequestType(net.opengis.cat.csw.v_2_0_2.EchoedRequestType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBContext(javax.xml.bind.JAXBContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Example 8 with DatatypeConfigurationException

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);
    }
}
Also used : MonitorNotification(javax.management.monitor.MonitorNotification) Marshaller(javax.xml.bind.Marshaller) AttributeChangeNotification(javax.management.AttributeChangeNotification) DatatypeFactory(javax.xml.datatype.DatatypeFactory) MBeanServerNotification(javax.management.MBeanServerNotification) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) RelationNotification(javax.management.relation.RelationNotification) TimerNotification(javax.management.timer.TimerNotification) Date(java.util.Date) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) StringWriter(java.io.StringWriter) NotificationEventType(org.apache.camel.component.jmx.jaxb.NotificationEventType) ObjectNamesType(org.apache.camel.component.jmx.jaxb.ObjectNamesType) JMXConnectionNotification(javax.management.remote.JMXConnectionNotification)

Example 9 with DatatypeConfigurationException

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;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 10 with DatatypeConfigurationException

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"));
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ArrayList(java.util.ArrayList)

Aggregations

DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)14 GregorianCalendar (java.util.GregorianCalendar)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 DatatypeFactory (javax.xml.datatype.DatatypeFactory)7 Date (java.util.Date)5 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 Marshaller (javax.xml.bind.Marshaller)2 QName (javax.xml.namespace.QName)2 MXBooleanType (com.ibm.maximo.MXBooleanType)1 MXDateTimeType (com.ibm.maximo.MXDateTimeType)1 MXStringType (com.ibm.maximo.MXStringType)1 FreeBusyResponseType (com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType)1 GetUserAvailabilityRequestType (com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityRequestType)1 GetUserAvailabilityResponseType (com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityResponseType)1 ArrayOfMailboxData (com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData)1