revised Java 6 checks to test for the presence of specific Java 6 interfaces/classes only

This commit is contained in:
Juergen Hoeller
2009-05-28 11:16:42 +00:00
parent 15e51c5fb3
commit a26a2275c3
4 changed files with 42 additions and 17 deletions

View File

@@ -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)));

View File

@@ -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 <code>true</code> if available; <code>false</code> 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);
}