org.springframework.expression.MethodExecutor

Here are the examples of the java api org.springframework.expression.MethodExecutor taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

19 Source : MethodReference.java
with Apache License 2.0
from langtianya

private TypedValue getValueInternal(EvaluationContext evaluationContext, Object value, TypeDescriptor targetType, Object[] arguments) {
    List<TypeDescriptor> argumentTypes = getArgumentTypes(arguments);
    if (value == null) {
        throwIfNotNullSafe(argumentTypes);
        return TypedValue.NULL;
    }
    MethodExecutor executorToUse = getCachedExecutor(evaluationContext, value, targetType, argumentTypes);
    if (executorToUse != null) {
        try {
            return executorToUse.execute(evaluationContext, value, arguments);
        } catch (AccessException ex) {
            // Two reasons this can occur:
            // 1. the method invoked actually threw a real exception
            // 2. the method invoked was not preplaceded the arguments it expected and
            // has become 'stale'
            // In the first case we should not retry, in the second case we should see
            // if there is a better suited method.
            // To determine the situation, the AccessException will contain a cause.
            // If the cause is an InvocationTargetException, a user exception was
            // thrown inside the method. Otherwise the method could not be invoked.
            throwSimpleExceptionIfPossible(value, ex);
            // At this point we know it wasn't a user problem so worth a retry if a
            // better candidate can be found.
            this.cachedExecutor = null;
        }
    }
    // either there was no accessor or it no longer existed
    executorToUse = findAccessorForMethod(this.name, argumentTypes, value, evaluationContext);
    this.cachedExecutor = new CachedMethodExecutor(executorToUse, (value instanceof Clreplaced ? (Clreplaced<?>) value : null), targetType, argumentTypes);
    try {
        return executorToUse.execute(evaluationContext, value, arguments);
    } catch (AccessException ex) {
        // Same unwrapping exception handling as above in above catch block
        throwSimpleExceptionIfPossible(value, ex);
        throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION, this.name, value.getClreplaced().getName(), ex.getMessage());
    }
}

18 Source : MethodReference.java
with Apache License 2.0
from langtianya

private MethodExecutor findAccessorForMethod(String name, List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException {
    List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers();
    if (methodResolvers != null) {
        for (MethodResolver methodResolver : methodResolvers) {
            try {
                MethodExecutor methodExecutor = methodResolver.resolve(evaluationContext, targetObject, name, argumentTypes);
                if (methodExecutor != null) {
                    return methodExecutor;
                }
            } catch (AccessException ex) {
                throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.PROBLEM_LOCATING_METHOD, name, targetObject.getClreplaced());
            }
        }
    }
    throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, FormatHelper.formatMethodForMessage(name, argumentTypes), FormatHelper.formatClreplacedNameForMessage(targetObject instanceof Clreplaced ? ((Clreplaced<?>) targetObject) : targetObject.getClreplaced()));
}

17 Source : MethodReference.java
with MIT License
from Vip-Augus

private TypedValue getValueInternal(EvaluationContext evaluationContext, @Nullable Object value, @Nullable TypeDescriptor targetType, Object[] arguments) {
    List<TypeDescriptor> argumentTypes = getArgumentTypes(arguments);
    if (value == null) {
        throwIfNotNullSafe(argumentTypes);
        return TypedValue.NULL;
    }
    MethodExecutor executorToUse = getCachedExecutor(evaluationContext, value, targetType, argumentTypes);
    if (executorToUse != null) {
        try {
            return executorToUse.execute(evaluationContext, value, arguments);
        } catch (AccessException ex) {
            // Two reasons this can occur:
            // 1. the method invoked actually threw a real exception
            // 2. the method invoked was not preplaceded the arguments it expected and
            // has become 'stale'
            // In the first case we should not retry, in the second case we should see
            // if there is a better suited method.
            // To determine the situation, the AccessException will contain a cause.
            // If the cause is an InvocationTargetException, a user exception was
            // thrown inside the method. Otherwise the method could not be invoked.
            throwSimpleExceptionIfPossible(value, ex);
            // At this point we know it wasn't a user problem so worth a retry if a
            // better candidate can be found.
            this.cachedExecutor = null;
        }
    }
    // either there was no accessor or it no longer existed
    executorToUse = findAccessorForMethod(argumentTypes, value, evaluationContext);
    this.cachedExecutor = new CachedMethodExecutor(executorToUse, (value instanceof Clreplaced ? (Clreplaced<?>) value : null), targetType, argumentTypes);
    try {
        return executorToUse.execute(evaluationContext, value, arguments);
    } catch (AccessException ex) {
        // Same unwrapping exception handling as above in above catch block
        throwSimpleExceptionIfPossible(value, ex);
        throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION, this.name, value.getClreplaced().getName(), ex.getMessage());
    }
}

15 Source : MethodReference.java
with MIT License
from Vip-Augus

private MethodExecutor findAccessorForMethod(List<TypeDescriptor> argumentTypes, Object targetObject, EvaluationContext evaluationContext) throws SpelEvaluationException {
    AccessException accessException = null;
    List<MethodResolver> methodResolvers = evaluationContext.getMethodResolvers();
    for (MethodResolver methodResolver : methodResolvers) {
        try {
            MethodExecutor methodExecutor = methodResolver.resolve(evaluationContext, targetObject, this.name, argumentTypes);
            if (methodExecutor != null) {
                return methodExecutor;
            }
        } catch (AccessException ex) {
            accessException = ex;
            break;
        }
    }
    String method = FormatHelper.formatMethodForMessage(this.name, argumentTypes);
    String clreplacedName = FormatHelper.formatClreplacedNameForMessage(targetObject instanceof Clreplaced ? ((Clreplaced<?>) targetObject) : targetObject.getClreplaced());
    if (accessException != null) {
        throw new SpelEvaluationException(getStartPosition(), accessException, SpelMessage.PROBLEM_LOCATING_METHOD, method, clreplacedName);
    } else {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_NOT_FOUND, method, clreplacedName);
    }
}

14 Source : Spr7538Tests.java
with MIT License
from Vip-Augus

@Ignore
@Test
public void repro() throws Exception {
    AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
    BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setTypeConverter(converter);
    List<Foo> arguments = new ArrayList<>();
    // !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
    // arguments.add(new Foo());
    List<TypeDescriptor> paramDescriptors = new ArrayList<>();
    Method method = AlwaysTrueReleaseStrategy.clreplaced.getMethod("checkCompleteness", List.clreplaced);
    paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0)));
    List<TypeDescriptor> argumentTypes = new ArrayList<>();
    argumentTypes.add(TypeDescriptor.forObject(arguments));
    ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
    MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);
    Object result = executor.execute(context, target, arguments);
    System.out.println("Result: " + result);
}

14 Source : Spr7538Tests.java
with Apache License 2.0
from SourceHot

@Test
void repro() throws Exception {
    AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
    BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setTypeConverter(converter);
    List<Foo> arguments = Collections.emptyList();
    List<TypeDescriptor> paramDescriptors = new ArrayList<>();
    Method method = AlwaysTrueReleaseStrategy.clreplaced.getMethod("checkCompleteness", List.clreplaced);
    paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0)));
    List<TypeDescriptor> argumentTypes = new ArrayList<>();
    argumentTypes.add(TypeDescriptor.forObject(arguments));
    ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
    MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);
    Object result = executor.execute(context, target, arguments);
    System.out.println("Result: " + result);
}

14 Source : Spr7538Tests.java
with Apache License 2.0
from langtianya

@Ignore
@Test
public void repro() throws Exception {
    AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
    BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setTypeConverter(converter);
    List<Foo> arguments = new ArrayList<Foo>();
    // !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
    // arguments.add(new Foo());
    List<TypeDescriptor> paramDescriptors = new ArrayList<TypeDescriptor>();
    Method method = AlwaysTrueReleaseStrategy.clreplaced.getMethod("checkCompleteness", List.clreplaced);
    paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, 0)));
    List<TypeDescriptor> argumentTypes = new ArrayList<TypeDescriptor>();
    argumentTypes.add(TypeDescriptor.forObject(arguments));
    ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
    MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);
    Object result = executor.execute(context, target, arguments);
    System.out.println("Result: " + result);
}