Search in sources :

Example 11 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project OpenClinica by OpenClinica.

the class StudySubjectEndpoint method getXMLGregorianCalendarTime.

/**
     * Helper method that translates a date object (specifically time) to an XMLGregorianCalendar which is the data type used in jaxb generated classes.
     * 
     * @param date
     * @return XMLGregorianCalendar
     * @throws Exception
     */
private XMLGregorianCalendar getXMLGregorianCalendarTime(Date date) throws Exception {
    GregorianCalendar gc = new GregorianCalendar(locale);
    gc.setTime(date);
    DatatypeFactory df = DatatypeFactory.newInstance();
    XMLGregorianCalendar gcTime = df.newXMLGregorianCalendarTime(gc.get(Calendar.HOUR_OF_DAY), gc.get(Calendar.MINUTE), gc.get(Calendar.SECOND), null, DatatypeConstants.FIELD_UNDEFINED);
    return gcTime;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 12 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project OpenClinica by OpenClinica.

the class StudySubjectEndpoint method getXMLGregorianCalendarDate.

/**
     * Helper method that translates a date object to an XMLGregorianCalendar which is the data type used in jaxb generated classes.
     * 
     * @param date
     * @return XMLGregorianCalendar
     * @throws Exception
     */
private XMLGregorianCalendar getXMLGregorianCalendarDate(Date date) throws Exception {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    DatatypeFactory df = DatatypeFactory.newInstance();
    XMLGregorianCalendar gcDate = df.newXMLGregorianCalendarDate(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH) + 1, gc.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED);
    return gcDate;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeFactory(javax.xml.datatype.DatatypeFactory) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 13 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory 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 14 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project cloudstack by apache.

the class PerfManagerMO method calendarToXMLGregorianCalendar.

/**
     * Converts Calendar object into XMLGregorianCalendar
     *
     * @param calendar Object to be converted
     * @return XMLGregorianCalendar
     */
private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar();
    xgc.setYear(calendar.get(Calendar.YEAR));
    xgc.setMonth(calendar.get(Calendar.MONTH) + 1);
    xgc.setDay(calendar.get(Calendar.DAY_OF_MONTH));
    xgc.setHour(calendar.get(Calendar.HOUR_OF_DAY));
    xgc.setMinute(calendar.get(Calendar.MINUTE));
    xgc.setSecond(calendar.get(Calendar.SECOND));
    xgc.setMillisecond(calendar.get(Calendar.MILLISECOND));
    // Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds.
    int offsetInMinutes = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
    xgc.setTimezone(offsetInMinutes);
    return xgc;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeFactory(javax.xml.datatype.DatatypeFactory)

Example 15 with DatatypeFactory

use of javax.xml.datatype.DatatypeFactory in project jena by apache.

the class FunctionsSQL method toSQLdatetimeString.

/** Turn the lexical form of an XSD date into what SQL believes in */
public static String toSQLdatetimeString(String lex) {
    try {
        DatatypeFactory f = DatatypeFactory.newInstance();
        XMLGregorianCalendar cal = f.newXMLGregorianCalendar(lex);
        long millis = cal.toGregorianCalendar().getTimeInMillis();
        Timestamp timestamp = new Timestamp(millis);
        return timestamp.toString();
    } catch (DatatypeConfigurationException e) {
        LoggerFactory.getLogger(SQLUtils.class).warn("Failed to convert " + lex, e);
        return "0000-00-00 00:00:00";
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) DatatypeFactory(javax.xml.datatype.DatatypeFactory) Timestamp(java.sql.Timestamp)

Aggregations

DatatypeFactory (javax.xml.datatype.DatatypeFactory)22 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)17 GregorianCalendar (java.util.GregorianCalendar)10 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)9 Date (java.util.Date)7 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)5 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)5 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)5 Predicate (ddf.catalog.pubsub.predicate.Predicate)5 HashMap (java.util.HashMap)5 FilterTransformer (org.geotools.filter.FilterTransformer)5 Test (org.junit.Test)5 Filter (org.opengis.filter.Filter)5 Event (org.osgi.service.event.Event)5 ArrayList (java.util.ArrayList)3 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