diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java b/org.springframework.context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java index 101419d233d..8e2dfee1a12 100644 --- a/org.springframework.context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java +++ b/org.springframework.context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,6 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.core.JdkVersion; import org.springframework.jmx.support.JmxUtils; import org.springframework.jmx.support.ObjectNameManager; import org.springframework.util.ClassUtils; @@ -258,7 +257,7 @@ public class MBeanClientInterceptor if (this.useStrictCasing) { // Use the JDK's own MBeanServerInvocationHandler, // in particular for native MXBean support on Java 6. - if (JdkVersion.isAtLeastJava16()) { + if (JmxUtils.isMXBeanSupportAvailable()) { this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); diff --git a/org.springframework.context/src/main/java/org/springframework/jmx/support/JmxUtils.java b/org.springframework.context/src/main/java/org/springframework/jmx/support/JmxUtils.java index 2bc3a663a51..849e1c0c280 100644 --- a/org.springframework.context/src/main/java/org/springframework/jmx/support/JmxUtils.java +++ b/org.springframework.context/src/main/java/org/springframework/jmx/support/JmxUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -303,7 +303,7 @@ public abstract class JmxUtils { for (Class iface : implementedInterfaces) { boolean isMxBean = iface.getName().endsWith(MXBEAN_SUFFIX); if (mxBeanAnnotationAvailable) { - Boolean checkResult = MXBeanChecker.hasMXBeanAnnotation(iface); + Boolean checkResult = MXBeanChecker.evaluateMXBeanAnnotation(iface); if (checkResult != null) { isMxBean = checkResult; } @@ -315,13 +315,22 @@ public abstract class JmxUtils { return getMXBeanInterface(clazz.getSuperclass()); } + /** + * Check whether MXBean support is available, i.e. whether we're running + * on Java 6 or above. + * @return true if available; false otherwise + */ + public static boolean isMXBeanSupportAvailable() { + return mxBeanAnnotationAvailable; + } + /** * Inner class to avoid a Java 6 dependency. */ private static class MXBeanChecker { - public static Boolean hasMXBeanAnnotation(Class iface) { + public static Boolean evaluateMXBeanAnnotation(Class iface) { MXBean mxBean = iface.getAnnotation(MXBean.class); return (mxBean != null ? mxBean.value() : null); } diff --git a/org.springframework.core/src/main/java/org/springframework/core/CollectionFactory.java b/org.springframework.core/src/main/java/org/springframework/core/CollectionFactory.java index a2055c2edf2..2cdff0ca5fa 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/CollectionFactory.java +++ b/org.springframework.core/src/main/java/org/springframework/core/CollectionFactory.java @@ -26,8 +26,6 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.NavigableMap; -import java.util.NavigableSet; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; @@ -36,6 +34,7 @@ import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; +import org.springframework.util.ClassUtils; import org.springframework.util.LinkedCaseInsensitiveMap; /** @@ -53,21 +52,34 @@ import org.springframework.util.LinkedCaseInsensitiveMap; */ public abstract class CollectionFactory { + private static final String NAVIGABLE_SET_CLASS_NAME = "java.util.NavigableSet"; + + private static final String NAVIGABLE_MAP_CLASS_NAME = "java.util.NavigableMap"; + private static final Set approximableCollectionTypes = new HashSet(10); private static final Set approximableMapTypes = new HashSet(6); + static { + // Standard collection interfaces approximableCollectionTypes.add(Collection.class); approximableCollectionTypes.add(List.class); approximableCollectionTypes.add(Set.class); approximableCollectionTypes.add(SortedSet.class); approximableMapTypes.add(Map.class); approximableMapTypes.add(SortedMap.class); - if (JdkVersion.isAtLeastJava16()) { - approximableCollectionTypes.add(NavigableSet.class); - approximableMapTypes.add(NavigableMap.class); + + // New Java 6 collection interfaces + try { + approximableCollectionTypes.add(ClassUtils.forName(NAVIGABLE_SET_CLASS_NAME, CollectionFactory.class.getClassLoader())); + approximableMapTypes.add(ClassUtils.forName(NAVIGABLE_MAP_CLASS_NAME, CollectionFactory.class.getClassLoader())); } + catch (ClassNotFoundException ex) { + // not running on Java 6 or above... + } + + // Common concrete collection classes approximableCollectionTypes.add(ArrayList.class); approximableCollectionTypes.add(LinkedList.class); approximableCollectionTypes.add(HashSet.class); @@ -78,6 +90,7 @@ public abstract class CollectionFactory { approximableMapTypes.add(TreeMap.class); } + /** * Create a linked Set if possible: This implementation always * creates a {@link java.util.LinkedHashSet}, since Spring 2.5 diff --git a/org.springframework.core/src/main/java/org/springframework/core/JdkVersion.java b/org.springframework.core/src/main/java/org/springframework/core/JdkVersion.java index 7b8d4ecad75..a19c2d149ba 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/JdkVersion.java +++ b/org.springframework.core/src/main/java/org/springframework/core/JdkVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,11 @@ package org.springframework.core; /** - * Internal helper class used to find the Java/JDK version + * Internal helper class used to find the Java/JVM version * that Spring is operating on, to allow for automatically * adapting to the present platform's capabilities. * - *

Note that Spring requires JVM 1.4 or higher, as of Spring 2.5. + *

Note that Spring requires JVM 1.5 or higher, as of Spring 3.0. * * @author Rod Johnson * @author Juergen Hoeller @@ -62,10 +62,10 @@ public abstract class JdkVersion { static { javaVersion = System.getProperty("java.version"); // version String should look like "1.4.2_10" - if (javaVersion.indexOf("1.7.") != -1) { + if (javaVersion.contains("1.7.")) { majorJavaVersion = JAVA_17; } - else if (javaVersion.indexOf("1.6.") != -1) { + else if (javaVersion.contains("1.6.")) { majorJavaVersion = JAVA_16; } else { @@ -99,6 +99,7 @@ public abstract class JdkVersion { return majorJavaVersion; } + /** * Convenience method to determine if the current JVM is at least Java 1.4. * @return true if the current JVM is at least Java 1.4 @@ -133,12 +134,15 @@ public abstract class JdkVersion { * Convenience method to determine if the current JVM is at least * Java 1.6 (Java 6). * @return true if the current JVM is at least Java 1.6 + * @deprecated as of Spring 3.0, in favor of reflective checks for + * the specific Java 1.6 classes of interest * @see #getMajorJavaVersion() * @see #JAVA_16 * @see #JAVA_17 */ + @Deprecated public static boolean isAtLeastJava16() { - return getMajorJavaVersion() >= JAVA_16; + return (majorJavaVersion >= JAVA_16); } }