revised Java 6 checks to test for the presence of specific Java 6 interfaces/classes only
This commit is contained in:
parent
15e51c5fb3
commit
a26a2275c3
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.BeanClassLoaderAware;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.core.JdkVersion;
|
|
||||||
import org.springframework.jmx.support.JmxUtils;
|
import org.springframework.jmx.support.JmxUtils;
|
||||||
import org.springframework.jmx.support.ObjectNameManager;
|
import org.springframework.jmx.support.ObjectNameManager;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
@ -258,7 +257,7 @@ public class MBeanClientInterceptor
|
||||||
if (this.useStrictCasing) {
|
if (this.useStrictCasing) {
|
||||||
// Use the JDK's own MBeanServerInvocationHandler,
|
// Use the JDK's own MBeanServerInvocationHandler,
|
||||||
// in particular for native MXBean support on Java 6.
|
// in particular for native MXBean support on Java 6.
|
||||||
if (JdkVersion.isAtLeastJava16()) {
|
if (JmxUtils.isMXBeanSupportAvailable()) {
|
||||||
this.invocationHandler =
|
this.invocationHandler =
|
||||||
new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
|
new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
|
||||||
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
|
(this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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) {
|
for (Class iface : implementedInterfaces) {
|
||||||
boolean isMxBean = iface.getName().endsWith(MXBEAN_SUFFIX);
|
boolean isMxBean = iface.getName().endsWith(MXBEAN_SUFFIX);
|
||||||
if (mxBeanAnnotationAvailable) {
|
if (mxBeanAnnotationAvailable) {
|
||||||
Boolean checkResult = MXBeanChecker.hasMXBeanAnnotation(iface);
|
Boolean checkResult = MXBeanChecker.evaluateMXBeanAnnotation(iface);
|
||||||
if (checkResult != null) {
|
if (checkResult != null) {
|
||||||
isMxBean = checkResult;
|
isMxBean = checkResult;
|
||||||
}
|
}
|
||||||
|
|
@ -315,13 +315,22 @@ public abstract class JmxUtils {
|
||||||
return getMXBeanInterface(clazz.getSuperclass());
|
return getMXBeanInterface(clazz.getSuperclass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether MXBean support is available, i.e. whether we're running
|
||||||
|
* on Java 6 or above.
|
||||||
|
* @return <code>true</code> if available; <code>false</code> otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isMXBeanSupportAvailable() {
|
||||||
|
return mxBeanAnnotationAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inner class to avoid a Java 6 dependency.
|
* Inner class to avoid a Java 6 dependency.
|
||||||
*/
|
*/
|
||||||
private static class MXBeanChecker {
|
private static class MXBeanChecker {
|
||||||
|
|
||||||
public static Boolean hasMXBeanAnnotation(Class<?> iface) {
|
public static Boolean evaluateMXBeanAnnotation(Class<?> iface) {
|
||||||
MXBean mxBean = iface.getAnnotation(MXBean.class);
|
MXBean mxBean = iface.getAnnotation(MXBean.class);
|
||||||
return (mxBean != null ? mxBean.value() : null);
|
return (mxBean != null ? mxBean.value() : null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NavigableMap;
|
|
||||||
import java.util.NavigableSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
@ -36,6 +34,7 @@ import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,21 +52,34 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
*/
|
*/
|
||||||
public abstract class CollectionFactory {
|
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<Class> approximableCollectionTypes = new HashSet<Class>(10);
|
private static final Set<Class> approximableCollectionTypes = new HashSet<Class>(10);
|
||||||
|
|
||||||
private static final Set<Class> approximableMapTypes = new HashSet<Class>(6);
|
private static final Set<Class> approximableMapTypes = new HashSet<Class>(6);
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
// Standard collection interfaces
|
||||||
approximableCollectionTypes.add(Collection.class);
|
approximableCollectionTypes.add(Collection.class);
|
||||||
approximableCollectionTypes.add(List.class);
|
approximableCollectionTypes.add(List.class);
|
||||||
approximableCollectionTypes.add(Set.class);
|
approximableCollectionTypes.add(Set.class);
|
||||||
approximableCollectionTypes.add(SortedSet.class);
|
approximableCollectionTypes.add(SortedSet.class);
|
||||||
approximableMapTypes.add(Map.class);
|
approximableMapTypes.add(Map.class);
|
||||||
approximableMapTypes.add(SortedMap.class);
|
approximableMapTypes.add(SortedMap.class);
|
||||||
if (JdkVersion.isAtLeastJava16()) {
|
|
||||||
approximableCollectionTypes.add(NavigableSet.class);
|
// New Java 6 collection interfaces
|
||||||
approximableMapTypes.add(NavigableMap.class);
|
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(ArrayList.class);
|
||||||
approximableCollectionTypes.add(LinkedList.class);
|
approximableCollectionTypes.add(LinkedList.class);
|
||||||
approximableCollectionTypes.add(HashSet.class);
|
approximableCollectionTypes.add(HashSet.class);
|
||||||
|
|
@ -78,6 +90,7 @@ public abstract class CollectionFactory {
|
||||||
approximableMapTypes.add(TreeMap.class);
|
approximableMapTypes.add(TreeMap.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a linked Set if possible: This implementation always
|
* Create a linked Set if possible: This implementation always
|
||||||
* creates a {@link java.util.LinkedHashSet}, since Spring 2.5
|
* creates a {@link java.util.LinkedHashSet}, since Spring 2.5
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
package org.springframework.core;
|
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
|
* that Spring is operating on, to allow for automatically
|
||||||
* adapting to the present platform's capabilities.
|
* adapting to the present platform's capabilities.
|
||||||
*
|
*
|
||||||
* <p>Note that Spring requires JVM 1.4 or higher, as of Spring 2.5.
|
* <p>Note that Spring requires JVM 1.5 or higher, as of Spring 3.0.
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
@ -62,10 +62,10 @@ public abstract class JdkVersion {
|
||||||
static {
|
static {
|
||||||
javaVersion = System.getProperty("java.version");
|
javaVersion = System.getProperty("java.version");
|
||||||
// version String should look like "1.4.2_10"
|
// version String should look like "1.4.2_10"
|
||||||
if (javaVersion.indexOf("1.7.") != -1) {
|
if (javaVersion.contains("1.7.")) {
|
||||||
majorJavaVersion = JAVA_17;
|
majorJavaVersion = JAVA_17;
|
||||||
}
|
}
|
||||||
else if (javaVersion.indexOf("1.6.") != -1) {
|
else if (javaVersion.contains("1.6.")) {
|
||||||
majorJavaVersion = JAVA_16;
|
majorJavaVersion = JAVA_16;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -99,6 +99,7 @@ public abstract class JdkVersion {
|
||||||
return majorJavaVersion;
|
return majorJavaVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to determine if the current JVM is at least Java 1.4.
|
* Convenience method to determine if the current JVM is at least Java 1.4.
|
||||||
* @return <code>true</code> if the current JVM is at least Java 1.4
|
* @return <code>true</code> 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
|
* Convenience method to determine if the current JVM is at least
|
||||||
* Java 1.6 (Java 6).
|
* Java 1.6 (Java 6).
|
||||||
* @return <code>true</code> if the current JVM is at least Java 1.6
|
* @return <code>true</code> 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 #getMajorJavaVersion()
|
||||||
* @see #JAVA_16
|
* @see #JAVA_16
|
||||||
* @see #JAVA_17
|
* @see #JAVA_17
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean isAtLeastJava16() {
|
public static boolean isAtLeastJava16() {
|
||||||
return getMajorJavaVersion() >= JAVA_16;
|
return (majorJavaVersion >= JAVA_16);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue