samples/composition/src-api2.0-runtime/org/apidesign/runtime/check/RuntimeCheck.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Feb 2009 17:30:06 +0100
changeset 321 06bf3a32eaa0
parent 155 c00f947c0936
permissions -rw-r--r--
Moving code to org.apidesign.math package
jtulach@155
     1
package org.apidesign.runtime.check;
jtulach@155
     2
jtulach@155
     3
import java.util.Map;
jtulach@155
     4
jtulach@155
     5
public final class RuntimeCheck {
jtulach@155
     6
    private RuntimeCheck() {
jtulach@155
     7
    }
jtulach@155
     8
    
jtulach@155
     9
    public static boolean requiresAtLeast(String minVersion, String apiName, ClassLoader caller) {
jtulach@155
    10
        if (caller instanceof AwareLoader) {
jtulach@155
    11
            String realVersion = ((AwareLoader)caller).requestedVersion(apiName);
jtulach@155
    12
            if (realVersion != null) {
jtulach@155
    13
                double minV = Double.parseDouble(minVersion);
jtulach@155
    14
                double realV = Double.parseDouble(realVersion);
jtulach@155
    15
                return minV <= realV;
jtulach@155
    16
            }
jtulach@155
    17
        }
jtulach@155
    18
        return false;
jtulach@155
    19
    }
jtulach@155
    20
    
jtulach@155
    21
    public static interface AwareLoader {
jtulach@155
    22
        public String requestedVersion(String apiName);
jtulach@155
    23
    }
jtulach@155
    24
    
jtulach@155
    25
    
jtulach@155
    26
    
jtulach@155
    27
    public static ClassLoader create(ClassLoader wrap, Map<String,String> requiredVersion) {
jtulach@155
    28
        return new VersionAwareClassLoader(wrap, requiredVersion);
jtulach@155
    29
    }
jtulach@155
    30
}