KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > easymock > classextension > internal > ClassInstantiatorFactory


1 /*
2  * Copyright (c) 2003-2004 OFFIS. This program is made available under the terms of
3  * the MIT License.
4  */

5 package org.easymock.classextension.internal;
6
7 /**
8  * Factory returning a {@link IClassInstantiator}for the current JVM
9  */

10 public class ClassInstantiatorFactory {
11
12     // ///CLOVER:OFF
13
private ClassInstantiatorFactory() {
14     }
15
16     // ///CLOVER:ON
17

18     /**
19      * Returns the current JVM as specified in the Systtem properties
20      *
21      * @return current JVM
22      */

23     public static String JavaDoc getJVM() {
24         return System.getProperty("java.vm.specification.vendor");
25     }
26
27     /**
28      * Returnes the current JVM specification version (1.5, 1.4, 1.3)
29      *
30      * @return current JVM specification version
31      */

32     public static String JavaDoc getJVMSpecificationVersion() {
33         return System.getProperty("java.specification.version");
34     }
35
36     public static boolean isSunJVM() {
37         return getJVM().equals("Sun Microsystems Inc.");
38     }
39
40     public static boolean is1_3Specifications() {
41         return getJVMSpecificationVersion().equals("1.3");
42     }
43
44     /**
45      * Returns a class instantiator suitable for the current JVM
46      *
47      * @return a class instantiator usable on the current JVM
48      */

49     public static IClassInstantiator getInstantiator() {
50         // Sadly, the class extension only works on Sun JVM for JDK 1.4 and
51
// above
52
if (isSunJVM() && !is1_3Specifications()) {
53             return new SunClassInstantiator();
54         }
55         return new DefaultClassInstantiator();
56     }
57 }
58
Popular Tags