1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.core;
  17. /**
  18. * Class used to find the current Java/JDK version.
  19. * Usually we want to find if we're in a 1.4 or higher JVM.
  20. * (Spring does not support 1.2 JVMs.)
  21. * @author Rod Johnson
  22. * @version $Id: JdkVersion.java,v 1.3 2004/06/02 17:12:30 jhoeller Exp $
  23. */
  24. public class JdkVersion {
  25. public static final int JAVA_13 = 0;
  26. public static final int JAVA_14 = 1;
  27. public static final int JAVA_15 = 2;
  28. private static int majorJavaVersion = JAVA_13;
  29. static {
  30. String javaVersion = System.getProperty("java.version");
  31. // should look like "1.4.1_02"
  32. if (javaVersion.indexOf("1.4") != -1) {
  33. majorJavaVersion = JAVA_14;
  34. }
  35. else if (javaVersion.indexOf("1.5") != -1) {
  36. majorJavaVersion = JAVA_15;
  37. }
  38. // else leave as 1.3 default
  39. }
  40. /**
  41. * Get the major version code. This means we can do things like
  42. * <code>if getMajorJavaVersion() < JAVA_14</code>.
  43. * @return a code comparable to the JAVA_XX codes in this class
  44. * @see #JAVA_13
  45. * @see #JAVA_14
  46. * @see #JAVA_15
  47. */
  48. public static int getMajorJavaVersion() {
  49. return majorJavaVersion;
  50. }
  51. }