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:com.luna.common.repository.support.SimpleBaseRepositoryFactoryBean.java

protected Object getTargetRepository(RepositoryMetadata metadata) {
    Class<?> repositoryInterface = metadata.getRepositoryInterface();

    if (isBaseRepository(repositoryInterface)) {

        JpaEntityInformation<M, ID> entityInformation = getEntityInformation(
                (Class<M>) metadata.getDomainType());
        SimpleBaseRepository 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   w ww . ja  va2 s. c o  m*/
            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());

        }

        return repository;
    }
    return super.getTargetRepository(metadata);
}

From source file:org.grails.datastore.mapping.model.config.DefaultMappingConfigurationStrategy.java

public boolean isPersistentEntity(Class javaClass) {
    return AnnotationUtils.findAnnotation(javaClass, Entity.class) != null;
}

From source file:com.expedia.seiso.domain.meta.ItemMetaImpl.java

public ItemMetaImpl(Class<?> itemClass, Class<?> repoInterface, boolean pagingRepo) {
    log.trace("Initializing resource mapping for {}", itemClass);

    this.itemClass = itemClass;
    this.itemRepoInterface = repoInterface;
    this.pagingRepo = pagingRepo;

    val ann = AnnotationUtils.findAnnotation(repoInterface, RestResource.class);
    if (ann != null) {
        this.exported = ann.exported();
        this.repoKey = ann.path();

        // Not sure this is how we want this to work, but LegacyItemLinks.linkToSingleResource() doesn't like null rels.
        boolean emptyRel = ("".equals(ann.rel()));
        this.rel = (emptyRel ? ann.path() : ann.rel());

        // TODO Take steps to ensure that neither repoKey nor rel is null.
    }//w ww.  j  a v  a2 s. c  o m

    // Initialize the findByKey method no matter whether we're exporting the repo or not. For instance, we don't
    // want to export the UserRepo, but we do want to be able to serialize and deserialize createdBy/updatedBy
    // users using the generic machinery. [WLW]
    initFindByKeyMethod();

    initProjections();
    initPropertyNames();
}

From source file:org.springjutsu.validation.context.ValidationContextHandlerContainer.java

/**
 * Finds the annotated context handlers by searching the bean factory.
 * Also registers XML-configured context handlers.
 * @throws BeansException on a bad./* w w w  .ja v  a  2s  .c  o m*/
 */
@PostConstruct
public void registerContextHandlers() throws BeansException {
    if (addDefaultContextHandlers) {
        addDefaultContextHandlers();
    }
    Map<String, Object> contextHandlerBeans = ((ListableBeanFactory) beanFactory)
            .getBeansWithAnnotation(ConfiguredContextHandler.class);

    for (String springName : contextHandlerBeans.keySet()) {
        ValidationContextHandler handler = (ValidationContextHandler) contextHandlerBeans.get(springName);
        String contextType = AnnotationUtils
                .findAnnotation(AopUtils.getTargetClass(handler), ConfiguredContextHandler.class).type();
        setCustomContextHandler(contextType, handler);
    }
    if (beanRegistrants != null) {
        for (KeyedBeanRegistrant registrant : beanRegistrants) {
            setCustomContextHandler(registrant.getKey(),
                    (ValidationContextHandler) beanFactory.getBean(registrant.getBeanName()));
        }
    }
}

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

@Override
public boolean supports(final Class<?> aClass) {
    boolean classLevelAnno = (null != AnnotationUtils.findAnnotation(aClass, Handler.class));
    final AtomicBoolean hasHandlerMethod = new AtomicBoolean(false);
    Class<?> clazz = aClass;
    while (null != clazz && clazz != Object.class) {
        ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
            @Override/*from  ww w  .j a v a2  s  .c o m*/
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                if (!hasHandlerMethod.get()) {
                    hasHandlerMethod.set(true);
                }
            }
        }, Handlers.USER_METHODS);
        clazz = clazz.getSuperclass();
    }

    return (hasHandlerMethod.get() || classLevelAnno);
}

From source file:org.jdal.aop.config.SerializableAnnotationBeanPostProcessor.java

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

    // Check for already serializable, infraestructure or serializable proxy targets.
    if (bean instanceof SerializableAopProxy || bean instanceof AopInfrastructureBean
            || beanName.startsWith(SerializableProxyUtils.TARGET_NAME_PREFIX))
        return bean;

    SerializableProxy ann = AnnotationUtils.findAnnotation(bean.getClass(), SerializableProxy.class);

    if (ann != null) {
        if (log.isDebugEnabled())
            log.debug("Creating serializable proxy for bean [" + beanName + "]");

        boolean proxyTargetClass = !beanFactory.getType(beanName).isInterface() || ann.proxyTargetClass();
        return SerializableProxyUtils.createSerializableProxy(bean, proxyTargetClass, ann.useCache(),
                beanFactory, beanName);/*from w  ww  .  j  a  v a  2 s  .c om*/
    }

    return bean;
}

From source file:guru.qas.martini.annotation.MartiniAnnotationCallback.java

protected void processAnnotation(Method method) {
    A annotation = AnnotationUtils.findAnnotation(method, annotationClass);
    if (null != annotation) {
        process(method, annotation);//  w  ww . ja  va 2 s  . c  o  m
    }
}

From source file:com.graby.store.base.remote.RemotingAnnotationHandlerMapping.java

/**
 * Checks for presence of the {@link org.springframework.web.bind.annotation.RequestMapping}
 * annotation on the handler class and on any of its methods.
 *///from  w ww. ja  va2  s. co  m
protected String[] determineUrlsForHandler(String beanName) {

    ApplicationContext context = getApplicationContext();
    Class<?> handlerType = context.getType(beanName);
    RemotingService mapping = AnnotationUtils.findAnnotation(handlerType, RemotingService.class);
    if (mapping == null && context instanceof ConfigurableApplicationContext
            && context.containsBeanDefinition(beanName)) {
        ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
        BeanDefinition bd = cac.getBeanFactory().getMergedBeanDefinition(beanName);
        if (bd instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
            if (abd.hasBeanClass()) {
                Class<?> beanClass = abd.getBeanClass();
                mapping = AnnotationUtils.findAnnotation(beanClass, RemotingService.class);
            }
        }
    }

    if (mapping != null) {
        this.cachedMappings.put(handlerType, mapping);
        Set<String> urls = new LinkedHashSet<String>();
        String path = mapping.serviceUrl();
        if (path != null) {
            addUrlsForPath(urls, path);
            return StringUtils.toStringArray(urls);
        } else {
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.cfr.capsicum.test.support.CayenneTestExecutionListener.java

private void initializeBeforeTestMethod(TestContext testContext) throws BeansException, Exception {
    Object instance = testContext.getTestInstance();
    Class<?> clazz = instance.getClass();
    CayenneRuntimeContext config = AnnotationUtils.findAnnotation(clazz, CayenneRuntimeContext.class);

    if (config == null) {
        if (logger.isInfoEnabled()) {
            logger.info(/*from  w  ww .  j ava  2s  .c  om*/
                    "@CayenneContextConfiguration is not present for class [" + clazz + "]: using defaults.");
        }
    } else {
        String name = config.name();
        context = testContext.getApplicationContext().getBean("&" + name, ICayenneRuntimeContext.class);
    }
}

From source file:org.jddd.jackson.SimpleValueObjectSerializerModifier.java

@Override
public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescription beanDesc,
        BeanSerializerBuilder builder) {

    for (BeanPropertyWriter writer : builder.getProperties()) {

        JavaType propertyType = writer.getMember().getType();
        Class<?> type = propertyType.getRawClass();
        List<BeanPropertyDefinition> properties = getProperties(propertyType, config);

        Optional.ofNullable(AnnotationUtils.findAnnotation(type, ValueObject.class))//
                .filter(it -> properties.size() == 1)//
                .flatMap(it -> properties.stream().findFirst())//
                .ifPresent(it -> writer.assignSerializer(new PropertyAccessingSerializer(it)));
    }/*from w w w .j a va 2  s  .c  o m*/

    return builder;
}