private void prepareEvaluationContext() throws Exception { StandardEvaluationContext context = getEvaluationContext(false); Class<?> targetType = AopUtils.getTargetClass(this.targetObject); if (this.method != null) { context.registerMethodFilter(targetType, new FixedMethodFilter(this.method)); if (this.expectedType != null) { Assert.state(context.getTypeConverter() .canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), this.expectedType), () -> "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); } } else { AnnotatedMethodFilter filter = new AnnotatedMethodFilter(this.annotationType, this.methodName, this.requiresReply); Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()), () -> "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); context.registerMethodFilter(targetType, filter); } context.setVariable("target", this.targetObject); context.registerFunction("requiredHeader", ParametersWrapper.class.getDeclaredMethod("getHeader", Map.class, String.class)); }
private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class<?> targetType, TypeConverter typeConverter) { if (this.expectedType == null) { return true; } List<Method> methods = filter.filter(Arrays.asList(ReflectionUtils.getAllDeclaredMethods(targetType))); for (Method candidate : methods) { if (typeConverter.canConvert(TypeDescriptor.valueOf(candidate.getReturnType()), this.expectedType)) { return true; } } return false; }
private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class<?> targetType, TypeConverter typeConverter) { if (this.expectedType == null) { return true; } List<Method> methods = filter.filter(Arrays.asList(ReflectionUtils.getAllDeclaredMethods(targetType))); for (Method candidate : methods) { if (typeConverter.canConvert(TypeDescriptor.valueOf(candidate.getReturnType()), this.expectedType)) { return true; } } return false; }
private void prepareEvaluationContext() throws Exception { StandardEvaluationContext context = getEvaluationContext(false); Class<?> targetType = AopUtils.getTargetClass(this.targetObject); if (this.method != null) { context.registerMethodFilter(targetType, new FixedMethodFilter(this.method)); if (this.expectedType != null) { Assert.state(context.getTypeConverter() .canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), this.expectedType), "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); } } else { AnnotatedMethodFilter filter = new AnnotatedMethodFilter(this.annotationType, this.methodName, this.requiresReply); Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()), "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); context.registerMethodFilter(targetType, filter); } context.setVariable("target", this.targetObject); context.registerFunction("requiredHeader", ParametersWrapper.class.getDeclaredMethod("getHeader", Map.class, String.class)); }