1/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2 *
3 * This program and the accompanying materials are made available under
4 * the terms of the Common Public License v1.0 which accompanies this distribution,
5 * and is available at http://www.eclipse.org/legal/cpl-v10.html
6 *
7 * $Id: IJREVersion.java,v 1.1.1.1.2.1 2004/07/10 03:34:52 vlad_r Exp $
8 */
9package com.vladium.util;
10
11// ----------------------------------------------------------------------------
12/**
13 * A constant collection to detect the current JRE version. Note that this code
14 * is more sophisticated then a mere check of "java.version" or "java.class.version"
15 * and similar system properties because some JVMs allow overriding those
16 * by the user (e.g., from the command line). This implementation relies on
17 * the core classes only and tries to minimize the number of security-sensitive
18 * methods it uses.<P>
19 *
20 * This interface is supported in Java 1.1+ and should be compiled with class
21 * version stamp 45.3 (-target 1.1).
22 *
23 * @author Vlad Roubtsov, (C) 2003
24 */
25public
26interface IJREVersion
27{
28    // public: ................................................................
29
30    /** 'true' iff the current runtime version is 1.2 or later */
31    boolean JRE_1_2_PLUS = _JREVersion._JRE_1_2_PLUS; // static final but not inlinable
32    /** 'true' iff the current runtime version is 1.3 or later */
33    boolean JRE_1_3_PLUS = _JREVersion._JRE_1_3_PLUS; // static final but not inlinable
34    /** 'true' iff the current runtime version is 1.4 or later */
35    boolean JRE_1_4_PLUS = _JREVersion._JRE_1_4_PLUS; // static final but not inlinable
36
37    // supporting Java 1.5 is trivial...
38
39    boolean JRE_SUN_SIGNAL_COMPATIBLE = _JREVersion._JRE_SUN_SIGNAL_COMPATIBLE;
40
41    /*
42     * Use a dummy nested class to fake a static initializer for the outer
43     * interface (I want IJREVersion as an interface and not a class so that
44     * all JRE_XXX constants could be imported via "implements").
45     */
46    abstract class _JREVersion
47    {
48        static final boolean _JRE_1_2_PLUS; // set in <clinit>
49        static final boolean _JRE_1_3_PLUS; // set in <clinit>
50        static final boolean _JRE_1_4_PLUS; // set in <clinit>
51
52        static final boolean _JRE_SUN_SIGNAL_COMPATIBLE; // set in <clinit>
53
54        private _JREVersion () {} // prevent subclassing
55
56        static
57        {
58            _JRE_1_2_PLUS = ((SecurityManager.class.getModifiers () & 0x0400) == 0);
59
60            boolean temp = false;
61            if (_JRE_1_2_PLUS)
62            {
63                try
64                {
65                    StrictMath.abs (1.0);
66                    temp = true;
67                }
68                catch (Error ignore) {}
69            }
70            _JRE_1_3_PLUS = temp;
71
72            if (temp)
73            {
74                temp = false;
75                try
76                {
77                    " ".subSequence (0, 0);
78                    temp = true;
79                }
80                catch (NoSuchMethodError ignore) {}
81            }
82            _JRE_1_4_PLUS = temp;
83
84            temp = false;
85
86            _JRE_SUN_SIGNAL_COMPATIBLE = temp;
87        }
88
89    } // end of nested class
90
91} // end of interface
92// ----------------------------------------------------------------------------
93
94