List of usage examples for org.springframework.jmx.access InvocationFailureException InvocationFailureException
public InvocationFailureException(String msg)
From source file:org.springframework.jmx.access.MBeanClientInterceptor.java
/** * Convert the given result object (from attribute access or operation invocation) * to the specified target class for returning from the proxy method. * @param result the result object as returned by the {@code MBeanServer} * @param parameter the method parameter of the proxy method that's been invoked * @return the converted result object, or the passed-in object if no conversion * is necessary/* w ww . j a v a2 s .co m*/ */ @Nullable protected Object convertResultValueIfNecessary(@Nullable Object result, MethodParameter parameter) { Class<?> targetClass = parameter.getParameterType(); try { if (result == null) { return null; } if (ClassUtils.isAssignableValue(targetClass, result)) { return result; } if (result instanceof CompositeData) { Method fromMethod = targetClass.getMethod("from", CompositeData.class); return ReflectionUtils.invokeMethod(fromMethod, null, result); } else if (result instanceof CompositeData[]) { CompositeData[] array = (CompositeData[]) result; if (targetClass.isArray()) { return convertDataArrayToTargetArray(array, targetClass); } else if (Collection.class.isAssignableFrom(targetClass)) { Class<?> elementType = ResolvableType.forMethodParameter(parameter).asCollection() .resolveGeneric(); if (elementType != null) { return convertDataArrayToTargetCollection(array, targetClass, elementType); } } } else if (result instanceof TabularData) { Method fromMethod = targetClass.getMethod("from", TabularData.class); return ReflectionUtils.invokeMethod(fromMethod, null, result); } else if (result instanceof TabularData[]) { TabularData[] array = (TabularData[]) result; if (targetClass.isArray()) { return convertDataArrayToTargetArray(array, targetClass); } else if (Collection.class.isAssignableFrom(targetClass)) { Class<?> elementType = ResolvableType.forMethodParameter(parameter).asCollection() .resolveGeneric(); if (elementType != null) { return convertDataArrayToTargetCollection(array, targetClass, elementType); } } } throw new InvocationFailureException( "Incompatible result value [" + result + "] for target type [" + targetClass.getName() + "]"); } catch (NoSuchMethodException ex) { throw new InvocationFailureException( "Could not obtain 'from(CompositeData)' / 'from(TabularData)' method on target type [" + targetClass.getName() + "] for conversion of MXBean data structure [" + result + "]"); } }