Example usage for javax.xml.datatype DatatypeFactory newInstance

List of usage examples for javax.xml.datatype DatatypeFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newInstance.

Prototype

public static DatatypeFactory newInstance() throws DatatypeConfigurationException 

Source Link

Document

Obtain a new instance of a DatatypeFactory .

Usage

From source file:edu.harvard.hms.dbmi.i2b2.api.ont.ONTCell.java

/**
 * Gets ontology process status// w w w .ja va2s  .  c om
 * 
 * @param client
 *            HTTP Client
 * @param max
 *            Maximum results to return
 * @param startDateStartTime
 *            start process start
 * @param startDateEndTime
 *            start process end
 * @param endDateStartTime
 *            end process start
 * @param endDateEndTime
 *            end process end
 * @param processId
 *            Process Id
 * @param processStatusCd
 *            Process Status
 * @param processTypeCd
 *            Process type
 * @return Process status
 * @throws JAXBException
 *             An XML Processing Exception occurred
 * @throws UnsupportedOperationException
 *             An unsupported operation exception occurred
 * @throws I2B2InterfaceException
 *             An error occurred on the i2b2 server
 * @throws IOException
 *             An IO Exception occurred
 * @throws DatatypeConfigurationException
 */
public OntologyProcessStatusListType getOntologyProcessStatus(HttpClient client, int max,
        GregorianCalendar startDateStartTime, GregorianCalendar startDateEndTime,
        GregorianCalendar endDateStartTime, GregorianCalendar endDateEndTime, String processId,
        String processStatusCd, String processTypeCd) throws JAXBException, UnsupportedOperationException,
        I2B2InterfaceException, IOException, DatatypeConfigurationException {
    RequestMessageType rmt = createMinimumBaseMessage("/getOntologyProcessStatus");

    GetOntProcessStatusType opst = ontOF.createGetOntProcessStatusType();
    opst.setMaxReturnRecords(max);

    ProcessStartDate psd = ontOF.createGetOntProcessStatusTypeProcessStartDate();
    psd.setEndTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(startDateEndTime));
    psd.setStartTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(startDateStartTime));

    opst.setProcessStartDate(psd);
    ProcessEndDate ped = ontOF.createGetOntProcessStatusTypeProcessEndDate();
    ped.setEndTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(endDateEndTime));
    ped.setStartTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(endDateStartTime));
    opst.setProcessEndDate(ped);

    opst.setProcessId(processId);
    opst.setProcessStatusCd(processStatusCd);
    opst.setProcessTypeCd(processTypeCd);

    rmt.getMessageBody().getAny().add(ontOF.createGetOntProcessStatus(opst));

    // Mashall the XML to String and attach it to the post request
    StringWriter sw = new StringWriter();
    ontMarshaller.marshal(ontOF.createRequest(rmt), sw);

    return getType(ontOF.createOntologyProcessStatusListType(),
            runRequest(client, sw.toString(), "/getOntologyProcessStatus"));
}

From source file:gov.nih.nci.integration.caaers.CaAERSParticipantStrategyTest.java

private ResponseDataType getParticipantResponseData() throws DatatypeConfigurationException {
    final ResponseDataType resDataType = new ResponseDataType();
    final Participants participants = new Participants();
    final ParticipantType participant = new ParticipantType();
    participant.setFirstName("updCherry060801");
    participant.setLastName("Blossom060801");
    final GregorianCalendar gcal3 = new GregorianCalendar(1960, 06, 15);
    final XMLGregorianCalendar xgcal3 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal3);
    participant.setBirthDate(xgcal3);/*w ww  .j av a2  s  .c  om*/
    participant.setGender(GenderType.MALE);
    participant.setRace(RaceType.BLACK_OR_AFRICAN_AMERICAN);
    participant.setEthnicity(EthnicityType.NOT_HISPANIC_OR_LATINO);

    participants.getParticipant().add(participant);
    resDataType.setAny(participants);
    return resDataType;
}

From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.i2b2.I2B2XMLResourceImplementation.java

private ItemType.ConstrainByDate createConstrainByDate(WhereClause whereClause)
        throws DatatypeConfigurationException {
    ItemType.ConstrainByDate cbd = new ItemType.ConstrainByDate();
    ConstrainDateType from = new ConstrainDateType();
    from.setInclusive(InclusiveType.fromValue(whereClause.getStringValues().get("FROM_INCLUSIVE")));
    from.setTime(ConstrainDateTimeType.fromValue(whereClause.getStringValues().get("FROM_TIME")));

    from.setValue(DatatypeFactory.newInstance()
            .newXMLGregorianCalendar(whereClause.getStringValues().get("FROM_DATE")));

    cbd.setDateFrom(from);//w  w  w.  j  a  v a 2  s . c  o  m

    ConstrainDateType to = new ConstrainDateType();
    to.setInclusive(InclusiveType.fromValue(whereClause.getStringValues().get("TO_INCLUSIVE")));
    to.setTime(ConstrainDateTimeType.fromValue(whereClause.getStringValues().get("TO_TIME")));
    to.setValue(DatatypeFactory.newInstance()
            .newXMLGregorianCalendar(whereClause.getStringValues().get("TO_DATE")));
    cbd.setDateTo(to);
    return cbd;
}

From source file:com.headstrong.npi.raas.Utils.java

public static CmAttributeDate getCmAttrDate(String dateStr) {
    if (null != dateStr && !dateStr.trim().isEmpty()) {
        Date date = DateConversion.getDateFromString(dateStr);
        if (null != date) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(date);/*from   w ww .j  a v  a2 s.c o m*/
            XMLGregorianCalendar xmlGregorianCalendar;
            try {
                xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
            } catch (DatatypeConfigurationException e) {
                e.printStackTrace();
                return null;
            }
            CmAttributeDate cmAttributeDate = new CmAttributeDate();
            cmAttributeDate.setValue(xmlGregorianCalendar);

            return cmAttributeDate;
        }
    }
    return null;
}

From source file:ddf.catalog.pubsub.PredicateTest.java

@Test
public void testTemporal() throws Exception {
    String methodName = "testTemporal";
    LOGGER.debug("***************  START: " + methodName + "  *****************");

    MockQuery query = new MockQuery();

    DatatypeFactory df = DatatypeFactory.newInstance();
    XMLGregorianCalendar start = df.newXMLGregorianCalendarDate(2011, 10, 25, 0);
    XMLGregorianCalendar end = df.newXMLGregorianCalendarDate(2011, 10, 27, 0);
    query.addTemporalFilter(start, end, Metacard.EFFECTIVE);

    SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
    Predicate pred = (Predicate) query.getFilter().accept(visitor, null);
    LOGGER.debug("resulting predicate: " + pred);

    Filter filter = query.getFilter();
    FilterTransformer transform = new FilterTransformer();
    transform.setIndentation(2);// w  ww.j  av  a2  s.c  o m
    String filterXml = transform.transform(filter);
    LOGGER.debug(filterXml);

    // input that passes temporal
    LOGGER.debug("\npass temporal.\n");
    MetacardImpl metacard = new MetacardImpl();
    metacard.setCreatedDate(new Date());
    metacard.setExpirationDate(new Date());
    metacard.setModifiedDate(new Date());
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());

    XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0);
    Date effectiveDate = cal.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate);

    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);

    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl

    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    Event testEvent = new Event("topic", properties);
    boolean b = pred.matches(testEvent);
    assertTrue(b);

    // input that fails temporal
    LOGGER.debug("\nfail temporal.  fail content type.\n");
    XMLGregorianCalendar cal1 = df.newXMLGregorianCalendarDate(2012, 10, 30, 0); // time out of
    // range
    Date effectiveDate1 = cal1.toGregorianCalendar().getTime();
    metacard.setEffectiveDate(effectiveDate1);
    LOGGER.debug("metacard date: " + metacard.getEffectiveDate());

    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    testEvent = new Event("topic", properties);
    assertFalse(pred.matches(testEvent));

    LOGGER.debug("***************  END: " + methodName + "  *****************");
}

From source file:eu.europa.esig.dss.DSSXMLUtils.java

/**
 * Converts a given {@code Date} to a new {@code XMLGregorianCalendar}.
 *
 * @param date the date to be converted/* w  ww  .j  a  v  a 2  s .  c  o  m*/
 * @return the new {@code XMLGregorianCalendar} or null
 */
public static XMLGregorianCalendar createXMLGregorianCalendar(final Date date) {

    if (date == null) {
        return null;
    }
    final GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {

        XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(calendar);
        xmlGregorianCalendar.setFractionalSecond(null);
        xmlGregorianCalendar = xmlGregorianCalendar.normalize(); // to UTC = Zulu
        return xmlGregorianCalendar;
    } catch (DatatypeConfigurationException e) {
        LOG.warn("Unable to properly convert a Date to an XMLGregorianCalendar " + e.getMessage(), e);
    }
    return null;
}

From source file:be.fedict.trust.client.XKMS2Client.java

private XMLGregorianCalendar getXmlGregorianCalendar(Date date) {
    try {//from ww w  .j  ava2s .  co m
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();

        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTime(date);
        XMLGregorianCalendar currentXmlGregorianCalendar = datatypeFactory
                .newXMLGregorianCalendar(gregorianCalendar);
        return currentXmlGregorianCalendar;

    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("datatype config error");
    }
}

From source file:eu.europa.esig.dss.DSSXMLUtils.java

/**
 * This method allows to convert the given text (XML representation of a date) to the {@code Date}.
 *
 * @param text the text representing the XML date
 * @return {@code Date} converted or null
 *//*from w ww  .j av a  2  s  .  c o  m*/
public static Date getDate(final String text) {

    try {

        final DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        final XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(text);
        return xmlGregorianCalendar.toGregorianCalendar().getTime();
    } catch (DatatypeConfigurationException e) {
        // do nothing
    }
    return null;
}

From source file:gov.va.ds4p.ds4pmobileportal.pep.XACMLPolicyEnforcement.java

private XMLGregorianCalendar getCurrentDateTime() {
    XMLGregorianCalendar xgc = null;
    try {//from  w ww  . j  a  va2s  .c  om
        GregorianCalendar gc = new GregorianCalendar();
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        xgc = dtf.newXMLGregorianCalendar(gc);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return xgc;
}

From source file:it.cnr.icar.eric.server.common.ServerRequestContext.java

private void saveAuditableEvents() throws RegistryException {
    UserType user = getUser();/*from   www .  j  ava 2  s. c  o m*/

    if (user != null) {
        auditableEvents.clear();

        XMLGregorianCalendar timeNow;
        try {
            timeNow = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());

            //create events during relocate event should be ignored
            if (eventOccured(getRelocateEvent())) {
                getRelocateEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getRelocateEvent());
                auditableEvents.add(getRelocateEvent());
            } else if (eventOccured(getCreateEvent())) {
                getCreateEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getCreateEvent());
                auditableEvents.add(getCreateEvent());
            }

            //Delete during update should be ignored as they are an impl artifact
            if (eventOccured(getUpdateEvent())) {
                getUpdateEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getUpdateEvent());
                auditableEvents.add(getUpdateEvent());
            } else if (eventOccured(getDeleteEvent())) {
                getDeleteEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getDeleteEvent());
                auditableEvents.add(getDeleteEvent());
            }

            if (eventOccured(getSetStatusEvent())) {
                getSetStatusEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getSetStatusEvent());
                auditableEvents.add(getSetStatusEvent());
            }

            if (eventOccured(getApproveEvent())) {
                getApproveEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getApproveEvent());
                auditableEvents.add(getApproveEvent());
            }

            if (eventOccured(getDeprecateEvent())) {
                getDeprecateEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getDeprecateEvent());
                auditableEvents.add(getDeprecateEvent());
            }

            if (eventOccured(getUnDeprecateEvent())) {
                getUnDeprecateEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getUnDeprecateEvent());
                auditableEvents.add(getUnDeprecateEvent());
            }

            if (eventOccured(getVersionEvent())) {
                getVersionEvent().setTimestamp(timeNow);
                removeDuplicateAffectedObjects(getVersionEvent());
                auditableEvents.add(getVersionEvent());
            }

            if (auditableEvents.size() > 0) {
                getCreateEvent().setTimestamp(timeNow);
                pm.insert(this, auditableEvents);
            }
        } catch (DatatypeConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}