Example usage for org.springframework.batch.support ReflectionUtils findMethod

List of usage examples for org.springframework.batch.support ReflectionUtils findMethod

Introduction

In this page you can find the example usage for org.springframework.batch.support ReflectionUtils findMethod.

Prototype

@SuppressWarnings("rawtypes")
public static final Set<Method> findMethod(Class clazz, Class<? extends Annotation> annotationType) 

Source Link

Document

Returns a java.util.Set of java.lang.reflect.Method instances that are annotated with the annotation provided.

Usage

From source file:org.springframework.batch.core.step.builder.StepBuilderHelper.java

/**
 * Registers objects using the annotation based listener configuration.
 *
 * @param listener the object that has a method configured with listener annotation
 * @return this for fluent chaining/*from   ww w.j  av  a 2  s . co m*/
 */
public B listener(Object listener) {
    Set<Method> stepExecutionListenerMethods = new HashSet<Method>();
    stepExecutionListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), BeforeStep.class));
    stepExecutionListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), AfterStep.class));

    if (stepExecutionListenerMethods.size() > 0) {
        StepListenerFactoryBean factory = new StepListenerFactoryBean();
        factory.setDelegate(listener);
        properties.addStepExecutionListener((StepExecutionListener) factory.getObject());
    }

    @SuppressWarnings("unchecked")
    B result = (B) this;
    return result;
}