01: package com.jeta.swingbuilder.gui.utils;
02:
03: import java.security.AccessControlException;
04:
05: /**
06: * Utility class for determining which JRE version Abeille is running within.
07: *
08: * @author Todd Viegut
09: * @since Abeille 2.1 M1
10: * @version 1.0, 08.28.2007
11: */
12: public final class JREUtils {
13:
14: private JREUtils() {
15: }
16:
17: public static boolean isJava3OrLater() {
18: return validateJavaVersion(1.3D);
19: }
20:
21: public static boolean isJava4OrLater() {
22: return validateJavaVersion(1.3999999999999999D);
23: }
24:
25: public static boolean isJava4Release2OrLater() {
26: String javaVersion = getJavaVersion();
27: String majorVersion = javaVersion.substring(0, 5);
28: return majorVersion.compareTo("1.4.2") >= 0;
29: }
30:
31: public static boolean isJava5OrLater() {
32: return validateJavaVersion(1.5D);
33: }
34:
35: public static boolean isJava6OrLater() {
36: return validateJavaVersion(1.6000000000000001D);
37: }
38:
39: public static boolean isJava7OrLater() {
40: return validateJavaVersion(1.7D);
41: }
42:
43: public static String getProperty(String key, String defaultValue) {
44: try {
45: return System.getProperty(key);
46: } catch (AccessControlException ace) {
47: return defaultValue;
48: }
49: }
50:
51: public static String getJavaVersion() {
52: return getProperty("java.version", "1.4.2");
53: }
54:
55: private static boolean validateJavaVersion(double targetVersion) {
56: try {
57: String fullVersion = getJavaVersion();
58: String majorVersion = fullVersion.substring(0, 3);
59: double d = Double.parseDouble(majorVersion);
60: return d >= targetVersion;
61: } catch (NumberFormatException nfe) {
62: return false;
63: }
64: }
65: }
|