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:fr.norad.jaxrs.oauth2.core.tck.spring.Hibernate5MethodValidationInterceptor.java

protected Class[] determineValidationGroups(MethodInvocation invocation) {
    Validated valid = AnnotationUtils.findAnnotation(invocation.getThis().getClass(), Validated.class);
    return (valid != null ? valid.value() : new Class[0]);
}

From source file:com.freebox.engeneering.application.system.webflow.spring.SpringFlowControllerContextLoader.java

/**
 * Scans beans annotated with State annotation and binds them to state context.
 *
 * @param context the spring application context
 *//*from   w  w  w. j a  v  a 2s  .  c  o  m*/
@SuppressWarnings("rawtypes")
public void load(ApplicationContext context) {
    long start = System.currentTimeMillis();
    final String[] beanDefinitionNames = context.getBeanDefinitionNames();
    for (String beanDefinitionName : beanDefinitionNames) {
        if (beanDefinitionName.endsWith("Context")) {
            final Object bean = context.getBean(beanDefinitionName);

            final Method[] methods = bean.getClass().getMethods();
            for (Method method : methods) {
                final State state = AnnotationUtils.findAnnotation(method, State.class);
                if (state != null) {
                    final String[] stateArray = state.value();
                    for (String stateName : stateArray) {
                        final Object bean1 = context.getBean(method.getName());
                        final Placeholder placeholder = AnnotationUtils.findAnnotation(method,
                                Placeholder.class);
                        if (placeholder != null) {
                            stateContext.bindController(stateName, placeholder.value(), method.getName());
                        }
                        if (bean1 instanceof LayoutController) {
                            stateContext.bindLayoutController(stateName, (LayoutController) bean1);
                        }
                    }
                }
            }
        }
    }
    long end = System.currentTimeMillis();
    LOGGER.info("took time: " + ((end - start) / 1000) + " seconds.");

}

From source file:com.cassius.spring.assembly.test.common.toolbox.ContextUtil.java

/**
 * Gets reuse spring context configure class.
 *
 * @param targetClass the target class//from ww  w  .j a v  a 2  s  . co  m
 * @return the reuse spring context configure class
 */
public static Class<?> getSpringContextCacheConfigureClass(Class<?> targetClass) {
    Class<?> declaringClass = AnnotationUtils.findAnnotationDeclaringClass(SpringAssemblyConfigure.class,
            targetClass);
    SpringAssemblyConfigure springAssemblyConfigure = AnnotationUtils.findAnnotation(targetClass,
            SpringAssemblyConfigure.class);
    if (declaringClass != null && springAssemblyConfigure != null
            && springAssemblyConfigure.reuseSpringContext()) {
        return declaringClass;
    }
    return targetClass;
}

From source file:py.una.pol.karaku.services.server.ServiceDefinitionRegister.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) {

    LOG.info("Registering @WebServices");
    String[] beans = bf.getBeanDefinitionNames();
    for (String s : beans) {
        Class<?> beanType = bf.getType(s);
        WebServiceDefinition ws = AnnotationUtils.findAnnotation(beanType, WebServiceDefinition.class);
        if (ws != null) {
            String name = getName(s);
            DefaultWsdl11Definition newWS = createWebService(name, ws.xsds());

            bf.registerSingleton(name, newWS);
            LOG.info("Web service: {} has been added", name);
        }/* w  w w .  ja  va2 s . c  o m*/
    }

}

From source file:ductive.stats.spring.StatsPostProcessor.java

@Override
public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
    ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() {
        @Override//from  www .ja v a 2 s . c om
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            Stats cmd = AnnotationUtils.findAnnotation(method, Stats.class);
            if (cmd == null)
                return;

            String[] path = ArrayUtils.addAll(prefix, cmd.value());
            statsProviderRegistry.register(path, bean, method);
        }
    });
    return bean;
}

From source file:com.excilys.ebi.spring.dbunit.test.RollbackTransactionalTestConfigurationProcessor.java

@Override
public DataSetConfiguration getConfiguration(TestContext testContext) {
    DataSetConfiguration configuration = null;

    final Method testMethod = testContext.getTestMethod();

    if (testMethod == null) { // beforeTestClass or afterTestClass

        configuration = configurationClassCache.get(testContext.getTestClass());

        if (configuration == null) {
            final DataSet dataSetAnnotation = AnnotationUtils.findAnnotation(testContext.getTestClass(),
                    DataSet.class);

            if (dataSetAnnotation != null) {
                LOGGER.debug("Configuring database at Class level");
                configuration = buildConfiguration(dataSetAnnotation, testContext);
                configurationClassCache.put(testContext.getTestClass(), configuration);
            }//from  w w w.j av a 2 s.  com
        }
    } else { // beforeTestMethod or afterTestMethod

        configuration = configurationCache.get(testMethod);
        if (configuration == null) {
            DataSet dataSetAnnotation = AnnotationUtils.findAnnotation(testContext.getTestMethod(),
                    DataSet.class);

            if (dataSetAnnotation != null) {
                LOGGER.debug("Configuring database at Method level");
                configuration = buildConfiguration(dataSetAnnotation, testContext);
                configurationCache.put(testContext.getTestMethod(), configuration);
            } else if (configurationClassCache.get(testContext.getTestClass()) == null) {
                LOGGER.info(
                        "DataSetTestExecutionListener was configured but without any DataSet or DataSets! DataSet features are disabled");
            }
        }
    }

    return configuration;
}

From source file:springfox.documentation.swagger.readers.operation.OperationImplicitParameterReader.java

protected List<Parameter> readParameters(OperationContext context) {
    HandlerMethod handlerMethod = context.getHandlerMethod();
    Method method = handlerMethod.getMethod();
    ApiImplicitParam annotation = AnnotationUtils.findAnnotation(method, ApiImplicitParam.class);
    List<Parameter> parameters = Lists.newArrayList();
    if (null != annotation) {
        parameters.add(OperationImplicitParameterReader.implicitParameter(annotation));
    }/*from   w  w  w.j  a va  2  s .  co  m*/
    return parameters;
}

From source file:de.otto.jsonhome.generator.SpringResourceLinkGenerator.java

/**
 * {@inheritDoc}//from ww w.ja  v  a 2 s.  c o m
 *
 * A method is a candidate if there is a RequestMapping annotation.
 *
 * @param method the current method of the controller.
 * @return true if method should be analysed
 */
@Override
public boolean isCandidateForAnalysis(final Method method) {
    return AnnotationUtils.findAnnotation(method, RequestMapping.class) != null;
}

From source file:ductive.console.commands.register.spring.ArgumentParserBeanPostProcessor.java

@Override
public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
    ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() {
        @Override// ww w. j  a  v a  2  s  . c  o m
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            ArgParser argParser = AnnotationUtils.findAnnotation(method, ArgParser.class);
            if (argParser == null)
                return;

            String qualifier = StringUtils.defaultIfEmpty(argParser.value(), null);

            if (!void.class.equals(argParser.bind())) {
                argParserRegistry.register(argParser.bind(), qualifier, bean, method);
                return;
            }

            Type genericReturnType = method.getGenericReturnType();
            Validate.isTrue(ParameterizedType.class.isInstance(genericReturnType),
                    String.format(
                            "method %s: return type of parser generator method must be a subclass of %s<?>",
                            method, Parser.class.getCanonicalName()));

            ParameterizedType pt = ParameterizedType.class.cast(genericReturnType);
            Validate.isTrue(Parser.class.isAssignableFrom((Class<?>) pt.getRawType()),
                    String.format(
                            "method %s: return type of parser generator method must be a subclass of %s<?>",
                            method, Parser.class.getCanonicalName()));

            Type[] genericParams = pt.getActualTypeArguments();
            Validate.isTrue(genericParams.length == 1);

            argParserRegistry.register((Class<?>) genericParams[0], qualifier, bean, method);
        }

    });
    return bean;
}

From source file:fr.gael.dhus.gwt.GWTWebapp.java

@Override
public void init() {
    this.name = "";
    this.servlets = new ArrayList<WebServlet>();
    this.welcomeFiles = new ArrayList<String>();

    servlets.add(new GWTClientWebServlet("home", "/home"));

    welcomeFiles.add("home");

    ClassPathScanningCandidateComponentProvider scan = new ClassPathScanningCandidateComponentProvider(false);
    scan.addIncludeFilter(new AnnotationTypeFilter(RPCService.class));
    logger.info("    Initializing RPC services");
    for (BeanDefinition bd : scan.findCandidateComponents("fr.gael.dhus.gwt.services")) {
        logger.info("     - service : " + bd.getBeanClassName());
        try {//from   w  ww.  j  av a 2 s.  c om
            Class<?> servletClass = GWTWebapp.class.getClassLoader().loadClass(bd.getBeanClassName());
            RPCService annotation = AnnotationUtils.findAnnotation(servletClass, RPCService.class);
            servlets.add(new RPCServlet((Servlet) (servletClass.newInstance()), annotation.value(),
                    "/" + annotation.value()));
        } catch (ClassNotFoundException e) {
            System.err.println("Cannot load service : '" + bd.getBeanClassName() + "'");
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}