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:guru.qas.martini.annotation.MartiniAnnotationCallback.java

protected void processAnnotationContainer(Method method) {
    C container = AnnotationUtils.findAnnotation(method, annotationContainerClass);
    if (null != container) {
        A[] annotations = getValues(container);
        for (A annotation : annotations) {
            process(method, annotation);
        }/*  w  w  w. j  a  va  2 s.c  om*/
    }
}

From source file:com.nortal.petit.beanmapper.BeanMappingFactoryImpl.java

public String inferTable(Class<?> type) {
    Table table = AnnotationUtils.findAnnotation(type, Table.class);
    if (table != null && !StringUtils.isBlank(table.name())) {
        return (StringUtils.isNotBlank(table.schema()) ? (table.schema() + ".") : "") + table.name();
    }//from w w  w. ja  va2  s . c om
    return BeanMappingStringUtils.camelCaseToUnderscore(type.getSimpleName());
}

From source file:org.shredzone.commons.view.manager.ViewManager.java

/**
 * Sets up the view manager. All Spring beans are searched for {@link ViewHandler}
 * annotations.//  w ww  .  ja va2s  .  co  m
 */
@PostConstruct
protected void setup() {
    Collection<Object> beans = applicationContext.getBeansWithAnnotation(ViewHandler.class).values();
    for (Object bean : beans) {
        ViewHandler vhAnno = bean.getClass().getAnnotation(ViewHandler.class);
        if (vhAnno != null) {
            for (Method method : bean.getClass().getMethods()) {
                ViewGroup groupAnno = AnnotationUtils.findAnnotation(method, ViewGroup.class);
                if (groupAnno != null) {
                    for (View viewAnno : groupAnno.value()) {
                        processView(bean, method, viewAnno);
                    }
                }

                View viewAnno = AnnotationUtils.findAnnotation(method, View.class);
                if (viewAnno != null) {
                    processView(bean, method, viewAnno);
                }
            }
        }
    }

    patternMap.values().forEach(pm -> pm.values().forEach(Collections::sort));
    Collections.sort(patternOrder);
}

From source file:py.una.pol.karaku.test.util.transaction.DatabasePopulatorExecutionListener.java

@Override
public void beforeTestClass(TestContext testContext) throws Exception {

    super.beforeTestClass(testContext);

    final Sequences sequences = AnnotationUtils.findAnnotation(testContext.getTestClass(), Sequences.class);

    if ((sequences != null) && (sequences.value() != null) && (sequences.value().length > 0)) {
        DatabaseUtils.executeDDL(SEQUENCE_CONSTRUCTOR, getApplicationContext(testContext), sequences.value());
    }//from  www  .j  a v  a2  s . co m
}

From source file:com.dangdang.config.service.easyzk.ConfigFactory.java

@Override
public void afterPropertiesSet() throws Exception {
    Map<String, IObserver> watchers = context.getBeansOfType(IObserver.class, false, true);
    for (Map.Entry<String, IObserver> entry : watchers.entrySet()) {
        IObserver watcher = entry.getValue();
        Notify notify = AnnotationUtils.findAnnotation(watcher.getClass(), Notify.class);
        if (notify != null) {
            String group = notify.group();
            String key = notify.key();
            if (!Strings.isNullOrEmpty(group)) {
                CompositeObserver compositeObserver = compositeObserverMap.get(group);
                if (compositeObserver == null) {
                    compositeObserverMap.put(group, new CompositeObserver(group, executorService));
                    compositeObserver = compositeObserverMap.get(group);
                }/* www .ja  va  2 s.c  om*/

                String groupKey = group;
                if (!Strings.isNullOrEmpty(key)) {
                    groupKey += "." + key;
                }
                compositeObserver.addWatchers(groupKey, watcher);
            }
        }
    }
}

From source file:org.makersoft.mvc.method.annotation.RESTfulMappingHandlerMapping.java

/**
 * {@inheritDoc} /* w w  w .  j  a  v  a2s. c  o  m*/
 * Expects a handler to have a type-level @{@link Controller} annotation.
 */
@Override
protected boolean isHandler(Class<?> beanType) {
    return AnnotationUtils.findAnnotation(beanType, Controller.class) != null;
}

From source file:com.conversantmedia.mapreduce.mrunit.UnitTestDistributedResourceManager.java

@SuppressWarnings("unchecked")
protected void addDistributedProperties(Class<?> clazz, List<String> properties) {
    Distribute distribute;/* w  w w  . java2  s  .  co m*/
    MaraAnnotationUtil util = MaraAnnotationUtil.INSTANCE;
    List<Field> fields = util.findAnnotatedFields(clazz, Distribute.class);
    for (Field field : fields) {
        distribute = field.getAnnotation(Distribute.class);
        String prop = StringUtils.isBlank(distribute.name()) ? field.getName() : distribute.name();
        properties.add(prop);
    }

    List<Method> methods = util.findAnnotatedMethods(clazz, Distribute.class);
    for (Method method : methods) {
        distribute = AnnotationUtils.findAnnotation(method, Distribute.class);
        String defaultName = StringUtils.uncapitalize(StringUtils.removeStart(method.getName(), "get"));
        String prop = StringUtils.isBlank(distribute.name()) ? defaultName : distribute.name();
        properties.add(prop);
    }
}

From source file:us.swcraft.springframework.cache.aerospike.config.annotation.AerospikeCacheConfiguration.java

public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> enableAttrMap = importMetadata
            .getAnnotationAttributes(EnableAerospikeCacheManager.class.getName());
    AnnotationAttributes enableAttrs = AnnotationAttributes.fromMap(enableAttrMap);
    if (enableAttrs == null) {
        // search parent classes
        Class<?> currentClass = ClassUtils.resolveClassName(importMetadata.getClassName(), beanClassLoader);
        for (Class<?> classToInspect = currentClass; classToInspect != null; classToInspect = classToInspect
                .getSuperclass()) {//from  w  w  w. j  av  a 2s  .  c  o m
            EnableAerospikeCacheManager enableWebSecurityAnnotation = AnnotationUtils
                    .findAnnotation(classToInspect, EnableAerospikeCacheManager.class);
            if (enableWebSecurityAnnotation == null) {
                continue;
            }
            enableAttrMap = AnnotationUtils.getAnnotationAttributes(enableWebSecurityAnnotation);
            enableAttrs = AnnotationAttributes.fromMap(enableAttrMap);
        }
    }
    defaultTimeToLiveInSeconds = enableAttrs.getNumber("defaultTimeToLiveInSeconds");
    defaultNamespace = enableAttrs.getString("defaultNamespace");
    defaultCacheName = enableAttrs.getString("defaultCacheName");
    compression = enableAttrs.getEnum("compression");
    serializerClass = enableAttrs.getClass("serializerClass");

    cachesConfiguration = enableAttrs.getAnnotationArray("caches");
}

From source file:com.griddynamics.banshun.web.ContextParentAnnotationHandlerMapping.java

protected void validateHandler(Object handler, HttpServletRequest request) throws Exception {
    RequestMapping mapping = this.cachedMappings.get(handler.getClass());
    if (mapping == null) {
        mapping = AnnotationUtils.findAnnotation(handler.getClass(), RequestMapping.class);
    }/*from w w w.  j a  va 2 s  .  c  om*/
    if (mapping != null) {
        validateMapping(mapping, request);
    }
}

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

private Object createRemotingBean(Object bean) {
    Object resultBean = bean;//from   ww w.  j a va 2s .co m
    RemotingService service = AnnotationUtils.findAnnotation(bean.getClass(), RemotingService.class);
    if (service != null) {
        RemotingServiceExporter serviceExporter = new RemotingServiceExporter();
        serviceExporter.setService(bean);
        serviceExporter.setServiceInterface(service.serviceInterface());
        serviceExporter.afterPropertiesSet();
        resultBean = serviceExporter;
    }
    return resultBean;
}