Example usage for javax.xml.datatype XMLGregorianCalendar setHour

List of usage examples for javax.xml.datatype XMLGregorianCalendar setHour

Introduction

In this page you can find the example usage for javax.xml.datatype XMLGregorianCalendar setHour.

Prototype

public abstract void setHour(int hour);

Source Link

Document

Set hours.

Usage

From source file:DatatypeAPIUsage.java

public static void main(String[] args) {
    try {//from  w ww  .j  a va  2  s . c o m
        DatatypeFactory df = DatatypeFactory.newInstance();
        // my work number in milliseconds:
        Duration myPhone = df.newDuration(9054133519l);
        Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0);
        int compareVal = myPhone.compare(myLife);
        switch (compareVal) {
        case DatatypeConstants.LESSER:
            System.out.println("There are fewer milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.EQUAL:
            System.out.println("The same number of milliseconds are in my phone number and my lifespan.");
            break;
        case DatatypeConstants.GREATER:
            System.out.println("There are more milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.INDETERMINATE:
            System.out.println("The comparison could not be carried out.");
        }

        // create a yearMonthDuration
        Duration ymDuration = df.newDurationYearMonth("P12Y10M");
        System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType());

        // create a dayTimeDuration (really this time)
        Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S");
        System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType());

        // try to fool the factory!
        try {
            ymDuration = df.newDurationYearMonth("P12Y10M1D");
        } catch (IllegalArgumentException e) {
            System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!");
        }

        XMLGregorianCalendar xgc = df.newXMLGregorianCalendar();
        xgc.setYear(1975);
        xgc.setMonth(DatatypeConstants.AUGUST);
        xgc.setDay(11);
        xgc.setHour(6);
        xgc.setMinute(44);
        xgc.setSecond(0);
        xgc.setMillisecond(0);
        xgc.setTimezone(5);
        xgc.add(myPhone);
        System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc);

        // adding a duration to XMLGregorianCalendar
        xgc.add(myLife);
        System.out.println("Adding the duration myLife to the above calendar:" + xgc);

        // create a new XMLGregorianCalendar using the string format of xgc.
        XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat());

        // should be equal-if not what happened!!
        if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) {
            System.out.println("oooops!");
        } else {
            System.out.println("Very good: " + xgc + " is equal to " + xgcCopy);
        }
    } catch (DatatypeConfigurationException dce) {
        System.err.println("error: Datatype error occurred - " + dce.getMessage());
        dce.printStackTrace(System.err);
    }
}

From source file:edu.harvard.i2b2.query.data.QueryConceptTreePanelData.java

public ConstrainByDate writeTimeConstraint() {
    ConstrainByDate timeConstrain = new ConstrainByDate();
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    log.info("Timezone: " + tz.getID() + " : " + zt_offset);

    if (startTime() != -1) {
        ConstrainDateType constraindateType = new ConstrainDateType();
        XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(startYear(), startMonth() + 1,
                startDay());//from w w  w .j a  va2s  . c om
        xmlC.setTimezone(zt_offset);//0);//-5*60);
        xmlC.setHour(0);
        xmlC.setMinute(0);
        xmlC.setSecond(0);
        constraindateType.setValue(xmlC);
        timeConstrain.setDateFrom(constraindateType);
    }

    if (endTime() != -1) {
        ConstrainDateType constraindateType = new ConstrainDateType();
        XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(endYear(), endMonth() + 1, endDay());
        xmlC.setTimezone(zt_offset);//0);//-5*60);
        xmlC.setHour(0);
        xmlC.setMinute(0);
        xmlC.setSecond(0);
        constraindateType.setValue(xmlC);
        timeConstrain.setDateTo(constraindateType);
    }
    return timeConstrain;
}

From source file:net.servicefixture.converter.XMLGregorianCalendarConverter.java

private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) {
    XMLGregorianCalendar xmlCal;
    try {/*ww w. ja v a 2 s. c  om*/
        xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("Failed to create XMLGregorianCalendar", e);
    }

    xmlCal.setYear(calendar.get(Calendar.YEAR));
    xmlCal.setMonth(calendar.get(Calendar.MONTH) + 1);
    xmlCal.setDay(calendar.get(Calendar.DAY_OF_MONTH));
    xmlCal.setHour(calendar.get(Calendar.HOUR));
    xmlCal.setMinute(calendar.get(Calendar.MINUTE));
    xmlCal.setSecond(calendar.get(Calendar.SECOND));
    xmlCal.setMillisecond(calendar.get(Calendar.MILLISECOND));
    return xmlCal;
}

From source file:com.evolveum.midpoint.certification.impl.AccCertUpdateHelper.java

protected AccessCertificationStageType createStage(AccessCertificationCampaignType campaign,
        int requestedStageNumber) {
    AccessCertificationStageType stage = new AccessCertificationStageType(prismContext);
    stage.setNumber(requestedStageNumber);
    stage.setStart(XmlTypeConverter.createXMLGregorianCalendar(new Date()));

    AccessCertificationStageDefinitionType stageDef = CertCampaignTypeUtil.findStageDefinition(campaign,
            stage.getNumber());/* w  w  w  .  ja v a  2s  . c  o m*/
    XMLGregorianCalendar end = (XMLGregorianCalendar) stage.getStart().clone();
    if (stageDef.getDays() != null) {
        end.add(XmlTypeConverter.createDuration(true, 0, 0, stageDef.getDays(), 0, 0, 0));
    }
    end.setHour(23);
    end.setMinute(59);
    end.setSecond(59);
    end.setMillisecond(999);
    stage.setEnd(end);

    stage.setName(stageDef.getName());
    stage.setDescription(stageDef.getDescription());

    return stage;
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

private void jForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(previousQueries.size() - 1).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;//from w  w w .ja  v  a2  s .c o m
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, false, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }

        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

private void jBackwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    /*LoginHelper pms = new LoginHelper();
    try {//  w w w .  j av a  2s .c  o  m
       PasswordType ptype = new PasswordType();
       ptype.setIsToken(UserInfoBean.getInstance().getUserPasswordIsToken());
       ptype.setTokenMsTimeout(UserInfoBean.getInstance()
       .getUserPasswordTimeout());
       ptype.setValue(UserInfoBean.getInstance().getUserPassword());
       String response = pms.getUserInfo(UserInfoBean.getInstance().getUserName(), ptype, UserInfoBean.getInstance().getSelectedProjectUrl(), 
       UserInfoBean.getInstance().getUserDomain(), false, UserInfoBean.getInstance().getProjectId());
    }
    catch(Exception e) {
       e.printStackTrace();
    }*/

    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(0).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, true, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }

        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, true);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

@SuppressWarnings("rawtypes")
private void jForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    //String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(previousQueries.size() - 1).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;/*from  ww  w .  j  a  v  a  2s  .  c  o m*/
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, false, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());
            // System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId());
            // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }
        loadPatientSets();
        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

@SuppressWarnings("rawtypes")
private void jBackwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    /*LoginHelper pms = new LoginHelper();
    try {// w  w w  .  jav  a  2 s  . c  o m
       PasswordType ptype = new PasswordType();
       ptype.setIsToken(UserInfoBean.getInstance().getUserPasswordIsToken());
       ptype.setTokenMsTimeout(UserInfoBean.getInstance()
       .getUserPasswordTimeout());
       ptype.setValue(UserInfoBean.getInstance().getUserPassword());
       String response = pms.getUserInfo(UserInfoBean.getInstance().getUserName(), ptype, UserInfoBean.getInstance().getSelectedProjectUrl(), 
       UserInfoBean.getInstance().getUserDomain(), false, UserInfoBean.getInstance().getProjectId());
    }
    catch(Exception e) {
       e.printStackTrace();
    }*/

    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    //String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(0).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, true, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());
            // System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }
        loadPatientSets();
        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, true);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:org.openanzo.test.client.TestDateTime.java

/**
 * Test the conversion of javax.xml.datatype.XMLGregorianCalendar objects in the Anzo.java API into various XML Schema-types RDF literals. The test will add
 * statements using javax.xml.datatype.XMLGregorianCalendar objects and verify that when those statements are retrieved, the expected lexical value,
 * datatype, etc. are correct./*w w  w  .j av a2  s .  c o m*/
 * 
 * @throws Exception
 */
public void testXMLGregorianCalendarBecomesXsdTypedLiterals() throws Exception {

    AnzoClient client = null;
    try {
        client = new AnzoClient(getDefaultClientConfiguration());
        client.connect();
        client.reset(loadStatements("initialize.trig"), null);
        ClientGraph graph = client.getReplicaGraph(GRAPH_URI);

        DatatypeFactory df = DatatypeFactory.newInstance();

        // xsd:dateTime with time zone.
        // With time zone, a literal with a time zone is represented as a java.util.Calendar when it is retrieved even if the input is an XMLGregorianCalendar. 
        XMLGregorianCalendar cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357,
                9 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-11T16:48:32.357+09:00",
                XMLSchema.DATETIME);
        // Without time zone
        cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 12, 16, 48, 32, 357,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-12T16:48:32.357", XMLSchema.DATETIME);

        // xsd:date
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 12,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-12", XMLSchema.DATE);
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 11, -8 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-11-08:00", XMLSchema.DATE);

        // xsd:time
        // Without time zone
        cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "16:48:32.357", XMLSchema.TIME);
        // With time zone
        cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, 4 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "16:48:32.357+04:00", XMLSchema.TIME);

        // xsd:gYearMonth
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, DatatypeConstants.FIELD_UNDEFINED,
                -4 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-04:00", XMLSchema.GYEARMONTH);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.AUGUST, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-08", XMLSchema.GYEARMONTH);

        // xsd:gYear
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2009, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2009-06:00", XMLSchema.GYEAR);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2010, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2010", XMLSchema.GYEAR);

        // xsd:gMonthDay
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 15,
                -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--07-15-06:00", XMLSchema.GMONTHDAY);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 16,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--07-16", XMLSchema.GMONTHDAY);

        // xsd:gMonth
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.AUGUST,
                DatatypeConstants.FIELD_UNDEFINED, -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--08-06:00", XMLSchema.GMONTH);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.SEPTEMBER,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--09", XMLSchema.GMONTH);

        // xsd:gDay
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, 15, -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "---15-06:00", XMLSchema.GDAY);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, 16, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "---16", XMLSchema.GDAY);

        // Invalid XMLGregorianCalendar objects
        // Incomplete data. No XML Schema built-in type allows just an hour. We expect an exception.
        cal = df.newXMLGregorianCalendar();
        cal.setHour(13);
        try {
            Constants.valueFactory.createTypedLiteral(cal);
            fail("Should not get here since previous statement should throw exception.");
        } catch (AnzoRuntimeException e) {
            log.debug("Expected exception.");
        }

        // An XMLGregorianCalendar that has invalid data (February 31st) will go into the
        // system but will not be able to be parsed back into an XMLGregorianCalendar on retrieval.
        cal = df.newXMLGregorianCalendar();
        cal.setDay(31);
        cal.setMonth(DatatypeConstants.FEBRUARY);
        addAndRetrieveNativeLiteral(client, graph, cal, null, "--02-31", XMLSchema.GMONTHDAY);

    } finally {
        if (client != null) {
            client.close();
        }
    }
}

From source file:org.openvpms.esci.adapter.map.invoice.UBLInvoice.java

/**
 * Returns the invoice issue date/time.//from   w  ww . ja  v a2 s  . c  o  m
 *
 * @return the issue date/time
 * @throws ESCIAdapterException if the issue date isn't set
 */
public Date getIssueDatetime() {
    IssueDateType issueDate = getRequired(invoice.getIssueDate(), "IssueDate");
    XMLGregorianCalendar calendar = issueDate.getValue();
    checkRequired(calendar, "IssueDate");

    IssueTimeType issueTime = invoice.getIssueTime();
    if (issueTime != null) {
        XMLGregorianCalendar time = issueTime.getValue();
        if (time != null) {
            calendar.setHour(time.getHour());
            calendar.setMinute(time.getMinute());
            calendar.setSecond(time.getSecond());
            calendar.setMillisecond(time.getMillisecond());
        }
    }
    return calendar.toGregorianCalendar().getTime();
}