Example usage for org.springframework.core.annotation AnnotationUtils findAnnotation

List of usage examples for org.springframework.core.annotation AnnotationUtils findAnnotation

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotationUtils findAnnotation.

Prototype

@Nullable
public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType) 

Source Link

Document

Find a single Annotation of annotationType on the supplied Class , traversing its interfaces, annotations, and superclasses if the annotation is not directly present on the given class itself.

Usage

From source file:org.flywaydb.test.dbunit.DBUnitTestExecutionListener.java

/**
 * Only annotation with loadFiles will be executed
 *///from   w  w w  . ja v a 2s . c o m
public void beforeTestClass(final TestContext testContext) throws Exception {
    // no we check for the DBResetForClass
    final Class<?> testClass = testContext.getTestClass();
    // For convinience one may annotate tests superclass.
    final Annotation annotation = AnnotationUtils.findAnnotation(testClass, DBUnitSupport.class);
    if (annotation != null) {
        final DBUnitSupport dbUnitAnnotaton = (DBUnitSupport) annotation;

        loadFiles(testContext, dbUnitAnnotaton);
    }
}

From source file:org.bremersee.common.spring.autoconfigure.WebMvcExceptionResolver.java

boolean isRestController(Object handler) {
    if (handler == null) {
        return false;
    }//w ww. j ava2  s . co m
    final Class<?> cls = getHandlerClass(handler);
    final boolean result = AnnotationUtils.findAnnotation(cls, RestController.class) != null;
    if (log.isDebugEnabled()) {
        log.debug("Is handler [" + handler + "] a rest controller? " + result);
    }
    return result;
}

From source file:io.neba.core.selftests.SelftestRegistrar.java

/**
 * In case no annotation metadata exists, find selftests by checking all
 * methods for the {@link SelfTest} annotation.
 *///w w  w  . j a va2  s . c o m
private void findSelftestUsingReflection(final ConfigurableListableBeanFactory factory, final String beanName,
        final Bundle bundle) {
    Class<?> beanType = factory.getType(beanName);
    if (beanType != null) {
        beanType = unproxy(beanType);
        ReflectionUtils.doWithMethods(beanType, new MethodCallback() {
            @Override
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                SelfTest selfTest = AnnotationUtils.findAnnotation(method, SelfTest.class);
                if (selfTest != null) {
                    String methodName = method.getName();
                    selftestReferences
                            .add(new SelftestReference(factory, beanName, selfTest, methodName, bundle));
                }
            }
        });
    }
}

From source file:com.tyro.oss.pact.spring4.pact.provider.PactTestRunner.java

private PactFilter getPactFilter(Class<?> clazz) throws IllegalAccessException, InstantiationException {
    WithPactFilter withPactFilter = AnnotationUtils.findAnnotation(clazz, WithPactFilter.class);

    if (withPactFilter == null) {
        return new NoOpPactFilter();
    } else {/*from  w  w  w . j a  v a2 s. c  o m*/
        return withPactFilter.value().newInstance();
    }
}

From source file:com.acc.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java

protected <T extends Annotation> T findAnnotation(final HandlerMethod handlerMethod,
        final Class<T> annotationType) {
    // Search for method level annotation
    final T annotation = handlerMethod.getMethodAnnotation(annotationType);
    if (annotation != null) {
        return annotation;
    }/*  ww w .j  a  v  a2s .co m*/

    // Search for class level annotation
    return AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), annotationType);
}

From source file:org.craftercms.commons.ebus.config.EBusBeanAutoConfiguration.java

private void wireBean(final Object bean, final Set<Method> methods) {
    if (methods == null || methods.isEmpty()) {
        return;//from   w  ww .ja  v a 2s.c  o  m
    }

    EventHandler eventHandlerAnnotation;
    Observable reactor;
    Selector selector;
    Consumer consumer;

    for (Method method : methods) {
        // scanAnnotation method
        eventHandlerAnnotation = AnnotationUtils.findAnnotation(method, EventHandler.class);
        reactor = fetchObservable(eventHandlerAnnotation, bean);
        selector = fetchSelector(eventHandlerAnnotation, bean, method);

        // register consumer
        Invoker handler = new Invoker(bean, method, conversionService);
        consumer = new ServiceConsumer(handler);
        reactor.on(selector, consumer);
    }
}

From source file:com.revolsys.ui.web.rest.interceptor.WebAnnotationMethodHandlerAdapter.java

protected final void addReturnValueAsModelAttribute(final Method handlerMethod, final Class<?> handlerType,
        final Object returnValue, final ExtendedModelMap implicitModel) {

    final ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
    String attrName = attr != null ? attr.value() : "";
    if ("".equals(attrName)) {
        final Class<?> resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
        attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
    }//from   www.jav  a 2s  .  com
    implicitModel.addAttribute(attrName, returnValue);
}

From source file:net.phoenix.thrift.xml.ProcessorBeanDefinitionParser.java

/**
 * context-scan???Iface//from  www.  ja  va  2s.c o  m
 * serviceparserContext?serviceprocesor
 */
private Map<String, BeanDefinition> scanProcessors(ParserContext parserContext) {
    Map<String, BeanDefinition> processors = new HashMap<String, BeanDefinition>();
    for (String serviceName : parserContext.getRegistry().getBeanDefinitionNames()) {
        BeanDefinition serviceBeanDefinition = parserContext.getRegistry().getBeanDefinition(serviceName);
        Class<?> clazz;
        try {
            clazz = Class.forName(serviceBeanDefinition.getBeanClassName());
        } catch (ClassNotFoundException e) {
            throw new CannotLoadBeanClassException(parserContext.getReaderContext().getResource().getFilename(),
                    serviceName, serviceBeanDefinition.getBeanClassName(), e);
        }
        Processor annotation = AnnotationUtils.findAnnotation(clazz, Processor.class);
        if (annotation != null) {
            //processor class;
            Class<?> processorClass = annotation.processor();
            // build bean definition for processor;
            BeanDefinition processorBeanDefinition = this.createProcessorBean(processorClass, serviceName);
            processors.put(serviceName, processorBeanDefinition);
        }
    }
    return processors;
}

From source file:com.github.philippn.springremotingautoconfigure.client.annotation.HttpInvokerProxyFactoryBeanRegistrar.java

protected String getMappingPath(Class<?> clazz) {
    RemoteExport definition = AnnotationUtils.findAnnotation(clazz, RemoteExport.class);
    if (definition.mappingPath().length() > 0) {
        return definition.mappingPath();
    }//  ww w. java2s  .  c  o m
    return "/" + clazz.getSimpleName();
}

From source file:com.tyro.oss.pact.spring4.pact.provider.PactTestRunner.java

private PactResolver getPactResolver(Class<?> clazz) throws IllegalAccessException, InstantiationException {
    WithPactResolver withPactResolver = AnnotationUtils.findAnnotation(clazz, WithPactResolver.class);

    if (withPactResolver == null) {
        return new DefaultPactResolver();
    } else {//  w  w w.j  av a2s . c om
        return withPactResolver.value().newInstance();
    }
}