Example usage for javax.xml.datatype Duration getTimeInMillis

List of usage examples for javax.xml.datatype Duration getTimeInMillis

Introduction

In this page you can find the example usage for javax.xml.datatype Duration getTimeInMillis.

Prototype

public long getTimeInMillis(final Date startInstant) 

Source Link

Document

Returns the length of the duration in milli-seconds.

Usage

From source file:Main.java

public static long gDurationToLong(javax.xml.datatype.Duration duration) {
    return duration.getTimeInMillis(new Date(0));
}

From source file:Main.java

/**
 * @param duration the JAXP {@link Duration}
 * @return/*from  w ww .  j  a  v  a 2s .c  om*/
 */
public static long toMillis(final Duration duration) {
    return duration.getTimeInMillis(new Date(0));
}

From source file:Main.java

/**
 * Converts a lexical duration, as defined by XML Schema 1.0, into milliseconds.
 * //from  w ww .  j  ava  2  s.c o  m
 * @param duration lexical duration representation
 * 
 * @return duration in milliseconds
 */
public static long durationToLong(String duration) {
    Duration xmlDuration = getDataTypeFactory().newDuration(duration);
    return xmlDuration.getTimeInMillis(new GregorianCalendar());
}

From source file:edu.internet2.middleware.shibboleth.common.config.SpringConfigurationUtils.java

/**
 * Converts a duration, either expressed as numerical time or or ISO8601 duration. If a numerical form is used a
 * warning message indicating that the new IS08601 duration form should be used will be written to the logs.
 * //from  w  ww.  j av a2 s.co m
 * This method will be removed once the deprecated numerical duration form is no longer allowed.
 * 
 * @param propertyName Name of the property carrying the duration. This is used in the warning log message if the
 *            duration is in numerical form.
 * @param duration the duration to be parsed
 * @param toMillisFactor used to convert a numerical duration to milliseconds, 0 indicates no conversion
 * 
 * @return the duration in milliseconds
 * 
 * @throws IllegalArgumentException thrown if the given duration is either an invalid number or ISO8601 duration or
 *             if the duration is negative
 */
@Deprecated
public static long parseDurationToMillis(String propertyName, String duration, int toMillisFactor)
        throws IllegalArgumentException {
    if (duration.startsWith("-")) {
        throw new IllegalArgumentException("Negative durations are not supported");
    }

    long millis = 0;
    if (duration.startsWith("P")) {
        Duration xmlDuration = XMLHelper.getDataTypeFactory().newDuration(duration);
        millis = xmlDuration.getTimeInMillis(new Date());
    } else {
        try {
            millis = Long.parseLong(duration);
            if (millis < 0) {
                throw new IllegalArgumentException("Negative durations are not supported");
            }
            if (toMillisFactor > 0) {
                millis *= toMillisFactor;
            }
            Duration xmlDuration = XMLHelper.getDataTypeFactory().newDuration(millis);
            log.warn(
                    "Numerical duration form is deprecated. The property {} should use the duration notation: {}",
                    propertyName, xmlDuration.toString());
        } catch (NumberFormatException e) {

        }
    }

    return millis;
}

From source file:com.evolveum.midpoint.test.DummyAuditService.java

@Override
public void cleanupAudit(CleanupPolicyType policy, OperationResult parentResult) {
    Validate.notNull(policy, "Cleanup policy must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");

    if (policy.getMaxAge() == null) {
        return;/*from  w  ww.j a v  a  2s . c om*/
    }

    Duration duration = policy.getMaxAge();
    if (duration.getSign() > 0) {
        duration = duration.negate();
    }
    long minValue = duration.getTimeInMillis(new Date());

    Iterator<AuditEventRecord> iterator = records.iterator();
    while (iterator.hasNext()) {
        AuditEventRecord record = iterator.next();
        Long timestamp = record.getTimestamp();
        if (timestamp == null) {
            continue;
        }

        if (timestamp < minValue) {
            iterator.remove();
        }
    }
}

From source file:com.htm.taskinstance.jpa.TaskInstanceFactoryJPA.java

protected void evaluateDurationQueries(ITaskModel taskModel, ITaskInstance taskInstance) {

    log.debug("Evaluating duration queries");

    /* Duration Min */
    Duration min;
    try {//from   w  w  w . ja  v a2  s.c  o m
        min = evaluateXPath(Duration.class, taskModel.getDurationMin(), taskInstance);

        if (min != null) {
            taskInstance.setDurationMin(min.getTimeInMillis(Calendar.getInstance()));
        }

    } catch (IllegalArgumentException e) {
        // TODO default value from configuration
        log.error("Cannot evaluate min duration. Setting default value", e);
    }

    /* Duration Avg */
    try {
        Duration avg = evaluateXPath(Duration.class, taskModel.getDurationAvg(), taskInstance);
        if (avg != null) {
            taskInstance.setDurationAvg(avg.getTimeInMillis(Calendar.getInstance()));
        }
    } catch (IllegalArgumentException e) {
        // TODO default value from configuration
        log.error("Cannot evaluate avg duration. Setting default value", e);
    }

    /* Duration Max */
    try {
        Duration max = evaluateXPath(Duration.class, taskModel.getDurationMax(), taskInstance);
        if (max != null) {
            taskInstance.setDurationMax(max.getTimeInMillis(Calendar.getInstance()));
        }
    } catch (IllegalArgumentException e) {
        // TODO default value from configuration
        log.error("Cannot evaluate max duration. Setting default value", e);
    }
}

From source file:org.miloss.fgsms.common.Utility.java

/**
 * converts a duration to time in ms/*w w  w  .j a v  a2  s  . c  om*/
 *
 * @param d
 * @return
 */
public static long durationToTimeInMS(Duration d) {
    if (d == null) {
        throw new IllegalArgumentException("duration cannot be null");
    }

    return d.getTimeInMillis(new GregorianCalendar());
    /*        return ((long) d.getYears() * yrms)
       + (d.getMonths() * monms)
       + (d.getDays() * dayms)
       + (d.getHours() * hrms)
       + (d.getMinutes() * minms)
       + (d.getSeconds() * secms);*/
}

From source file:org.onebusaway.siri.core.SiriClientRequestFactory.java

/****
 * Private Methods//from   ww  w  .  j  a va  2  s.co  m
 ****/

private void processCommonArgs(Map<String, String> args, SiriClientRequest request) {

    String url = args.get(ARG_URL);
    if (url == null)
        throw new SiriMissingArgumentException(ARG_URL);
    request.setTargetUrl(url);

    String manageSubscriptionUrl = args.get(ARG_MANAGE_SUBSCRIPTION_URL);
    request.setManageSubscriptionUrl(manageSubscriptionUrl);

    String checkStatusUrl = args.get(ARG_CHECK_STATUS_URL);
    request.setCheckStatusUrl(checkStatusUrl);

    String versionId = args.get(ARG_VERSION);
    if (versionId != null) {
        ESiriVersion version = ESiriVersion.getVersionForVersionId(versionId);
        if (version == null) {
            throw new SiriUnknownVersionException(versionId);
        }
        request.setTargetVersion(version);
    } else {
        request.setTargetVersion(ESiriVersion.V1_3);
    }

    String subscribeValue = args.get(ARG_SUBSCRIBE);
    if (subscribeValue != null) {
        boolean subscribe = Boolean.parseBoolean(subscribeValue);
        request.setSubscribe(subscribe);
    }

    String pollIntervalValue = args.get(ARG_POLL_INTERVAL);
    if (pollIntervalValue != null) {
        int pollInterval = Integer.parseInt(pollIntervalValue);
        request.setPollInterval(pollInterval);
    }

    String initialTerminationTime = args.get(ARG_INITIAL_TERMINATION_TIME);
    if (initialTerminationTime != null) {
        if (initialTerminationTime.startsWith("P")) {
            Duration duration = _dataTypeFactory.newDuration(initialTerminationTime);
            request.setInitialTerminationDuration(duration.getTimeInMillis(new Date()));
        } else {
            try {
                Date time = getIso8601StringAsTime(initialTerminationTime, TimeZone.getDefault());
                request.setInitialTerminationDuration(time.getTime() - System.currentTimeMillis());
            } catch (ParseException e) {
                throw new SiriException("error parsing initial termination time (ISO 8601)");
            }
        }
    } else {
        /**
         * By default, expire in 24 hours
         */
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_YEAR, 1);
        request.setInitialTerminationDuration(c.getTimeInMillis() - System.currentTimeMillis());
    }

    String reconnectionAttempts = args.get(ARG_RECONNECTION_ATTEMPTS);
    if (reconnectionAttempts != null) {
        int attempts = Integer.parseInt(reconnectionAttempts);
        request.setReconnectionAttempts(attempts);
    }

    String reconnectionInterval = args.get(ARG_RECONNECTION_INTERVAL);
    if (reconnectionInterval != null) {
        int interval = Integer.parseInt(reconnectionInterval);
        request.setReconnectionInterval(interval);
    }

    String checkStatusIntervalValue = args.get(ARG_CHECK_STATUS_INTERVAL);
    if (checkStatusIntervalValue != null) {
        int checkStatusInterval = Integer.parseInt(checkStatusIntervalValue);
        request.setCheckStatusInterval(checkStatusInterval);
    }

    String heartbeatIntervalValue = args.get(ARG_HEARTBEAT_INTERVAL);
    if (heartbeatIntervalValue != null) {
        int heartbeatInterval = Integer.parseInt(heartbeatIntervalValue);
        request.setHeartbeatInterval(heartbeatInterval);
    }
}

From source file:org.yawlfoundation.yawl.util.StringUtil.java

public static long durationToMSecs(Duration d, long def) {
    return (d != null) ? d.getTimeInMillis(new Date()) : def;
}