|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2014 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. |
|
|
|
@ -107,7 +107,7 @@ public class MBeanClientInterceptor |
|
|
|
|
|
|
|
|
|
|
|
private boolean useStrictCasing = true; |
|
|
|
private boolean useStrictCasing = true; |
|
|
|
|
|
|
|
|
|
|
|
private Class managementInterface; |
|
|
|
private Class<?> managementInterface; |
|
|
|
|
|
|
|
|
|
|
|
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); |
|
|
|
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); |
|
|
|
|
|
|
|
|
|
|
|
@ -215,7 +215,7 @@ public class MBeanClientInterceptor |
|
|
|
* setters and getters for MBean attributes and conventional Java methods |
|
|
|
* setters and getters for MBean attributes and conventional Java methods |
|
|
|
* for MBean operations. |
|
|
|
* for MBean operations. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setManagementInterface(Class managementInterface) { |
|
|
|
public void setManagementInterface(Class<?> managementInterface) { |
|
|
|
this.managementInterface = managementInterface; |
|
|
|
this.managementInterface = managementInterface; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -223,7 +223,7 @@ public class MBeanClientInterceptor |
|
|
|
* Return the management interface of the target MBean, |
|
|
|
* Return the management interface of the target MBean, |
|
|
|
* or {@code null} if none specified. |
|
|
|
* or {@code null} if none specified. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected final Class getManagementInterface() { |
|
|
|
protected final Class<?> getManagementInterface() { |
|
|
|
return this.managementInterface; |
|
|
|
return this.managementInterface; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -262,7 +262,7 @@ public class MBeanClientInterceptor |
|
|
|
this.invocationHandler = null; |
|
|
|
this.invocationHandler = null; |
|
|
|
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 (JmxUtils.isMXBeanSupportAvailable()) { |
|
|
|
if (JmxUtils.isMXBeanSupportAvailable()) { |
|
|
|
this.invocationHandler = |
|
|
|
this.invocationHandler = |
|
|
|
new MBeanServerInvocationHandler(this.serverToUse, this.objectName, |
|
|
|
new MBeanServerInvocationHandler(this.serverToUse, this.objectName, |
|
|
|
@ -297,7 +297,7 @@ public class MBeanClientInterceptor |
|
|
|
MBeanOperationInfo[] operationInfo = info.getOperations(); |
|
|
|
MBeanOperationInfo[] operationInfo = info.getOperations(); |
|
|
|
this.allowedOperations = new HashMap<MethodCacheKey, MBeanOperationInfo>(operationInfo.length); |
|
|
|
this.allowedOperations = new HashMap<MethodCacheKey, MBeanOperationInfo>(operationInfo.length); |
|
|
|
for (MBeanOperationInfo infoEle : operationInfo) { |
|
|
|
for (MBeanOperationInfo infoEle : operationInfo) { |
|
|
|
Class[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader); |
|
|
|
Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader); |
|
|
|
this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle); |
|
|
|
this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -531,7 +531,7 @@ public class MBeanClientInterceptor |
|
|
|
* is necessary |
|
|
|
* is necessary |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected Object convertResultValueIfNecessary(Object result, MethodParameter parameter) { |
|
|
|
protected Object convertResultValueIfNecessary(Object result, MethodParameter parameter) { |
|
|
|
Class targetClass = parameter.getParameterType(); |
|
|
|
Class<?> targetClass = parameter.getParameterType(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (result == null) { |
|
|
|
if (result == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -549,7 +549,7 @@ public class MBeanClientInterceptor |
|
|
|
return convertDataArrayToTargetArray(array, targetClass); |
|
|
|
return convertDataArrayToTargetArray(array, targetClass); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (Collection.class.isAssignableFrom(targetClass)) { |
|
|
|
else if (Collection.class.isAssignableFrom(targetClass)) { |
|
|
|
Class elementType = GenericCollectionTypeResolver.getCollectionParameterType(parameter); |
|
|
|
Class<?> elementType = GenericCollectionTypeResolver.getCollectionParameterType(parameter); |
|
|
|
if (elementType != null) { |
|
|
|
if (elementType != null) { |
|
|
|
return convertDataArrayToTargetCollection(array, targetClass, elementType); |
|
|
|
return convertDataArrayToTargetCollection(array, targetClass, elementType); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -565,7 +565,7 @@ public class MBeanClientInterceptor |
|
|
|
return convertDataArrayToTargetArray(array, targetClass); |
|
|
|
return convertDataArrayToTargetArray(array, targetClass); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (Collection.class.isAssignableFrom(targetClass)) { |
|
|
|
else if (Collection.class.isAssignableFrom(targetClass)) { |
|
|
|
Class elementType = GenericCollectionTypeResolver.getCollectionParameterType(parameter); |
|
|
|
Class<?> elementType = GenericCollectionTypeResolver.getCollectionParameterType(parameter); |
|
|
|
if (elementType != null) { |
|
|
|
if (elementType != null) { |
|
|
|
return convertDataArrayToTargetCollection(array, targetClass, elementType); |
|
|
|
return convertDataArrayToTargetCollection(array, targetClass, elementType); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -581,8 +581,8 @@ public class MBeanClientInterceptor |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Object convertDataArrayToTargetArray(Object[] array, Class targetClass) throws NoSuchMethodException { |
|
|
|
private Object convertDataArrayToTargetArray(Object[] array, Class<?> targetClass) throws NoSuchMethodException { |
|
|
|
Class targetType = targetClass.getComponentType(); |
|
|
|
Class<?> targetType = targetClass.getComponentType(); |
|
|
|
Method fromMethod = targetType.getMethod("from", array.getClass().getComponentType()); |
|
|
|
Method fromMethod = targetType.getMethod("from", array.getClass().getComponentType()); |
|
|
|
Object resultArray = Array.newInstance(targetType, array.length); |
|
|
|
Object resultArray = Array.newInstance(targetType, array.length); |
|
|
|
for (int i = 0; i < array.length; i++) { |
|
|
|
for (int i = 0; i < array.length; i++) { |
|
|
|
@ -592,11 +592,11 @@ public class MBeanClientInterceptor |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
private Collection convertDataArrayToTargetCollection(Object[] array, Class collectionType, Class elementType) |
|
|
|
private Collection<?> convertDataArrayToTargetCollection(Object[] array, Class<?> collectionType, Class<?> elementType) |
|
|
|
throws NoSuchMethodException { |
|
|
|
throws NoSuchMethodException { |
|
|
|
|
|
|
|
|
|
|
|
Method fromMethod = elementType.getMethod("from", array.getClass().getComponentType()); |
|
|
|
Method fromMethod = elementType.getMethod("from", array.getClass().getComponentType()); |
|
|
|
Collection resultColl = CollectionFactory.createCollection(collectionType, Array.getLength(array)); |
|
|
|
Collection<Object> resultColl = CollectionFactory.createCollection(collectionType, Array.getLength(array)); |
|
|
|
for (int i = 0; i < array.length; i++) { |
|
|
|
for (int i = 0; i < array.length; i++) { |
|
|
|
resultColl.add(ReflectionUtils.invokeMethod(fromMethod, null, array[i])); |
|
|
|
resultColl.add(ReflectionUtils.invokeMethod(fromMethod, null, array[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -608,6 +608,7 @@ public class MBeanClientInterceptor |
|
|
|
this.connector.close(); |
|
|
|
this.connector.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Simple wrapper class around a method name and its signature. |
|
|
|
* Simple wrapper class around a method name and its signature. |
|
|
|
* Used as the key when caching methods. |
|
|
|
* Used as the key when caching methods. |
|
|
|
@ -616,7 +617,7 @@ public class MBeanClientInterceptor |
|
|
|
|
|
|
|
|
|
|
|
private final String name; |
|
|
|
private final String name; |
|
|
|
|
|
|
|
|
|
|
|
private final Class[] parameterTypes; |
|
|
|
private final Class<?>[] parameterTypes; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new instance of {@code MethodCacheKey} with the supplied |
|
|
|
* Create a new instance of {@code MethodCacheKey} with the supplied |
|
|
|
@ -624,9 +625,9 @@ public class MBeanClientInterceptor |
|
|
|
* @param name the name of the method |
|
|
|
* @param name the name of the method |
|
|
|
* @param parameterTypes the arguments in the method signature |
|
|
|
* @param parameterTypes the arguments in the method signature |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MethodCacheKey(String name, Class[] parameterTypes) { |
|
|
|
public MethodCacheKey(String name, Class<?>[] parameterTypes) { |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
this.parameterTypes = (parameterTypes != null ? parameterTypes : new Class[0]); |
|
|
|
this.parameterTypes = (parameterTypes != null ? parameterTypes : new Class<?>[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|