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.googlecode.android_scripting.activity.ApiBrowser.java

private void updateAndFilterMethodDescriptors(final String query) {
    mMethodDescriptors = Lists.newArrayList(Collections2.filter(FacadeConfiguration.collectMethodDescriptors(),
            new Predicate<MethodDescriptor>() {
                @Override//from   w  w  w  .  j  av a 2 s  .c om
                public boolean apply(MethodDescriptor descriptor) {
                    Method method = descriptor.getMethod();
                    if (method.isAnnotationPresent(RpcDeprecated.class)) {
                        return false;
                    } else if (method.isAnnotationPresent(RpcMinSdk.class)) {
                        int requiredSdkLevel = method.getAnnotation(RpcMinSdk.class).value();
                        if (FacadeConfiguration.getSdkLevel() < requiredSdkLevel) {
                            return false;
                        }
                    }
                    if (query == null) {
                        return true;
                    }
                    return descriptor.getName().toLowerCase().contains(query.toLowerCase());
                }
            }));
}

From source file:org.tinygroup.springmvc.coc.impl.AbstractConventionHandlerMethodResolver.java

public Set<String> resolve() {
    final Set<String> urlList = new HashSet<String>();// for this handler
    String className = handlerType.getName();
    // //from w  w  w .ja v a  2  s .c  o m
    final StringBuilder uri = new StringBuilder("/");
    int lastpos = className.indexOf("." + conventionHelper.getHandlerStyle());
    int startpos = className.indexOf("web.");
    startpos += 5;
    String path = StringUtils.EMPTY;
    if (startpos < lastpos) {
        path = StringUtils.substring(className, startpos, lastpos);
        path = path.replace(".", "/");
        uri.append(path).append("/");
    }
    // uri-prefix. => /namespace/
    String resourcesName = conventionHelper.getHandlerName(getHandlerType());
    uri.append(resourcesName);

    ReflectionUtils.doWithMethods(getHandlerType(), new ReflectionUtils.MethodCallback() {
        public void doWith(Method method) {
            if (!qualify(method)) {
                return;
            }
            // method should be public.
            if (!Modifier.isPublic(method.getModifiers())) {
                return;
            }
            if (method.isAnnotationPresent(RequestMapping.class)) {
                return;
            } else if (method.isAnnotationPresent(InitBinder.class)) {
                return;
            } else if (method.isAnnotationPresent(ModelAttribute.class)) {
                return;
            } else {
                List<String> urls = doResolve(uri.toString(), method);
                if (!CollectionUtil.isEmpty(urls)) {
                    for (String url : urls) {
                        urlList.add(url);
                    }
                }
            }
        }
    }, new MethodFilter() {
        // ==object.class
        public boolean matches(Method method) {
            return method.getDeclaringClass() != Object.class;
        }

    });
    return urlList;
}

From source file:de.eidottermihi.rpicheck.activity.CustomCommandActivity.java

private String getValueViaReflection(RaspberryDeviceBean device, String accessor) {
    for (Method method : device.getClass().getMethods()) {
        if (method.isAnnotationPresent(Exported.class)) {
            if (method.getName().replaceFirst("get", "").toLowerCase().equals(accessor.toLowerCase())) {
                try {
                    Object result = method.invoke(device, new Object[] {});
                    if (result != null) {
                        return result.toString();
                    }//from  w  ww .j a  v  a2  s . co m
                } catch (IllegalAccessException e) {
                } catch (InvocationTargetException e) {
                }
            }
        }
    }
    LOGGER.debug("No getter found on DeviceBean. Property is not present.");
    return null;
}

From source file:org.kuali.kra.proposaldevelopment.rules.CreditSplitValidator.java

/**
 * Discover the name of a {@link CreditSplitable}. Not all {@link CreditSplitable} instances will have a <code>name</code> property. Even if they
 * did, it's not likely for all the properties to be called <code>name</code>. {@link CreditSplitable} relies on a property to be annotated
 * as being the name of the {@link CreditSplitable}. This checks for that annotation and returns the name. 
 * /*from   w  w  w  . j a  v a  2  s  .  co  m*/
 * 
 * @param splitable 
 * @return <code>null</code> if the name could not be found or if the value of the name is also <code>null</code>; otherwise, the name is returned.
 */
private String getCreditSplitableName(CreditSplitable splitable) {

    for (Method method : splitable.getClass().getMethods()) {
        if (method.isAnnotationPresent(CreditSplitNameInfo.class)) {
            LOG.info("Found method name " + method.getName());
            try {
                return (String) method.invoke(splitable, null);
            } catch (Exception e) {
                LOG.warn("Could not find the name property for the credit splitable object of class "
                        + splitable.getClass().getName() + ". Make sure the "
                        + CreditSplitNameInfo.class.getSimpleName()
                        + " annotation is declared on the name property of "
                        + splitable.getClass().getSimpleName());

            }
        }
    }

    return null;
}

From source file:com.googlecode.jsonschema2pojo.integration.EnumIT.java

@Test
public void enumContainsWorkingAnnotatedSerializationMethod() throws NoSuchMethodException {

    Method toString = enumClass.getMethod("toString");

    assertThat(enumClass.getEnumConstants()[0].toString(), is("one"));
    assertThat(enumClass.getEnumConstants()[1].toString(), is("secondOne"));
    assertThat(enumClass.getEnumConstants()[2].toString(), is("3rd one"));

    assertThat(toString.isAnnotationPresent(JsonValue.class), is(true));

}

From source file:net.paoding.rose.jade.statement.UpdateQuerier.java

public UpdateQuerier(DataAccessFactory dataAccessProvider, StatementMetaData metaData) {
    this.dataAccessProvider = dataAccessProvider;
    Method method = metaData.getMethod();
    // ?//from   w w w . j a va2  s .com
    Class<?> returnType = method.getReturnType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    this.returnType = returnType;
    if (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class))) {
        returnGeneratedKeys = true;
    } else {
        returnGeneratedKeys = false;
    }
}

From source file:org.b3log.latke.servlet.handler.AdviceHandler.java

/**
 * get AfterRequestProcessAdvice from annotation.
 *
 * @param invokeHolder the real invoked method
 * @param processorClass the class of the invoked methond
 * @return the list of AfterRequestProcessAdvice
 *///from   w ww.j  a va2s  .c o  m
private List<Class<? extends AfterRequestProcessAdvice>> getAfterList(final Method invokeHolder,
        final Class<?> processorClass) {
    // after invoke(first method before advice and then class before advice).
    final List<Class<? extends AfterRequestProcessAdvice>> afterAdviceClassList = new ArrayList<Class<? extends AfterRequestProcessAdvice>>();

    if (invokeHolder.isAnnotationPresent(After.class)) {
        final Class<? extends AfterRequestProcessAdvice>[] ac = invokeHolder.getAnnotation(After.class)
                .adviceClass();

        afterAdviceClassList.addAll(Arrays.asList(ac));
    }

    if (processorClass.isAnnotationPresent(After.class)) {
        final Class<? extends AfterRequestProcessAdvice>[] ac = processorClass.getAnnotation(After.class)
                .adviceClass();

        afterAdviceClassList.addAll(Arrays.asList(ac));
    }

    return afterAdviceClassList;
}

From source file:podd.dataaccess.hibernate.DeadlockInterceptorUnitTest.java

private void checkOneMethod(Method mtd) throws Exception {
    StringWriter writer = new StringWriter();

    // FIXME: Should not be doing this in code
    Appender appender = new WriterAppender(new SimpleLayout(), writer);
    LOGGER.addAppender(appender);/*w  w w . j a v  a2  s. c  o m*/

    try {
        if (mtd.isAnnotationPresent(Idempotent.class)) {
            Object[] params = new Object[] { null };
            try {
                mtd.invoke(dao, params);
            } catch (Exception e) {
                if (!interceptor.getExceptionClass().isInstance(e.getCause())) {
                    throw e;
                }
            }
            checkInterceptorLog(writer, null);
        }
    } finally {
        LOGGER.removeAppender(appender);
    }
}

From source file:net.ymate.platform.webmvc.WebMVC.java

public boolean registerController(Class<? extends Controller> targetClass) throws Exception {
    boolean _isValid = false;
    for (Method _method : targetClass.getDeclaredMethods()) {
        if (_method.isAnnotationPresent(RequestMapping.class)) {
            RequestMeta _meta = new RequestMeta(this, targetClass, _method);
            __mappingParser.registerRequestMeta(_meta);
            ////from   ww w. j a  va  2  s .  c  o  m
            if (__owner.getConfig().isDevelopMode()) {
                _LOG.debug("--> " + _meta.getAllowMethods() + ": " + _meta.getMapping() + " : "
                        + _meta.getTargetClass().getName());
            }
            //
            _isValid = true;
        }
    }
    //
    if (_isValid) {
        if (targetClass.getAnnotation(Controller.class).singleton()) {
            __owner.registerBean(BeanMeta.create(targetClass.newInstance(), targetClass));
        } else {
            __owner.registerBean(BeanMeta.create(targetClass));
        }
    }
    return _isValid;
}

From source file:org.jolokia.converter.json.BeanExtractor.java

private List<String> extractBeanAttributes(Object pValue) {
    List<String> attrs = new ArrayList<String>();
    for (Method method : pValue.getClass().getMethods()) {
        if (!Modifier.isStatic(method.getModifiers()) && !IGNORE_METHODS.contains(method.getName())
                && !isIgnoredType(method.getReturnType()) && !method.isAnnotationPresent(Transient.class)) {
            addAttributes(attrs, method);
        }//w  w  w  .  j av a2s .c  om
    }
    return attrs;
}