KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > foxtrot > JREVersion


1 /**
2  * Copyright (c) 2002-2005, Simone Bordet
3  * All rights reserved.
4  *
5  * This software is distributable under the BSD license.
6  * See the terms of the BSD license in the documentation provided with this software.
7  */

8
9 package foxtrot;
10
11 import java.security.AccessController JavaDoc;
12 import java.security.PrivilegedAction JavaDoc;
13
14 /**
15  * Helper class that returns which is the current JRE version
16  * @version $Revision: 1.4 $
17  */

18 class JREVersion
19 {
20    private static Boolean JavaDoc jre141;
21    private static Boolean JavaDoc jre140;
22    private static Boolean JavaDoc jre14;
23    private static Boolean JavaDoc jre13;
24    private static Boolean JavaDoc jre12;
25
26    /**
27     * @deprecated
28     */

29    static boolean isJRE141()
30    {
31       if (jre141 == null)
32       {
33          Class JavaDoc 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    /**
41     * @deprecated
42     */

43    static boolean isJRE140()
44    {
45       if (jre140 == null)
46       {
47          Class JavaDoc 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 JavaDoc loadClass(String JavaDoc className)
73    {
74       // Avoid some smart guy puts the classes in the classpath or in lib/ext.
75
// We ask directly to the boot classloader
76
try
77       {
78          return Class.forName(className, false, null);
79       }
80       catch (ClassNotFoundException JavaDoc ignored)
81       {
82       }
83       return null;
84    }
85
86    private static Boolean JavaDoc hasGetFirst(final Class JavaDoc cls)
87    {
88       return (Boolean JavaDoc)AccessController.doPrivileged(new PrivilegedAction JavaDoc()
89       {
90          public Object JavaDoc run()
91          {
92             try
93             {
94                cls.getDeclaredMethod("getFirst", null);
95                return Boolean.TRUE;
96             }
97             catch (Exception JavaDoc ignored)
98             {
99             }
100             return Boolean.FALSE;
101          }
102       });
103    }
104 }
105
Popular Tags