1 8 9 package foxtrot; 10 11 import java.security.AccessController ; 12 import java.security.PrivilegedAction ; 13 14 18 class JREVersion 19 { 20 private static Boolean jre141; 21 private static Boolean jre140; 22 private static Boolean jre14; 23 private static Boolean jre13; 24 private static Boolean jre12; 25 26 29 static boolean isJRE141() 30 { 31 if (jre141 == null) 32 { 33 Class cls = loadClass("java.awt.SequencedEvent"); 34 if (cls == null) jre141 = Boolean.FALSE; 35 else jre141 = hasGetFirst(cls); 36 } 37 return jre141.booleanValue(); 38 } 39 40 43 static boolean isJRE140() 44 { 45 if (jre140 == null) 46 { 47 Class cls = loadClass("java.awt.SequencedEvent"); 48 if (cls == null) jre140 = Boolean.FALSE; 49 else jre140 = hasGetFirst(cls).booleanValue() ? Boolean.FALSE : Boolean.TRUE; 50 } 51 return jre140.booleanValue(); 52 } 53 54 static boolean isJRE14() 55 { 56 if (jre14 == null) jre14 = loadClass("java.util.logging.Logger") == null ? Boolean.FALSE : Boolean.TRUE; 57 return jre14.booleanValue(); 58 } 59 60 static boolean isJRE13() 61 { 62 if (jre13 == null) jre13 = loadClass("java.lang.reflect.Proxy") == null ? Boolean.FALSE : Boolean.TRUE; 63 return jre13.booleanValue(); 64 } 65 66 static boolean isJRE12() 67 { 68 if (jre12 == null) jre12 = loadClass("java.util.Collection") == null ? Boolean.FALSE : Boolean.TRUE; 69 return jre12.booleanValue(); 70 } 71 72 private static Class loadClass(String className) 73 { 74 try 77 { 78 return Class.forName(className, false, null); 79 } 80 catch (ClassNotFoundException ignored) 81 { 82 } 83 return null; 84 } 85 86 private static Boolean hasGetFirst(final Class cls) 87 { 88 return (Boolean )AccessController.doPrivileged(new PrivilegedAction () 89 { 90 public Object run() 91 { 92 try 93 { 94 cls.getDeclaredMethod("getFirst", null); 95 return Boolean.TRUE; 96 } 97 catch (Exception ignored) 98 { 99 } 100 return Boolean.FALSE; 101 } 102 }); 103 } 104 } 105 | Popular Tags |