Example usage for java.lang.reflect Method isAnnotationPresent

List of usage examples for java.lang.reflect Method isAnnotationPresent

Introduction

In this page you can find the example usage for java.lang.reflect Method isAnnotationPresent.

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:com.feilong.core.lang.annotation.AnnotationTest.java

/**
 * TestAnnotationTest./*  w ww.jav  a 2 s .c om*/
 */
@Test
public void testAnnotationTest() {
    LOGGER.debug("" + AnnotationTest.class.isAnnotationPresent(MyAnnotation.class));

    MyAnnotation myAnnotation = AnnotationTest.class.getAnnotation(MyAnnotation.class);
    LOGGER.debug(myAnnotation.name());

    // *************************************************************
    Method[] methods = AnnotationTest.class.getDeclaredMethods();
    for (Method method : methods) {
        if (method.isAnnotationPresent(MyAnnotation.class)) {
            LOGGER.debug("[Test." + method.getName() + "].annotation:");
            MyAnnotation fieldAnnotation = method.getAnnotation(MyAnnotation.class);
            LOGGER.debug(ArrayUtils.toString(fieldAnnotation.loveStrings()));
        }
    }
}

From source file:com.feilong.commons.core.lang.annotation.AnnotationTest.java

/**
 * TestAnnotationTest.//  ww  w . ja v a 2s .c o  m
 */
@Test
public void testAnnotationTest() {
    log.info("" + AnnotationTest.class.isAnnotationPresent(MyAnnotation.class));

    MyAnnotation myAnnotation = AnnotationTest.class.getAnnotation(MyAnnotation.class);
    log.info(myAnnotation.name());

    // *************************************************************
    Method[] methods = AnnotationTest.class.getDeclaredMethods();
    for (Method method : methods) {
        if (method.isAnnotationPresent(MyAnnotation.class)) {
            log.info("[Test." + method.getName() + "].annotation:");
            MyAnnotation fieldAnnotation = method.getAnnotation(MyAnnotation.class);
            log.info(ArrayUtils.toString(fieldAnnotation.loveStrings()));
        }
    }
}

From source file:net.ymate.platform.core.beans.intercept.InterceptAnnoHelper.java

public static List<Class<? extends IInterceptor>> getAfterIntercepts(Class<?> targetClass,
        Method targetMethod) {
    List<Class<? extends IInterceptor>> _classes = new ArrayList<Class<? extends IInterceptor>>();
    if (targetClass.isAnnotationPresent(After.class)) {
        After _after = targetClass.getAnnotation(After.class);
        Clean _clean = getCleanIntercepts(targetMethod);
        ////  w  w w. ja v  a  2s .  co  m
        if (_clean != null && (_clean.type().equals(IInterceptor.CleanType.ALL)
                || _clean.type().equals(IInterceptor.CleanType.AFTER))) {
            if (_clean.value().length > 0) {
                for (Class<? extends IInterceptor> _clazz : _after.value()) {
                    if (ArrayUtils.contains(_clean.value(), _clazz)) {
                        continue;
                    }
                    _classes.add(_clazz);
                }
            }
        } else {
            Collections.addAll(_classes, _after.value());
        }
    }
    //
    if (targetMethod.isAnnotationPresent(After.class)) {
        Collections.addAll(_classes, targetMethod.getAnnotation(After.class).value());
    }
    //
    return _classes;
}

From source file:net.ymate.platform.core.beans.intercept.InterceptAnnoHelper.java

public static List<Class<? extends IInterceptor>> getBeforeIntercepts(Class<?> targetClass,
        Method targetMethod) {
    List<Class<? extends IInterceptor>> _classes = new ArrayList<Class<? extends IInterceptor>>();
    if (targetClass.isAnnotationPresent(Before.class)) {
        Before _before = targetClass.getAnnotation(Before.class);
        Clean _clean = getCleanIntercepts(targetMethod);
        //// w w  w.j  av  a2 s. co m
        if (_clean != null && (_clean.type().equals(IInterceptor.CleanType.ALL)
                || _clean.type().equals(IInterceptor.CleanType.BEFORE))) {
            if (_clean.value().length > 0) {
                for (Class<? extends IInterceptor> _clazz : _before.value()) {
                    if (ArrayUtils.contains(_clean.value(), _clazz)) {
                        continue;
                    }
                    _classes.add(_clazz);
                }
            }
        } else {
            Collections.addAll(_classes, _before.value());
        }
    }
    //
    if (targetMethod.isAnnotationPresent(Before.class)) {
        Collections.addAll(_classes, targetMethod.getAnnotation(Before.class).value());
    }
    //
    return _classes;
}

From source file:org.zalando.stups.boot.eventbus.EventBusSubscriberBeanPostProcessor.java

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

    for (Method m : bean.getClass().getMethods()) {
        if (m.isAnnotationPresent(Subscribe.class)) {
            logger.info("register bean as subscriber");
            this.eventBus.register(bean);
            this.asyncEventBus.register(bean);
            break;
        }//w  w w.  j ava2s .c  o  m
    }

    return bean;
}

From source file:com.github.tddts.jet.config.spring.postprocessor.EventBusBeanPostProcessor.java

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

    Pair<Class<?>, Object> typeObjectPair = SpringUtil.checkForDinamicProxy(bean);
    Class<?> type = typeObjectPair.getLeft();
    Object target = typeObjectPair.getRight();

    for (Method method : type.getDeclaredMethods()) {

        if (method.isAnnotationPresent(Subscribe.class)) {
            eventBus.register(target);/*w w w .  j  a  va 2 s  . com*/
            logger.debug("Bean registered to EventBus: [" + beanName + "]");
            return bean;
        }
    }
    return bean;
}

From source file:com.google.code.rees.scope.spring.SpringConversationArbitrator.java

@Override
protected boolean isAction(Method method) {
    return method.isAnnotationPresent(RequestMapping.class);
}

From source file:org.nuxeo.cm.web.invalidations.CaseManagementContextInterceptor.java

protected void beforeInvocation(InvocationContext invocationContext) {
    Object target = invocationContext.getTarget();
    for (Method meth : target.getClass().getMethods()) {
        if (meth.isAnnotationPresent(CaseManagementContextChecker.class)) {
            try {
                meth.invoke(target, getCaseManagementContextHolder());
            } catch (ReflectiveOperationException e) {
                log.error("Error during Invalidation method call", e);
            }/*from   www .j  a  v a2s . com*/
        }
    }
}

From source file:org.LexGrid.LexBIG.caCore.applicationservice.resource.RemoteResourceManager.java

private boolean doMethodsContainClientSideSafeAnnotation(Class<?> clazz) {
    for (Method method : clazz.getMethods()) {
        if (method.isAnnotationPresent(LgClientSideSafe.class)) {
            LgClientSideSafe css = method.getAnnotation(LgClientSideSafe.class);
            if (css.force()) {
                return true;
            }//from   w w w.j ava  2  s.  c o  m
        }
    }
    return false;
}

From source file:org.apache.pig.JVMReuseManager.java

public void registerForStaticDataCleanup(Class<?> clazz) {
    for (Method method : clazz.getMethods()) {
        if (method.isAnnotationPresent(StaticDataCleanup.class)) {
            if (!(Modifier.isStatic(method.getModifiers()) && Modifier.isPublic(method.getModifiers()))) {
                throw new RuntimeException("Method " + method.getName() + " in class " + clazz.getName()
                        + "should be public and static as it is annotated with  ");
            }// w  w w.  j  ava2s  .  c  o m
            LOG.debug("Method " + method.getName() + " in class " + method.getDeclaringClass()
                    + " registered for static data cleanup");
            instance.cleanupMethods.add(method);
        }
    }
}