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:cn.guoyukun.spring.web.controller.BaseController.java

protected String defaultViewPrefix() {
    String currentViewPrefix = "";
    RequestMapping requestMapping = AnnotationUtils.findAnnotation(getClass(), RequestMapping.class);
    if (requestMapping != null && requestMapping.value().length > 0) {
        currentViewPrefix = requestMapping.value()[0];
    }//from w  w w  .j  a  v  a 2  s  .  c  o m

    if (StringUtils.isEmpty(currentViewPrefix)) {
        currentViewPrefix = this.entityClass.getSimpleName();
    }

    return currentViewPrefix;
}

From source file:fr.putnami.pwt.plugin.spring.rpc.server.service.CommandServiceImpl.java

private void scanBean(Object bean, String name) {
    Class<?> implClass = bean.getClass();
    if (AopUtils.isAopProxy(bean)) {
        implClass = AopUtils.getTargetClass(bean);
    }/*from  www .  jav  a 2 s.c  om*/
    Service serviceAnnotation = AnnotationUtils.findAnnotation(implClass, Service.class);
    if (serviceAnnotation != null) {
        for (Class<?> inter : implClass.getInterfaces()) {
            this.injectService(inter, bean);
        }
    }
}

From source file:com.epam.ta.reportportal.database.fixture.SpringFixtureRule.java

/**
 * Looking for {@link SpringFixture} annotation on test method and test
 * class/*from  w w w . j a va 2  s  .  c  o m*/
 * 
 * @param description
 * @return
 */
private SpringFixture getFixtureAnnotation(Description description) {
    SpringFixture fixture = null;
    try {
        Class<?> testClass = description.getTestClass();

        Method method = testClass.getDeclaredMethod(description.getMethodName());

        /* Try to find fixture on method */
        fixture = method.getAnnotation(SpringFixture.class);

        /*
         * if method is not annotated tries to find annotation on test class
         */
        if (!isTestAnnotated(fixture)) {
            fixture = AnnotationUtils.findAnnotation(testClass, SpringFixture.class);

        }

    } catch (Exception e) {
        Throwables.propagate(e);
    }

    if (null == fixture) {
        throw new RuntimeException("You should put 'Fixture' annotation on test class or test method");
    }
    return fixture;

}

From source file:io.dyn.core.handler.Handlers.java

public static String findEventName(Method method) {
    On on = find(On.class, method);
    if (null != on) {
        return on.value();
    } else if (null != AnnotationUtils.findAnnotation(method.getDeclaringClass(), Handler.class)) {
        return method.getName();
    }//from w  ww  .ja va2 s.c  o m
    return null;
}

From source file:cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepositoryFactoryBean.java

private Object doGetTargetRepository(RepositoryMetadata metadata) {
    Class<?> repositoryInterface = metadata.getRepositoryInterface();
    JpaEntityInformation<M, ID> entityInformation = getEntityInformation((Class<M>) metadata.getDomainType());
    SimpleBaseRepository<M, ID> repository = new SimpleBaseRepository<M, ID>(entityInformation, entityManager);

    SearchableQuery searchableQuery = AnnotationUtils.findAnnotation(repositoryInterface,
            SearchableQuery.class);
    if (searchableQuery != null) {
        String countAllQL = searchableQuery.countAllQuery();
        if (!StringUtils.isEmpty(countAllQL)) {
            repository.setCountAllQL(countAllQL);
        }/*from  ww w. j  av  a  2  s. c  om*/
        String findAllQL = searchableQuery.findAllQuery();
        if (!StringUtils.isEmpty(findAllQL)) {
            repository.setFindAllQL(findAllQL);
        }
        Class<? extends SearchCallback> callbackClass = searchableQuery.callbackClass();
        if (callbackClass != null && callbackClass != SearchCallback.class) {
            repository.setSearchCallback(BeanUtils.instantiate(callbackClass));
        }

        repository.setJoins(searchableQuery.joins());

    }
    LOG.debug("?DAO {}", repository);
    return repository;
}

From source file:com.nec.harvest.resolver.AuthenticatedArgumentResolver.java

/**
 * Obtains the specified {@link java.lang.annotation.Annotation} on the specified {@link org.springframework.core.MethodParameter}.
 *
 * @param annotationClass the class of the {@link java.lang.annotation.Annotation} to find on the {@link org.springframework.core.MethodParameter}
 * @param parameter the {@link org.springframework.core.MethodParameter} to search for an {@link java.lang.annotation.Annotation}
 * @return the {@link java.lang.annotation.Annotation} that was found or null.
 *//*from w w w  . ja v a2  s  .com*/
private <T extends Annotation> T findMethodAnnotation(Class<T> annotationClass, MethodParameter parameter) {
    T annotation = parameter.getParameterAnnotation(annotationClass);
    if (annotation != null) {
        return annotation;
    }

    Annotation[] annotationsToSearch = parameter.getParameterAnnotations();
    for (Annotation toSearch : annotationsToSearch) {
        annotation = AnnotationUtils.findAnnotation(toSearch.annotationType(), annotationClass);
        if (annotation != null) {
            return annotation;
        }
    }
    return null;
}

From source file:org.shredzone.cilla.plugin.social.manager.SocialHandlerManager.java

/**
 * Sets up the manager. All beans are scanned for {@link SocialHandler} annotations.
 * If found, {@link SocialBookmark} annotations will further describe the social
 * bookmark service.//from   w ww .  j  ava 2  s  .  co  m
 */
@PostConstruct
public void setup() {
    Set<String> blacklistSet = Arrays.stream(blacklist.split("[,;]+")).map(String::trim)
            .filter(it -> !it.isEmpty()).collect(Collectors.toSet());

    Collection<Object> beans = applicationContext.getBeansWithAnnotation(SocialHandler.class).values();
    for (Object bean : beans) {
        SocialHandler shAnno = bean.getClass().getAnnotation(SocialHandler.class);
        if (shAnno != null) {
            for (Method method : bean.getClass().getMethods()) {
                SocialBookmark bookmarkAnno = AnnotationUtils.findAnnotation(method, SocialBookmark.class);
                if (bookmarkAnno != null) {
                    processBookmarkHandler(bean, method, bookmarkAnno, blacklistSet);
                }
            }
        }
    }
}

From source file:fi.helsinki.opintoni.exception.GlobalExceptionHandlers.java

@ExceptionHandler(value = Exception.class)
public ResponseEntity<CommonError> handleException(Exception e) throws Exception {
    // Only log a brief info message on broken pipes
    if (StringUtils.containsIgnoreCase(ExceptionUtils.getRootCauseMessage(e), "Broken pipe")) {
        LOGGER.info("Broken pipe occurred");
        return null;
    }//from  w  w  w  .j  a v a 2  s. com

    // If the exception is annotated with @ResponseStatus, rethrow it for other handlers
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;
    }

    LOGGER.error("Caught exception", e);

    return new ResponseEntity<>(new CommonError("Something went wrong"), HttpStatus.INTERNAL_SERVER_ERROR);
}

From source file:com.liferay.portal.spring.extender.internal.bean.ApplicationContextServicePublisher.java

protected Dictionary<String, Object> getBeanProperties(String symbloicName, Object object) {

    HashMapDictionary<String, Object> properties = new HashMapDictionary<>();

    properties.put("origin.bundle.symbolic.name", symbloicName);

    Class<? extends Object> clazz = null;

    try {//from  w  w  w.j a  v a2  s  .  c  o  m
        clazz = getTargetClass(object);
    } catch (Exception e) {
        return properties;
    }

    OSGiBeanProperties osgiBeanProperties = AnnotationUtils.findAnnotation(clazz, OSGiBeanProperties.class);

    if (osgiBeanProperties == null) {
        return properties;
    }

    properties.putAll(OSGiBeanProperties.Convert.toMap(osgiBeanProperties));

    return properties;
}