public class InvocableShellMethod extends Object
The class may be created with a bean instance or with a bean name
(e.g. lazy-init bean, prototype bean). Use createWithResolvedBean()
to obtain a HandlerMethod
instance with a bean instance resolved
through the associated BeanFactory
.
Modifier and Type | Class and Description |
---|---|
protected class |
InvocableShellMethod.HandlerMethodParameter
A MethodParameter with HandlerMethod-specific behavior.
|
Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
log
Public for wrapping with fallback logger.
|
Modifier | Constructor and Description |
---|---|
protected |
InvocableShellMethod(InvocableShellMethod handlerMethod)
Copy constructor for use in subclasses.
|
|
InvocableShellMethod(Object bean,
Method method)
Create an instance from a bean instance and a method.
|
|
InvocableShellMethod(Object bean,
String methodName,
Class<?>... parameterTypes)
Create an instance from a bean instance, method name, and parameter types.
|
|
InvocableShellMethod(String beanName,
org.springframework.beans.factory.BeanFactory beanFactory,
Method method)
Create an instance from a bean name, a method, and a
BeanFactory . |
Modifier and Type | Method and Description |
---|---|
protected void |
assertTargetBean(Method method,
Object targetBean,
Object[] args)
Assert that the target bean class is an instance of the class where the given
method is declared.
|
InvocableShellMethod |
createWithResolvedBean()
If the provided instance contains a bean name rather than an object instance,
the bean name is resolved before a
InvocableShellMethod is created and
returned. |
protected Object |
doInvoke(Object... args)
Invoke the handler method with the given argument values.
|
boolean |
equals(Object other) |
protected static Object |
findProvidedArgument(org.springframework.core.MethodParameter parameter,
Object... providedArgs) |
protected static String |
formatArgumentError(org.springframework.core.MethodParameter param,
String message) |
protected String |
formatInvokeError(String text,
Object[] args) |
Object |
getBean()
Return the bean for this handler method.
|
Class<?> |
getBeanType()
This method returns the type of the handler for this handler method.
|
protected Method |
getBridgedMethod()
If the bean method is a bridge method, this method returns the bridged
(user-defined) method.
|
Method |
getMethod()
Return the method for this handler method.
|
<A extends Annotation> |
getMethodAnnotation(Class<A> annotationType)
Return a single annotation on the underlying method traversing its super methods
if no annotation can be found on the given method itself.
|
protected Object[] |
getMethodArgumentValues(org.springframework.messaging.Message<?> message,
Object... providedArgs)
Get the method argument values for the current message, checking the provided
argument values and falling back to the configured argument resolvers.
|
org.springframework.core.MethodParameter[] |
getMethodParameters()
Return the method parameters for this handler method.
|
InvocableShellMethod |
getResolvedFromHandlerMethod()
Return the HandlerMethod from which this HandlerMethod instance was
resolved via
createWithResolvedBean() . |
org.springframework.core.MethodParameter |
getReturnType()
Return the HandlerMethod return type.
|
org.springframework.core.MethodParameter |
getReturnValueType(Object returnValue)
Return the actual return value type.
|
String |
getShortLogMessage()
Return a short representation of this handler method for log message purposes.
|
int |
hashCode() |
<A extends Annotation> |
hasMethodAnnotation(Class<A> annotationType)
Return whether the parameter is declared with the given annotation type.
|
Object |
invoke(org.springframework.messaging.Message<?> message,
Object... providedArgs)
Invoke the method after resolving its argument values in the context of the given message.
|
boolean |
isVoid()
Return
true if the method return type is void, false otherwise. |
void |
setConversionService(org.springframework.core.convert.ConversionService conversionService)
Sets a conversion service
|
void |
setMessageMethodArgumentResolvers(ShellMethodArgumentResolverComposite argumentResolvers)
Set
HandlerMethodArgumentResolvers to use to use for resolving method argument values. |
void |
setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer for resolving parameter names when needed
(e.g.
|
void |
setValidator(javax.validation.Validator validator) |
String |
toString() |
public InvocableShellMethod(Object bean, Method method)
public InvocableShellMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
NoSuchMethodException
- when the method cannot be foundpublic InvocableShellMethod(String beanName, org.springframework.beans.factory.BeanFactory beanFactory, Method method)
BeanFactory
.
The method createWithResolvedBean()
may be used later to
re-create the HandlerMethod
with an initialized bean.protected InvocableShellMethod(InvocableShellMethod handlerMethod)
public void setConversionService(org.springframework.core.convert.ConversionService conversionService)
conversionService
- the conversion servicepublic void setValidator(javax.validation.Validator validator)
public void setMessageMethodArgumentResolvers(ShellMethodArgumentResolverComposite argumentResolvers)
HandlerMethodArgumentResolvers
to use to use for resolving method argument values.public void setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)
Default is a DefaultParameterNameDiscoverer
.
@Nullable public Object invoke(org.springframework.messaging.Message<?> message, Object... providedArgs) throws Exception
Argument values are commonly resolved through
HandlerMethodArgumentResolvers
.
The providedArgs
parameter however may supply argument values to be used directly,
i.e. without argument resolution.
Delegates to getMethodArgumentValues(org.springframework.messaging.Message<?>, java.lang.Object...)
and calls doInvoke(java.lang.Object...)
with the
resolved arguments.
message
- the current message being processedprovidedArgs
- "given" arguments matched by type, not resolvedException
- raised if no suitable argument resolver can be found,
or if the method raised an exceptiongetMethodArgumentValues(org.springframework.messaging.Message<?>, java.lang.Object...)
,
doInvoke(java.lang.Object...)
protected Object[] getMethodArgumentValues(org.springframework.messaging.Message<?> message, Object... providedArgs) throws Exception
The resulting array will be passed into doInvoke(java.lang.Object...)
.
Exception
@Nullable protected Object doInvoke(Object... args) throws Exception
Exception
public Object getBean()
public Method getMethod()
public Class<?> getBeanType()
Note that if the bean type is a CGLIB-generated class, the original user-defined class is returned.
protected Method getBridgedMethod()
getMethod()
.public org.springframework.core.MethodParameter[] getMethodParameters()
public org.springframework.core.MethodParameter getReturnType()
public org.springframework.core.MethodParameter getReturnValueType(@Nullable Object returnValue)
public boolean isVoid()
true
if the method return type is void, false
otherwise.@Nullable public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)
Also supports merged composed annotations with attribute overrides.
annotationType
- the type of annotation to introspect the method fornull
if none foundAnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<A>)
public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType)
annotationType
- the annotation type to look forAnnotatedElementUtils.hasAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
@Nullable public InvocableShellMethod getResolvedFromHandlerMethod()
createWithResolvedBean()
.public InvocableShellMethod createWithResolvedBean()
InvocableShellMethod
is created and
returned.public String getShortLogMessage()
@Nullable protected static Object findProvidedArgument(org.springframework.core.MethodParameter parameter, @Nullable Object... providedArgs)
protected static String formatArgumentError(org.springframework.core.MethodParameter param, String message)
protected void assertTargetBean(Method method, Object targetBean, Object[] args)
Copyright © 2024. All rights reserved.