Class AbstractMethodInvokingDelegator<T>
- java.lang.Object
- org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator<T>
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
ItemProcessorAdapter,ItemReaderAdapter,ItemWriterAdapter,MethodInvokingTaskletAdapter,PropertyExtractingDelegatingItemWriter
public abstract class AbstractMethodInvokingDelegator<T> extends java.lang.Object implements org.springframework.beans.factory.InitializingBeanSuperclass for delegating classes which dynamically call a custom method of injected object. Provides convenient API for dynamic method invocation shielding subclasses from low-level details and exception handling.Exceptions thrown by a successfully invoked delegate method are re-thrown without wrapping. In case the delegate method throws aThrowablethat doesn't subclassExceptionit will be wrapped byAbstractMethodInvokingDelegator.InvocationTargetThrowableWrapper.- Author:
- Robert Kasanicky, Mahmoud Ben Hassine
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractMethodInvokingDelegator.InvocationTargetThrowableWrapperUsed to wrap aThrowable(not anException) thrown by a reflectively-invoked delegate.
Constructor Summary
Constructors Constructor Description AbstractMethodInvokingDelegator()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()protected java.lang.Object[]getArguments()Return arguments.protected TinvokeDelegateMethod()Invoker the target method with arguments set bysetArguments(Object[]).protected TinvokeDelegateMethodWithArgument(java.lang.Object object)Invokes the target method with given argument.protected TinvokeDelegateMethodWithArguments(java.lang.Object[] args)Invokes the target method with given arguments.voidsetArguments(java.lang.Object[] arguments)voidsetTargetMethod(java.lang.String targetMethod)voidsetTargetObject(java.lang.Object targetObject)
Method Detail
invokeDelegateMethod
protected T invokeDelegateMethod() throws java.lang.Exception
Invoker the target method with arguments set bysetArguments(Object[]).- Returns:
- object returned by invoked method
- Throws:
java.lang.Exception- exception thrown when executing the delegate method.
invokeDelegateMethodWithArgument
protected T invokeDelegateMethodWithArgument(java.lang.Object object) throws java.lang.Exception
Invokes the target method with given argument.- Parameters:
object- argument for the target method- Returns:
- object returned by target method
- Throws:
java.lang.Exception- exception thrown when executing the delegate method.
invokeDelegateMethodWithArguments
protected T invokeDelegateMethodWithArguments(java.lang.Object[] args) throws java.lang.Exception
Invokes the target method with given arguments.- Parameters:
args- arguments for the invoked method- Returns:
- object returned by invoked method
- Throws:
java.lang.Exception- exception thrown when executing the delegate method.
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception
setTargetObject
public void setTargetObject(java.lang.Object targetObject)
- Parameters:
targetObject- the delegate - bean id can be used to set this value in Spring configuration
setTargetMethod
public void setTargetMethod(java.lang.String targetMethod)
- Parameters:
targetMethod- name of the method to be invoked onsetTargetObject(Object).
setArguments
public void setArguments(java.lang.Object[] arguments)
- Parameters:
arguments- arguments values for the {setTargetMethod(String). These will be used only when the subclass tries to invoke the target method without providing explicit argument values. If arguments are set to not-null valueafterPropertiesSet()will check the values are compatible with target method's signature. In case arguments are null (not set) method signature will not be checked and it is assumed correct values will be supplied at runtime.
getArguments
protected java.lang.Object[] getArguments()
Return arguments.- Returns:
- arguments