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.quartercode.classmod.extra.def.DefaultFunctionInvocation.java

/**
 * Returns wether the given {@link FunctionExecutorContext} is invocable.
 * For example, a {@link FunctionExecutor} which already exceeded its invocation limit is not invocable.
 * This can be overriden to modify which {@link FunctionExecutor}s should be invoked.
 * //from  w  ww. j  av a 2s.c om
 * @param executor The {@link FunctionExecutorContext} to check.
 * @return Wether the given {@link FunctionExecutorContext} is invocable.
 */
protected boolean isExecutorInvocable(FunctionExecutorContext<R> executor) {

    // Lockable
    try {
        Method invokeMethod = executor.getExecutor().getClass().getMethod("invoke", FunctionInvocation.class,
                Object[].class);
        if (executor.isLocked() || source.isLocked() && invokeMethod.isAnnotationPresent(Lockable.class)) {
            return false;
        }
    } catch (NoSuchMethodException e) {
        LOGGER.log(Level.SEVERE,
                "Programmer's fault: Can't find invoke() method (should be defined by interface)", e);
    }

    // Limit
    if (executor.getInvocations() + 1 > (Integer) executor.getValue(Limit.class, "value")) {
        return false;
    }

    // Delay
    int invocation = source.getInvocations() - 1;
    int firstDelay = (Integer) executor.getValue(Delay.class, "firstDelay");
    int delay = (Integer) executor.getValue(Delay.class, "delay");
    if (invocation < firstDelay) {
        return false;
    } else if (delay > 0 && (invocation - firstDelay) % (delay + 1) != 0) {
        return false;
    }

    return true;
}

From source file:org.apache.sling.performance.FrameworkPerformanceMethod.java

/**
 * Retrieve all the specific methods from test class
 *
 * @param testClass//from  w w w. j  a v  a 2s  .c  om
 *            the test class that we need to search in
 * @param annotation
 *            the annotation that we should look for
 * @return the list with the methods that have the specified annotation
 */
@SuppressWarnings({ "rawtypes" })
private Method[] getSpecificMethods(Class testClass, Class<? extends Annotation> annotation) {
    Method[] allMethods = testClass.getDeclaredMethods();

    List<Method> methodListResult = new ArrayList<Method>();

    for (Method testMethod : allMethods) {
        if (testMethod.isAnnotationPresent(annotation)) {
            methodListResult.add(testMethod);
        }
    }
    return methodListResult.toArray(new Method[] {});
}

From source file:com.evolveum.midpoint.repo.sql.query.definition.ClassDefinitionParser.java

private QName getJaxbName(Method method) {
    QName name = new QName(SchemaConstantsGenerated.NS_COMMON, getPropertyName(method.getName()));
    if (method.isAnnotationPresent(JaxbName.class)) {
        JaxbName jaxbName = method.getAnnotation(JaxbName.class);
        name = new QName(jaxbName.namespace(), jaxbName.localPart());
    }/*from   w  w w. j a v  a2s.  c o  m*/

    return name;
}

From source file:com.stehno.sjdbcx.reflection.ReflectionImplementationProvider.java

@Override
public void implement(final Method method) throws Exception {
    final OperationContext operationContext = applicationContext.getBean(OperationContext.class);
    final String sql = sqlResolver.resolve(prototype, method);

    final Operation operation;
    if (method.isAnnotationPresent(Implemented.class)) {
        operation = buildCustomOperation(method, sql, operationContext,
                method.getAnnotation(Implemented.class));

    } else {/*from  w w  w.j av  a 2  s .  c om*/
        operation = buildDefaultOperation(method, sql, operationContext, method.getAnnotation(Sql.class));
    }

    invocationHandler.addOperation(method, operation);
}

From source file:org.springmodules.xt.model.generator.factory.FactoryGeneratorInterceptor.java

private boolean isConstructorArg(Method method) {
    if (method.getName().startsWith("set") && method.isAnnotationPresent(ConstructorArg.class)) {
        return true;
    } else {/*from w w w  .  j  a  v  a  2 s . c o m*/
        return false;
    }
}

From source file:org.springmodules.xt.model.generator.factory.FactoryGeneratorInterceptor.java

private boolean isPropertySetter(Method method) {
    if (method.getName().startsWith("set") && method.isAnnotationPresent(Property.class)) {
        return true;
    } else {/*from  www. j av a2 s  .  c o m*/
        return false;
    }
}

From source file:org.springmodules.xt.model.generator.factory.FactoryGeneratorInterceptor.java

private boolean isValueSetter(Method method) {
    if (method.getName().startsWith("set") && method.isAnnotationPresent(Value.class)) {
        return true;
    } else {/*  w ww. j  ava  2 s . c  o m*/
        return false;
    }
}

From source file:org.jspare.server.jetty.JettyRouter.java

/**
 * Builds the and registry command map.// ww  w  . j av  a  2 s.  c o  m
 *
 * @param cmdClazz
 *            the cmd clazz
 */
private void buildAndRegistryCommandMap(Class<?> cmdClazz) {

    if (!isValidCommand(cmdClazz)) {

        throw new InvalidControllerException(
                String.format("Cannot find name Controller on class [%s]", cmdClazz.getName()));
    }

    for (

    Method method : cmdClazz.getDeclaredMethods()) {

        if (method.isAnnotationPresent(Command.class)) {

            CommandData cmdData = new CommandData(cmdClazz, method);
            addCommand(cmdData);

            if (cmdData.isStartCommand() && !cmdData.getCommand().equals(StringUtils.EMPTY)
                    && !cmdData.getCommand().equals(START_PATTERN)) {

                CommandData startCommand = cmdData.clone();
                startCommand.setCommand(START_PATTERN);
                addCommand(startCommand);
            }
        }
    }
}

From source file:test.automation.execution.TestExecutor.java

/**
 * Get all the methods marked with the given annotation in the given class.
 * @param testClass the test class./*  w ww .  j a va2  s. co  m*/
 * @param annotationClass the annotation class we're interested.
 * @return all the matching methods.
 */
private Set<Method> getTestableMethods(final Class testClass, final Class annotationClass) {
    final Set<Method> methods = new HashSet<Method>();

    for (final Method testMethod : testClass.getMethods()) {
        if (testMethod.isAnnotationPresent(annotationClass)) {
            methods.add(testMethod);
        }
    }

    return (methods);
}

From source file:org.vaadin.spring.events.internal.ScopedEventBus.java

private void subscribe(final Object listener, final String topic, final boolean includingPropagatingEvents,
        final boolean weakReference) {
    logger.trace(/*from w  ww.  j  av a  2s .  c  o m*/
            "Subscribing listener [{}] to event bus [{}], includingPropagatingEvents = {}, weakReference = {}",
            listener, this, includingPropagatingEvents, weakReference);

    final int[] foundMethods = new int[1];
    ClassUtils.visitClassHierarchy(new ClassUtils.ClassVisitor() {
        @Override
        public void visit(Class<?> clazz) {
            for (Method m : clazz.getDeclaredMethods()) {
                if (m.isAnnotationPresent(EventBusListenerMethod.class)) {
                    if (m.getParameterTypes().length == 1) {
                        logger.trace("Found listener method [{}] in listener [{}]", m.getName(), listener);
                        MethodListenerWrapper l = new MethodListenerWrapper(ScopedEventBus.this, listener,
                                topic, includingPropagatingEvents, m);
                        if (weakReference) {
                            listeners.addWithWeakReference(l);
                        } else {
                            listeners.add(l);
                        }
                        foundMethods[0]++;
                    } else {
                        throw new IllegalArgumentException(
                                "Listener method " + m.getName() + " does not have the required signature");
                    }
                }
            }
        }
    }, listener.getClass());

    if (foundMethods[0] == 0) {
        logger.warn("Listener [{}] did not contain a single listener method!", listener);
    }
}