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
     1 package org.apidesign.runtime.check;
     2 
     3 import java.util.Map;
     4 
     5 public final class RuntimeCheck {
     6     private RuntimeCheck() {
     7     }
     8     
     9     public static boolean requiresAtLeast(String minVersion, String apiName, ClassLoader caller) {
    10         if (caller instanceof AwareLoader) {
    11             String realVersion = ((AwareLoader)caller).requestedVersion(apiName);
    12             if (realVersion != null) {
    13                 double minV = Double.parseDouble(minVersion);
    14                 double realV = Double.parseDouble(realVersion);
    15                 return minV <= realV;
    16             }
    17         }
    18         return false;
    19     }
    20     
    21     public static interface AwareLoader {
    22         public String requestedVersion(String apiName);
    23     }
    24     
    25     
    26     
    27     public static ClassLoader create(ClassLoader wrap, Map<String,String> requiredVersion) {
    28         return new VersionAwareClassLoader(wrap, requiredVersion);
    29     }
    30 }