/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.context;
import io.micronaut.core.annotation.UsedByGeneratedCode;
import io.micronaut.inject.BeanDefinition;
import io.micronaut.inject.ExecutableMethod;
import io.micronaut.inject.MethodExecutionHandle;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;
Interface for components that are able to locate and return ExecutionHandle
instances for beans. Author: Graeme Rocher Since: 1.0
/**
* Interface for components that are able to locate and return {@link io.micronaut.inject.ExecutionHandle} instances
* for beans.
*
* @author Graeme Rocher
* @since 1.0
*/
public interface ExecutionHandleLocator {
A empty no-op locator.
/**
* A empty no-op locator.
*/
ExecutionHandleLocator EMPTY = new ExecutionHandleLocator() { };
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - beanType – The bean type
- method – The method
- arguments – The arguments
Type parameters: - <T> – The target bean
- <R> – The result type of the execution handle
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The target bean
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param method The method
* @param arguments The arguments
* @return The execution handle
*/
default <T, R> Optional<MethodExecutionHandle<T, R>> findExecutionHandle(Class<T> beanType, String method, Class... arguments) {
return Optional.empty();
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - beanType – The bean type
- qualifier – The bean qualifer
- method – The method
- arguments – The arguments
Type parameters: - <T> – The target bean
- <R> – The result type of the execution handle
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The target bean
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param qualifier The bean qualifer
* @param method The method
* @param arguments The arguments
* @return The execution handle
*/
default <T, R> Optional<MethodExecutionHandle<T, R>> findExecutionHandle(Class<T> beanType, Qualifier<?> qualifier, String method, Class... arguments) {
return Optional.empty();
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - bean – The bean to invoke the method on
- method – The method
- arguments – The arguments
Type parameters: - <T> – The target bean
- <R> – The result type of the execution handle
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The target bean
* @param <R> The result type of the execution handle
* @param bean The bean to invoke the method on
* @param method The method
* @param arguments The arguments
* @return The execution handle
*/
default <T, R> Optional<MethodExecutionHandle<T, R>> findExecutionHandle(T bean, String method, Class... arguments) {
return Optional.empty();
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - beanType – The bean type
- method – The method
- arguments – The arguments
Type parameters: - <T> – The bean type class
- <R> – The result type of the execution handle
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The bean type class
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param method The method
* @param arguments The arguments
* @return The execution handle
*/
default <T, R> Optional<ExecutableMethod<T, R>> findExecutableMethod(Class<T> beanType, String method, Class... arguments) {
return Optional.empty();
}
Finds the original unproxied method for a ProxyBeanDefinition
. Params: - beanType – The bean type
- method – The method
- arguments – The arguments
Type parameters: Returns: The execution handle
/**
* Finds the original unproxied method for a {@link io.micronaut.inject.ProxyBeanDefinition}.
*
* @param <T> The bean type class
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param method The method
* @param arguments The arguments
* @return The execution handle
*/
default <T, R> Optional<ExecutableMethod<T, R>> findProxyTargetMethod(Class<T> beanType, String method, Class... arguments) {
return Optional.empty();
}
Finds the original unproxied method for a ProxyBeanDefinition
. Params: - beanType – The bean type
- qualifier – The qualifier
- method – The method
- arguments – The arguments
Type parameters: Returns: The execution handle
/**
* Finds the original unproxied method for a {@link io.micronaut.inject.ProxyBeanDefinition}.
*
* @param <T> The bean type class
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param qualifier The qualifier
* @param method The method
* @param arguments The arguments
* @return The execution handle
*/
default <T, R> Optional<ExecutableMethod<T, R>> findProxyTargetMethod(Class<T> beanType, Qualifier<T> qualifier, String method, Class... arguments) {
return Optional.empty();
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - beanType – The bean type
- method – The method
- arguments – The arguments
Type parameters: - <T> – The bean type class
- <R> – The result type of the execution handle
Throws: - NoSuchMethodException – if the method cannot be found
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The bean type class
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param method The method
* @param arguments The arguments
* @return The execution handle
* @throws NoSuchMethodException if the method cannot be found
*/
default <T, R> ExecutableMethod<T, R> getExecutableMethod(Class<T> beanType, String method, Class... arguments) throws NoSuchMethodException {
Optional<ExecutableMethod<T, R>> executableMethod = this.findExecutableMethod(beanType, method, arguments);
return executableMethod.orElseThrow(() ->
new NoSuchMethodException("No such method [" + method + "(" + Arrays.stream(arguments).map(Class::getName).collect(Collectors.joining(",")) + ") ] for bean [" + beanType.getName() + "]")
);
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - beanType – The bean type
- method – The method
- arguments – The arguments
Type parameters: - <T> – The bean type class
- <R> – The result type of the execution handle
Throws: - NoSuchMethodException – if the method cannot be found
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The bean type class
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param method The method
* @param arguments The arguments
* @return The execution handle
* @throws NoSuchMethodException if the method cannot be found
*/
@UsedByGeneratedCode
default <T, R> ExecutableMethod<T, R> getProxyTargetMethod(Class<T> beanType, String method, Class... arguments) throws NoSuchMethodException {
Optional<ExecutableMethod<T, R>> executableMethod = this.findProxyTargetMethod(beanType, method, arguments);
return executableMethod.orElseThrow(() ->
new NoSuchMethodException("No such method [" + method + "(" + Arrays.stream(arguments).map(Class::getName).collect(Collectors.joining(",")) + ") ] for bean [" + beanType.getName() + "]")
);
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - beanType – The bean type
- qualifier – The qualifier
- method – The method
- arguments – The arguments
Type parameters: - <T> – The bean type class
- <R> – The result type of the execution handle
Throws: - NoSuchMethodException – if the method cannot be found
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The bean type class
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param qualifier The qualifier
* @param method The method
* @param arguments The arguments
* @return The execution handle
* @throws NoSuchMethodException if the method cannot be found
*/
@UsedByGeneratedCode
default <T, R> ExecutableMethod<T, R> getProxyTargetMethod(Class<T> beanType, Qualifier<T> qualifier, String method, Class... arguments) throws NoSuchMethodException {
Optional<ExecutableMethod<T, R>> executableMethod = this.findProxyTargetMethod(beanType, qualifier, method, arguments);
return executableMethod.orElseThrow(() ->
new NoSuchMethodException("No such method [" + method + "(" + Arrays.stream(arguments).map(Class::getName).collect(Collectors.joining(",")) + ") ] for bean [" + beanType.getName() + "]")
);
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
implemented by generated byte code.
Params: - beanType – The bean type
- method – The method
- arguments – The arguments
Type parameters: - <T> – The target bean
- <R> – The result type of the execution handle
Throws: - NoSuchMethodException – if the method cannot be found
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be
* implemented by generated byte code.
*
* @param <T> The target bean
* @param <R> The result type of the execution handle
* @param beanType The bean type
* @param method The method
* @param arguments The arguments
* @return The execution handle
* @throws NoSuchMethodException if the method cannot be found
*/
default <T, R> MethodExecutionHandle<T, R> getExecutionHandle(Class<T> beanType, String method, Class... arguments) throws NoSuchMethodException {
return this.<T, R>findExecutionHandle(beanType, method, arguments).orElseThrow(() ->
new NoSuchMethodException("No such method [" + method + "(" + Arrays.stream(arguments).map(Class::getName).collect(Collectors.joining(",")) + ") ] for bean [" + beanType.getName() + "]")
);
}
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.
Params: - bean – The bean to invoke the method on
- method – The method
- arguments – The arguments
Type parameters: - <T> – The target bean
- <R> – The result type of the execution handle
Throws: - NoSuchMethodException – if the method cannot be found
Returns: The execution handle
/**
* Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.
*
* @param <T> The target bean
* @param <R> The result type of the execution handle
* @param bean The bean to invoke the method on
* @param method The method
* @param arguments The arguments
* @return The execution handle
* @throws NoSuchMethodException if the method cannot be found
*/
default <T, R> MethodExecutionHandle<T, R> getExecutionHandle(T bean, String method, Class... arguments) throws NoSuchMethodException {
return this.<T, R>findExecutionHandle(bean, method, arguments).orElseThrow(() ->
new NoSuchMethodException("No such method [" + method + "(" + Arrays.stream(arguments).map(Class::getName).collect(Collectors.joining(",")) + ") ] for bean [" + bean + "]")
);
}
Create an execution handle for the given bean definition and method.
Params: - beanDefinition – The bean definition
- method – The method
Returns: The execution handle
/**
* Create an execution handle for the given bean definition and method.
* @param beanDefinition The bean definition
* @param method The method
* @return The execution handle
*/
default MethodExecutionHandle<?, Object> createExecutionHandle(BeanDefinition<?> beanDefinition, ExecutableMethod<Object, ?> method) {
throw new UnsupportedOperationException("No such method [" + method + "(" + Arrays.stream(method.getArgumentTypes()).map(Class::getName).collect(Collectors.joining(",")) + ") ] for bean [" + beanDefinition.getBeanType() + "]");
}
}