Example usage for com.google.gwt.core.ext CachedGeneratorResult getTimeGenerated

List of usage examples for com.google.gwt.core.ext CachedGeneratorResult getTimeGenerated

Introduction

In this page you can find the example usage for com.google.gwt.core.ext CachedGeneratorResult getTimeGenerated.

Prototype

long getTimeGenerated();

Source Link

Document

Returns the time this generator result was created.

Usage

From source file:net.sf.mmm.util.gwt.base.rebind.AbstractIncrementalGenerator.java

License:Apache License

/**
 * This method determines whether a {@link CachedGeneratorResult} is obsolete or can be reused.
 * /*from   w  w  w . ja  v a  2s.  com*/
 * @param cachedGeneratorResult is the {@link CachedGeneratorResult}.
 * @param typeName is the full-qualified name of the {@link Class} to generate.
 * @return <code>true</code> if the {@link CachedGeneratorResult} is obsolete and has to be re-generated,
 *         <code>false</code> otherwise (if it can be reused).
 */
protected boolean isCachedResultObsolete(CachedGeneratorResult cachedGeneratorResult, String typeName) {

    try {
        URL javaFileUrl = Thread.currentThread().getContextClassLoader()
                .getResource(typeName.replace('.', '/') + ".java");
        String protocol = javaFileUrl.getProtocol().toLowerCase();
        if ("file".equals(protocol)) {
            String urlString = URLDecoder.decode(javaFileUrl.getFile(), "UTF-8");
            File javaFile = new File(urlString);
            long lastModified = javaFile.lastModified();
            long timeGenerated = cachedGeneratorResult.getTimeGenerated();
            return (lastModified > timeGenerated);
        } else {
            throw new IllegalCaseException(protocol);
        }
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.cruxframework.crux.core.rebind.AbstractProxyCreator.java

License:Apache License

protected boolean findCacheableImplementationAndMarkForReuseIfAvailable(JClassType baseIntf) {
    CachedGeneratorResult lastResult = context.getCachedGeneratorResult();
    if (lastResult == null || !context.isGeneratorResultCachingEnabled()) {
        return false;
    }/*from   ww w . j  a v  a2  s  .c o m*/

    String proxyName = getProxyQualifiedName();

    // check that it is available for reuse
    if (!lastResult.isTypeCached(proxyName)) {
        return false;
    }

    try {
        long lastModified = 0L;
        if (baseIntf instanceof JRealClassType) {
            lastModified = ((JRealClassType) baseIntf).getLastModifiedTime();
        }

        if (lastModified != 0L && lastModified < lastResult.getTimeGenerated()) {
            return context.tryReuseTypeFromCache(proxyName);
        }
    } catch (RuntimeException ex) {
        // could get an exception checking modified time
        return false;
    }

    return false;
}