Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateTimeInstance.

Prototype

public static final DateFormat getDateTimeInstance() 

Source Link

Document

Gets the date/time formatter with the default formatting style for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:de.d3web.we.ci4ke.build.CIRenderer.java

private void apppendBuildHeadline(BuildResult build, RenderResult buffy) {
    DateFormat dateFormat = DateFormat.getDateTimeInstance();
    String buildDate = dateFormat.format(build.getBuildDate());
    buffy.appendHtml("<div class='ci-name'>Build #").append(build.getBuildNumber()).append(" (")
            .append(buildDate).append(") ");

    // get the build duration time
    buffy.append(" in ");
    long duration = build.getBuildDuration();
    if (duration < 1000) {
        buffy.append(duration + " msec.");
    } else if (duration >= 1000 && duration < 60000) {
        buffy.append((duration / 1000) + " sec.");
    } else {//  www  .j  a v a 2s .  com
        long sec = duration / 1000;
        buffy.append(String.format("%d:%02d min.", sec / 60, sec % 60));
    }

    buffy.appendHtml("</div>");
}

From source file:at.alladin.rmbt.android.about.RMBTAboutFragment.java

/**
 * //from w  w  w  .j a va2 s  . c om
 * @param context
 * @return
 */
private String getAppInfo(final Context context) {
    PackageInfo pInfo;
    try {

        String date = "";
        try {
            final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                    0);
            final ZipFile zf = new ZipFile(ai.sourceDir);
            final ZipEntry ze = zf.getEntry("classes.dex");
            zf.close();
            final long time = ze.getTime();
            date = DateFormat.getDateTimeInstance().format(new java.util.Date(time));

        } catch (final Exception e) {// not much we can do
        }

        pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        clientVersion = pInfo.versionName + " (" + pInfo.versionCode + ")\n("
                + RevisionHelper.getVerboseRevision() + ")\n(" + date + ")";
        clientName = context.getResources().getString(R.string.app_name);
    } catch (final Exception e) {
        // e1.printStackTrace();
        Log.e(DEBUG_TAG, "version of the application cannot be found", e);
    }

    return clientVersion;
}

From source file:org.adl.samplerte.server.CourseService.java

/**
 * This method is used to update SCOData object and its associated comments.
 * <br>//from   w ww  .  j  av a  2s.co m
 * 
 * @param iActivityID -
 *           The unique identifier (internal to the Sample RTE) used to
 *           identify a single SCO in the Sample RTE.
 * @param iComments -
 *           A '[.]' delimited list of comments_from_lms Strings to be used
 *           to initialize the SCO when it is launched
 * @param iUpdate - 
 *          String representation of whether this is an update (true or false)
 * @param iLocations - 
 *          The locations
 * @return String - indicates whether the update was successful
 */
public String updateSCO(int iActivityID, String iComments, String iUpdate, String iLocations) {
    String result = "true";

    // Get all of the course information out of the database
    Connection conn = LMSDatabaseHandler.getConnection();

    PreparedStatement stmtDeleteComment;
    PreparedStatement stmtSetComment;

    String sqlSetComment = "INSERT INTO SCOComments(ActivityID, Comment,  "
            + "CommentDateTime, CommentLocation) VALUES(?,?,?,?)";

    String sqlDeleteComment = "DELETE FROM SCOComments WHERE ActivityID " + "= ?";

    Vector comments = new Vector();
    comments = getCommentVector(iComments);

    Vector locations = new Vector();
    locations = getCommentVector(iLocations);

    try {
        stmtSetComment = conn.prepareStatement(sqlSetComment);

        if (iUpdate.equals("false")) {
            // Clean out old comments then insert the new
            stmtDeleteComment = conn.prepareStatement(sqlDeleteComment);

            synchronized (stmtDeleteComment) {
                stmtDeleteComment.setInt(1, iActivityID);
                stmtDeleteComment.executeUpdate();
            }

            stmtDeleteComment.close();
        }

        DateFormat date = DateFormat.getDateTimeInstance();

        if (iComments != null && (!iComments.equals(""))) {

            for (int i = 0; i < comments.size(); i++) {
                if (locations.elementAt(i).equals("")) {
                    synchronized (stmtSetComment) {
                        stmtSetComment.setInt(1, iActivityID);
                        stmtSetComment.setString(2, (String) comments.elementAt(i));
                        stmtSetComment.setString(3, date.format(new Date()));
                        stmtSetComment.executeUpdate();
                    }
                } else {
                    synchronized (stmtSetComment) {
                        stmtSetComment.setInt(1, iActivityID);
                        stmtSetComment.setString(2, (String) comments.elementAt(i));
                        stmtSetComment.setString(3, date.format(new Date()));
                        stmtSetComment.setString(4, (String) locations.elementAt(i));
                        stmtSetComment.executeUpdate();
                    }
                }
            }

            stmtSetComment.close();
        }

        conn.close();
    } catch (Exception e) {
        result = "false";
        e.printStackTrace();
    }

    return result;
}

From source file:org.opendatakit.briefcase.util.ExportToCsv.java

private boolean emitSubmissionCsv(OutputStreamWriter osw, EncryptionInformation ei, Element submissionElement,
        TreeElement primarySet, TreeElement treeElement, boolean first, String uniquePath, File instanceDir)
        throws IOException {
    // OK -- group with at least one element -- assume no value...
    // TreeElement list has the begin and end tags for the nested groups.
    // Swallow the end tag by looking to see if the prior and current
    // field names are the same.
    TreeElement prior = null;//www.  j  av a  2  s.  co  m
    for (int i = 0; i < treeElement.getNumChildren(); ++i) {
        TreeElement current = (TreeElement) treeElement.getChildAt(i);
        log.fine(" element name: " + current.getName());
        if ((prior != null) && (prior.getName().equals(current.getName()))) {
            // it is the end-group tag... seems to happen with two adjacent repeat
            // groups
            log.info("repeating tag at " + i + " skipping " + current.getName());
            prior = current;
        } else {
            Element ec = findElement(submissionElement, current.getName());
            switch (current.getDataType()) {
            case org.javarosa.core.model.Constants.DATATYPE_TEXT:/**
                                                                 * Text question
                                                                 * type.
                                                                 */
            case org.javarosa.core.model.Constants.DATATYPE_INTEGER:/**
                                                                    * Numeric
                                                                    * question type. These are numbers without decimal points
                                                                    */
            case org.javarosa.core.model.Constants.DATATYPE_DECIMAL:/**
                                                                    * Decimal
                                                                    * question type. These are numbers with decimals
                                                                    */
            case org.javarosa.core.model.Constants.DATATYPE_CHOICE:/**
                                                                   * This is a
                                                                   * question with alist of options where not more than one option can
                                                                   * be selected at a time.
                                                                   */
            case org.javarosa.core.model.Constants.DATATYPE_CHOICE_LIST:/**
                                                                        * This is a
                                                                        * question with alist of options where more than one option can be
                                                                        * selected at a time.
                                                                        */
            case org.javarosa.core.model.Constants.DATATYPE_BOOLEAN:/**
                                                                    * Question with
                                                                    * true and false answers.
                                                                    */
            case org.javarosa.core.model.Constants.DATATYPE_BARCODE:/**
                                                                    * Question with
                                                                    * barcode string answer.
                                                                    */
            default:
            case org.javarosa.core.model.Constants.DATATYPE_UNSUPPORTED:
                if (ec == null) {
                    emitString(osw, first, null);
                } else {
                    emitString(osw, first, getSubmissionValue(ei, current, ec));
                }
                first = false;
                break;
            case org.javarosa.core.model.Constants.DATATYPE_DATE:
                /**
                 * Date question type. This has only date component without time.
                 */
                if (ec == null) {
                    emitString(osw, first, null);
                } else {
                    String value = getSubmissionValue(ei, current, ec);
                    if (value == null || value.length() == 0) {
                        emitString(osw, first, null);
                    } else {
                        Date date = WebUtils.parseDate(value);
                        DateFormat formatter = DateFormat.getDateInstance();
                        emitString(osw, first, formatter.format(date));
                    }
                }
                first = false;
                break;
            case org.javarosa.core.model.Constants.DATATYPE_TIME:
                /**
                 * Time question type. This has only time element without date
                 */
                if (ec == null) {
                    emitString(osw, first, null);
                } else {
                    String value = getSubmissionValue(ei, current, ec);
                    if (value == null || value.length() == 0) {
                        emitString(osw, first, null);
                    } else {
                        Date date = WebUtils.parseDate(value);
                        DateFormat formatter = DateFormat.getTimeInstance();
                        emitString(osw, first, formatter.format(date));
                    }
                }
                first = false;
                break;
            case org.javarosa.core.model.Constants.DATATYPE_DATE_TIME:
                /**
                 * Date and Time question type. This has both the date and time
                 * components
                 */
                if (ec == null) {
                    emitString(osw, first, null);
                } else {
                    String value = getSubmissionValue(ei, current, ec);
                    if (value == null || value.length() == 0) {
                        emitString(osw, first, null);
                    } else {
                        Date date = WebUtils.parseDate(value);
                        DateFormat formatter = DateFormat.getDateTimeInstance();
                        emitString(osw, first, formatter.format(date));
                    }
                }
                first = false;
                break;
            case org.javarosa.core.model.Constants.DATATYPE_GEOPOINT:
                /**
                 * Question with location answer.
                 */
                String compositeValue = (ec == null) ? null : getSubmissionValue(ei, current, ec);
                compositeValue = (compositeValue == null) ? null : compositeValue.trim();

                // emit separate lat, long, alt, acc columns...
                if (compositeValue == null || compositeValue.length() == 0) {
                    for (int count = 0; count < 4; ++count) {
                        emitString(osw, first, null);
                        first = false;
                    }
                } else {
                    String[] values = compositeValue.split(" ");
                    for (String value : values) {
                        emitString(osw, first, value);
                        first = false;
                    }
                    for (int count = values.length; count < 4; ++count) {
                        emitString(osw, first, null);
                        first = false;
                    }
                }
                break;
            case org.javarosa.core.model.Constants.DATATYPE_BINARY:
                /**
                 * Question with external binary answer.
                 */
                String binaryFilename = getSubmissionValue(ei, current, ec);
                if (binaryFilename == null || binaryFilename.length() == 0) {
                    emitString(osw, first, null);
                    first = false;
                } else {
                    if (exportMedia) {
                        int dotIndex = binaryFilename.lastIndexOf(".");
                        String namePart = (dotIndex == -1) ? binaryFilename
                                : binaryFilename.substring(0, dotIndex);
                        String extPart = (dotIndex == -1) ? "" : binaryFilename.substring(dotIndex);

                        File binaryFile = new File(instanceDir, binaryFilename);
                        String destBinaryFilename = binaryFilename;
                        int version = 1;
                        File destFile = new File(outputMediaDir, destBinaryFilename);
                        while (destFile.exists()) {
                            destBinaryFilename = namePart + "-" + (++version) + extPart;
                            destFile = new File(outputMediaDir, destBinaryFilename);
                        }
                        if (binaryFile.exists()) {
                            FileUtils.copyFile(binaryFile, destFile);
                        }
                        emitString(osw, first, MEDIA_DIR + File.separator + destFile.getName());
                    } else {
                        emitString(osw, first, binaryFilename);
                    }

                    first = false;
                }
                break;
            case org.javarosa.core.model.Constants.DATATYPE_NULL: /*
                                                                   * for nodes that
                                                                   * have no data,
                                                                   * or data type
                                                                   * otherwise
                                                                   * unknown
                                                                   */
                if (current.isRepeatable()) {
                    if (prior == null || !current.getName().equals(prior.getName())) {
                        // repeatable group...
                        if (ec == null) {
                            emitString(osw, first, null);
                            first = false;
                        } else {
                            String uniqueGroupPath = uniquePath + "/" + getFullName(current, primarySet);
                            emitString(osw, first, uniqueGroupPath);
                            first = false;
                            // first time processing this repeat group (ignore templates)
                            List<Element> ecl = findElementList(submissionElement, current.getName());
                            emitRepeatingGroupCsv(ei, ecl, current, uniquePath, uniqueGroupPath, instanceDir);
                        }
                    }
                } else if (current.getNumChildren() == 0 && current != briefcaseLfd.getSubmissionElement()) {
                    // assume fields that don't have children are string fields.
                    if (ec == null) {
                        emitString(osw, first, null);
                        first = false;
                    } else {
                        emitString(osw, first, getSubmissionValue(ei, current, ec));
                        first = false;
                    }
                } else {
                    /* one or more children -- this is a non-repeating group */
                    first = emitSubmissionCsv(osw, ei, ec, primarySet, current, first, uniquePath, instanceDir);
                }
                break;
            }
            prior = current;
        }
    }
    return first;
}

From source file:org.dawnsci.commandserver.ui.view.StatusQueueView.java

private void rerun(StatusBean bean) {

    try {/*from   w  ww . j av  a  2 s .c  o  m*/

        final DateFormat format = DateFormat.getDateTimeInstance();
        boolean ok = MessageDialog.openQuestion(getViewSite().getShell(),
                "Confirm resubmission " + bean.getName(), "Are you sure you want to rerun " + bean.getName()
                        + " submitted on " + format.format(new Date(bean.getSubmissionTime())) + "?");

        if (!ok)
            return;

        final StatusBean copy = bean.getClass().newInstance();
        copy.merge(bean);
        copy.setMessage("Rerun of " + bean.getName());

        IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE,
                "org.dawnsci.commandserver.ui");
        final URI uri = new URI(store.getString("org.dawnsci.commandserver.URI"));

        final RemoteSubmission factory = new RemoteSubmission(uri);
        factory.setQueueName(getSubmissionQueueName());

        factory.submit(copy, true);

        reconnect();

    } catch (Exception e) {
        ErrorDialog.openError(getViewSite().getShell(), "Cannot rerun " + bean.getName(),
                "Cannot rerun " + bean.getName() + "\n\nPlease contact your support representative.",
                new Status(IStatus.ERROR, "org.dawnsci.commandserver.ui", e.getMessage()));
    }

}

From source file:com.evolveum.midpoint.wf.impl.jobs.JobController.java

private String prepareValueForWfStatusProperty(String stateDescription) {
    // statusTsDt (for wfStatus): [<timestamp>: <formatted datetime>] <status description>
    // (timestamp is to enable easy sorting, [] to easy parsing)

    Date d = new Date();
    DateFormat df = DateFormat.getDateTimeInstance();
    return "[" + d.getTime() + ": " + df.format(d) + "] " + stateDescription;
}

From source file:org.opennms.features.newts.converter.eventd.EventdStresser.java

public static SnmpTrapBuilder createBuilder() throws IllegalArgumentException {

    SnmpV1TrapBuilder builder = SnmpUtils.getV1TrapBuilder();

    builder.setAgentAddress(m_agentAddress);

    SnmpObjId enterpriseOid = SnmpObjId.get(".1.3.6.1.4.1.5813.1");
    builder.setEnterprise(enterpriseOid);
    builder.setTimeStamp(0);/*  www .  java2 s  .  c o m*/

    builder.setGeneric(6);
    builder.setSpecific(1);
    builder.setTimeStamp(1);

    // dbid
    SnmpObjId dbIdOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.1");
    SnmpValue dbIdValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("-1".getBytes());
    builder.addVarBind(dbIdOid, dbIdValue);

    // distPoller
    SnmpObjId distPollerOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.2");
    SnmpValue distPollerValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(distPollerOid, distPollerValue);

    // create-time
    SnmpObjId createTimeOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.3");
    Date createTime = Calendar.getInstance().getTime();
    String formattedTime = DateFormat.getDateTimeInstance().format(createTime);
    SnmpValue createTimeValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString(formattedTime.getBytes());
    builder.addVarBind(createTimeOid, createTimeValue);

    // master-station
    SnmpObjId masterStationOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.4");
    SnmpValue masterStationValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString(m_trapSink.getHostAddress().getBytes());
    builder.addVarBind(masterStationOid, masterStationValue);

    // uei
    SnmpObjId ueiOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.5");
    SnmpValue ueiValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString("uei.opennms.org/test/EventdStressTest".getBytes());
    builder.addVarBind(ueiOid, ueiValue);

    // source,
    SnmpObjId sourceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.6");
    SnmpValue sourceValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString("EventdStresser".getBytes());
    builder.addVarBind(sourceOid, sourceValue);

    // nodeid,
    SnmpObjId nodeIdOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.7");
    SnmpValue nodeIdValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("1".getBytes());
    builder.addVarBind(nodeIdOid, nodeIdValue);

    // time,
    SnmpObjId timeOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.8");
    SnmpValue timeValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(formattedTime.getBytes());
    builder.addVarBind(timeOid, timeValue);

    // host,
    SnmpObjId hostOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.9");
    SnmpValue hostValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(hostOid, hostValue);

    // interface,
    SnmpObjId interfaceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.10");
    SnmpValue interfaceValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(interfaceOid, interfaceValue);

    // snmphost,
    SnmpObjId snmpHostOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.11");
    SnmpValue snmpValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(snmpHostOid, snmpValue);

    // service,
    SnmpObjId serviceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.12");
    SnmpValue serviceValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("SNMP".getBytes());
    builder.addVarBind(serviceOid, serviceValue);

    // descr,
    SnmpObjId descrOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.13");
    SnmpValue descrValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString("Eventd Stressor Trap".getBytes());
    builder.addVarBind(descrOid, descrValue);

    // logmsg,
    SnmpObjId logMsgOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.14");
    SnmpValue logMsgValue = SnmpUtils.getStrategy().getValueFactory()
            .getOctetString("Eventd Stressor Trap".getBytes());
    builder.addVarBind(logMsgOid, logMsgValue);

    // severity,
    SnmpObjId severityOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.15");
    SnmpValue severityValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("4".getBytes());
    builder.addVarBind(severityOid, severityValue);

    // pathoutage,
    SnmpObjId pathOutageOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.16");
    SnmpValue pathOutageValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("NA".getBytes());
    builder.addVarBind(pathOutageOid, pathOutageValue);

    // operinst,
    SnmpObjId operInstOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.17");
    SnmpValue operInstValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("Ignore".getBytes());
    builder.addVarBind(operInstOid, operInstValue);

    // ifresolve,
    SnmpObjId ifResolveOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.18");
    SnmpValue ifResolveValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("NA".getBytes());
    builder.addVarBind(ifResolveOid, ifResolveValue);

    // nodelabel
    SnmpObjId nodeLabelOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.19");
    String nodeLabel;
    nodeLabel = m_agentAddress.getCanonicalHostName();
    SnmpValue nodeLabelValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(nodeLabel.getBytes());
    builder.addVarBind(nodeLabelOid, nodeLabelValue);

    return builder;
}

From source file:com.mbientlab.metawear.app.CustomFragment.java

public String writeFile() {
    String csvData;/* w w w. j  a va2s. com*/
    int count = 0;
    csvData = "linear_x,linear_y,linear_z,heading,pitch,roll,yaw,timestamp\n";
    for (String data[] : dataSet) {
        csvData = csvData + data[0] + "," + data[1] + "," + data[2] + "," + data[3] + "," + data[4] + ","
                + data[5] + "," + data[6] + "," + data[7] + "\n";
        count++;
    }
    showLog(csvData);
    String filename = DateFormat.getDateTimeInstance().format(new Date()) + ".csv";
    writeToFile(csvData, filename);
    resetData(true);
    return count + "_" + filename;

}

From source file:org.globus.workspace.scheduler.defaults.DefaultSchedulerAdapter.java

public void stateNotification(int id, int state, Calendar start, Calendar stop, String hostname)
        throws ManageException {

    if (id < 0) {
        logger.fatal("invalid id: " + id);
        return;/*from ww w. j  a  va2 s  . c o  m*/
    }

    if (lager.traceLog) {
        String msg = "stateNotification(): " + Lager.id(id) + ", state = " + this.dataConvert.stateName(state)
                + ", stop = ";
        if (stop != null) {
            DateFormat localFormat = DateFormat.getDateTimeInstance();
            msg += "'" + localFormat.format(stop.getTime()) + "'";
        } else {
            msg += "null";
        }
        logger.trace(msg);
    }

    if (state == WorkspaceConstants.STATE_DESTROYING || state == WorkspaceConstants.STATE_DESTROY_FAILED) {
        return; // not ready yet
    }

    if (state == WorkspaceConstants.STATE_DESTROY_SUCCEEDED) {
        removeScheduling(id);
        notifySiManager(id, state);
        return;
    }

    // This simple scheduler implementation only decides what to do at
    // creation and when to shutdown (with lockdown of web services start
    // and shutdown operations).

    InstanceResource resource = null;

    // In the case of a slot obtained in a delayed manner (e.g. using
    // the workspace-pilot and/or coscheduled), we cannot act on
    // STATE_FIRST_LEGAL unless this.slotReserved is called (where
    // stop is !null).
    // In the future, stop time should not be overloaded like this, make
    // a more explicit parameter.

    boolean noActivateSituation = false;
    boolean populateAndSchedule = false;

    if (state == WorkspaceConstants.STATE_FIRST_LEGAL) {

        if (this.slotManager.isBestEffort() && stop == null) {

            noActivateSituation = true;

        } else if (this.slotManager.isBestEffort()) {

            populateAndSchedule = true;

        } else {

            resource = this.fetchResource(id, state);
            if (resource == null) {
                return;
            }

            if (resource.getEnsembleId() != null) {
                if (stop == null) {
                    noActivateSituation = true;
                } else {
                    populateAndSchedule = true;
                }
            }
        }

    }

    if (state == WorkspaceConstants.STATE_FIRST_LEGAL) {
        this.creationPending.notpending(id);
        if (noActivateSituation) {
            return;
        }
    }

    // Since it is immediate, nothing needs to be decided.
    if (state == WorkspaceConstants.STATE_FIRST_LEGAL) {

        if (resource == null) {
            resource = this.fetchResource(id, state);
            if (resource == null) {
                return;
            }
        }

        if (populateAndSchedule) {

            // note that in the pilot case running time duration currently
            // equals requested running time, leaving no time for
            // unpropagation (need B scheduler), client will need to call
            // shutdown + ready-for-transport to get unpropagation
            this.db.scheduleTasks(id, stop);

            if (hostname == null) {
                logger.error(
                        Lager.id(id) + "scheduler received " + "slot-reserved notification without a hostname");
                return;
            } else {
                resource.newHostname(hostname);
            }

            if (start == null) {
                logger.error(Lager.id(id) + "scheduler received "
                        + "slot-reserved notification without a start time");
                return;
            } else {
                resource.newStartTime(start);
            }

            if (stop == null) {
                // this is actually impossible to reach, leaving in
                // for future developers
                logger.error(Lager.id(id) + "scheduler received "
                        + "slot-reserved notification without a stop time");
                return;
            } else {
                resource.newStopTime(stop);
            }
        }

        resource.setOpsEnabled(true);
        try {
            resource.activate();
            this.sweeper.scheduleSweeper();
        } catch (ManageException e) {
            logger.error("", e);
        }
    }

    /* Once transport-readying is hit for any reason, no turning back */
    else if (state == WorkspaceConstants.STATE_READYING_FOR_TRANSPORT) {
        try {
            resource = this.home.find(id);
        } catch (DoesNotExistException e) {
            logger.error("scheduler received state notification (" + this.dataConvert.stateName(state)
                    + ") about " + Lager.id(id) + ", but it seems to be gone now", e);
            return;
        }

        // find will not return null
        resource.setOpsEnabled(false);
        try {
            this.db.markShutdown(id);
        } catch (WorkspaceDatabaseException e) {
            logger.error("", e);
        }
    }
}

From source file:org.lockss.tdb.TdbXml.java

/**
  * <p>//  w w w.ja  va  2  s  .  c o m
  * Outputs the XML preamble to a given output channel.
  * </p>
  *
  * @param options
  *          The options map.
  * @param out
  *          The output channel.
  * @since 1.67
  */
public void preamble(Map<String, Object> options, PrintStream out) {
    StringBuilder sb = new StringBuilder(2048);
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    sb.append("<!DOCTYPE lockss-config [\n");
    sb.append("<!ELEMENT lockss-config (if|property)*>\n");
    sb.append("<!ELEMENT property (property|list|value|if)*>\n");
    sb.append("<!ELEMENT list (value)+>\n");
    sb.append("<!ELEMENT value (#PCDATA)>\n");
    sb.append("<!ELEMENT test EMPTY>\n");
    sb.append("<!ELEMENT and (and|or|not|test)*>\n");
    sb.append("<!ELEMENT or (and|or|not|test)*>\n");
    sb.append("<!ELEMENT not (and|or|not|test)*>\n");
    sb.append("<!ELEMENT if (and|or|not|then|else|test|property)*>\n");
    sb.append("<!ELEMENT then (if|property)*>\n");
    sb.append("<!ELEMENT else (if|property)*>\n");
    sb.append("<!ATTLIST property name CDATA #REQUIRED>\n");
    sb.append("<!ATTLIST property value CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test hostname CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test group CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test daemonVersionMin CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test daemonVersionMax CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test daemonVersion CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test platformVersionMin CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test platformVersionMax CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test platformVersion CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST test platformName CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if hostname CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if group CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if daemonVersionMin CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if daemonVersionMax CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if daemonVersion CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if platformVersionMin CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if platformVersionMax CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if platformVersion CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST if platformName CDATA #IMPLIED>\n");
    sb.append("<!ATTLIST list append CDATA #IMPLIED>\n");
    sb.append("]>\n");
    sb.append("\n");
    if (options.get(KEY_NO_TIMESTAMP) == Boolean.FALSE) {
        sb.append("<!-- ");
        sb.append(DateFormat.getDateTimeInstance().format(new Date()));
        sb.append(" -->\n");
        sb.append("\n");
    }
    sb.append("<lockss-config>\n");
    out.println(sb.toString());
}