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:org.shredzone.cilla.web.fragment.manager.FragmentManager.java

/**
 * Sets up the {@link FragmentManager} after construction.
 *//*from   ww  w  .  j  av  a2  s .  co  m*/
@PostConstruct
protected void setup() {
    Collection<Object> beans = applicationContext.getBeansWithAnnotation(FragmentRenderer.class).values();
    for (Object bean : beans) {
        FragmentRenderer fhAnno = bean.getClass().getAnnotation(FragmentRenderer.class);
        if (fhAnno != null) {
            for (Method method : bean.getClass().getMethods()) {
                Fragment fragmentAnno = AnnotationUtils.findAnnotation(method, Fragment.class);
                if (fragmentAnno != null) {
                    processFragment(bean, method, fragmentAnno);
                }
            }
        }
    }
}

From source file:ch.ralscha.extdirectspring.util.MethodInfo.java

public MethodInfo(Class<?> clazz, ApplicationContext context, String beanName, Method method) {

    ExtDirectMethod extDirectMethodAnnotation = AnnotationUtils.findAnnotation(method, ExtDirectMethod.class);

    this.type = extDirectMethodAnnotation.value();

    if (extDirectMethodAnnotation.jsonView() != ExtDirectMethod.NoJsonView.class) {
        this.jsonView = extDirectMethodAnnotation.jsonView();
    } else {// w ww  . j  av  a2  s  .  c o m
        this.jsonView = null;
    }

    if (StringUtils.hasText(extDirectMethodAnnotation.group())) {
        this.group = extDirectMethodAnnotation.group().trim();
    } else {
        this.group = null;
    }

    this.synchronizeOnSession = extDirectMethodAnnotation.synchronizeOnSession();
    this.streamResponse = extDirectMethodAnnotation.streamResponse();

    if (this.type != ExtDirectMethodType.FORM_POST) {
        this.method = method;
        this.parameters = buildParameterList(clazz, method);

        this.collectionType = extDirectMethodAnnotation.entryClass() == Object.class ? null
                : extDirectMethodAnnotation.entryClass();

        if (this.collectionType == null) {
            for (ParameterInfo parameter : this.parameters) {
                Class<?> collType = parameter.getCollectionType();
                if (collType != null) {
                    this.collectionType = collType;
                    break;
                }
            }
        }
    } else {
        if (method.getReturnType().equals(Void.TYPE)) {

            RequestMapping methodAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
            RequestMapping classAnnotation = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);

            String path = null;
            if (hasValue(classAnnotation)) {
                path = classAnnotation.value()[0];
            }

            if (hasValue(methodAnnotation)) {
                String methodPath = methodAnnotation.value()[0];
                if (path != null) {
                    path = path + methodPath;
                } else {
                    path = methodPath;
                }
            }

            if (path != null) {
                if (path.charAt(0) == '/' && path.length() > 1) {
                    path = path.substring(1, path.length());
                }
                this.forwardPath = "forward:" + path;
            }
        } else {
            this.handlerMethod = new HandlerMethod(beanName, context, method).createWithResolvedBean();
        }
    }

    switch (this.type) {
    case SIMPLE:
        int paramLength = 0;
        for (ParameterInfo parameter : this.parameters) {
            if (parameter.isClientParameter()) {
                paramLength++;
            }
        }
        this.action = Action.create(method.getName(), paramLength, extDirectMethodAnnotation.batched());
        break;
    case SIMPLE_NAMED:
        int noOfClientParameters = 0;
        Class<?> parameterType = null;

        List<String> parameterNames = new ArrayList<String>();
        for (ParameterInfo parameter : this.parameters) {
            if (parameter.isClientParameter()) {
                noOfClientParameters++;
                parameterType = parameter.getType();
                parameterNames.add(parameter.getName());
            }
        }

        if (noOfClientParameters == 1 && Map.class.isAssignableFrom(parameterType)) {
            this.action = Action.createNamed(method.getName(), Collections.<String>emptyList(), Boolean.FALSE,
                    extDirectMethodAnnotation.batched());
        } else {
            this.action = Action.createNamed(method.getName(), Collections.unmodifiableList(parameterNames),
                    null, extDirectMethodAnnotation.batched());
        }
        break;
    case FORM_LOAD:
        this.action = Action.create(method.getName(), 1, extDirectMethodAnnotation.batched());
        break;
    case STORE_READ:
    case STORE_MODIFY:
    case TREE_LOAD:
        List<String> metadataParams = new ArrayList<String>();
        for (ParameterInfo parameter : this.parameters) {
            if (parameter.hasMetadataParamAnnotation()) {
                metadataParams.add(parameter.getName());
            }
        }
        this.action = Action.createTreeLoad(method.getName(), 1, metadataParams,
                extDirectMethodAnnotation.batched());
        break;
    case FORM_POST:
        this.action = Action.createFormHandler(method.getName(), 0);
        break;
    case FORM_POST_JSON:
        this.action = Action.create(method.getName(), 1, extDirectMethodAnnotation.batched());
        break;
    case POLL:
        this.pollingProvider = new PollingProvider(beanName, method.getName(),
                extDirectMethodAnnotation.event());
        break;
    default:
        throw new IllegalStateException("ExtDirectMethodType: " + this.type + " does not exists");
    }

    this.action = extractDocumentationAnnotations(extDirectMethodAnnotation.documentation());

}

From source file:pl.bristleback.server.bristle.conf.resolver.action.client.ClientActionClassesResolver.java

private ClientActionClassInformation prepareActionClass(Object actionClassInstance) {
    Class actionClass = actionClassInstance.getClass().getSuperclass(); // skip proxy class
    ClientActionClass actionClassAnnotation = AnnotationUtils.findAnnotation(actionClass,
            ClientActionClass.class);
    String actionClassName = getActionClassName(actionClass, actionClassAnnotation);
    Map<String, ClientActionInformation> actions = prepareActions(actionClass, actionClassName);

    return new ClientActionClassInformation(actionClassName, actions);
}

From source file:de.lbe.sandbox.springboot.jersey2.JerseyAutoConfiguration.java

@PostConstruct
public void path() {
    this.path = findPath(AnnotationUtils.findAnnotation(this.config.getClass(), ApplicationPath.class));
}

From source file:ch.ralscha.extdirectspring.controller.MethodRegistrar.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {

    ApplicationContext context = (ApplicationContext) event.getSource();

    String[] beanNames = context.getBeanNamesForType(Object.class);

    for (String beanName : beanNames) {

        Class<?> handlerType = context.getType(beanName);
        final Class<?> userType = ClassUtils.getUserClass(handlerType);

        Set<Method> methods = MethodIntrospector.selectMethods(userType, new MethodFilter() {
            @Override// w w w  . j  a  v  a 2s  .  c  o  m
            public boolean matches(Method method) {
                return AnnotationUtils.findAnnotation(method, ExtDirectMethod.class) != null;
            }
        });

        for (Method method : methods) {
            ExtDirectMethod directMethodAnnotation = AnnotationUtils.findAnnotation(method,
                    ExtDirectMethod.class);
            final String beanAndMethodName = beanName + "." + method.getName();
            if (directMethodAnnotation.value().isValid(beanAndMethodName, userType, method)) {
                this.methodInfoCache.put(beanName, handlerType, method, event.getApplicationContext());

                // /CLOVER:OFF
                if (log.isDebugEnabled()) {
                    String info = "Register " + beanAndMethodName + "(" + directMethodAnnotation.value();
                    if (StringUtils.hasText(directMethodAnnotation.group())) {
                        info += ", " + directMethodAnnotation.group();
                    }
                    info += ")";
                    log.debug(info);
                }
                // /CLOVER:ON
            }
        }

    }
}

From source file:org.fenixedu.bennu.spring.portal.PortalHandlerMapping.java

private void registerLonelyControllers(Collection<Object> values) {
    for (Object bean : values) {
        Class<?> type = bean.getClass();
        Class<?> functionalityType = AnnotationUtils.findAnnotation(type, BennuSpringController.class).value();
        Functionality functionality = functionalities.get(functionalityType);
        if (functionality == null) {
            throw new Error("Controller " + type.getName() + " declares " + functionalityType.getName()
                    + " as a functionality, but it is not one...");
        }//from w ww  .  ja v a2 s  .c o m
        functionalities.put(type, functionality);
    }
}

From source file:py.una.pol.karaku.test.cucumber.DatabasePopulatorCucumberExecutionListener.java

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

    super.afterTestClass(testContext);

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

    if ((sequences != null) && (sequences.value() != null) && (sequences.value().length > 0)) {
        DatabaseUtils.executeDDL(SEQUENCE_DESTRUCTOR, getApplicationContext(testContext), sequences.value());
    }/*from w w w  .j  av  a2s .c  o m*/
}

From source file:org.xmatthew.spy2servers.config.ComponentPostProcessor.java

private void detectAlertComponent(Object bean) throws RuntimeException {
    Class<?> beanClass = this.getBeanClass(bean);
    AlertComponent alertComponentAnnotation = AnnotationUtils.findAnnotation(beanClass, AlertComponent.class);
    if (alertComponentAnnotation != null) {
        if (bean instanceof org.xmatthew.spy2servers.core.AlertComponent) {
            org.xmatthew.spy2servers.core.AlertComponent alertComponent;
            alertComponent = (org.xmatthew.spy2servers.core.AlertComponent) bean;

            String name = alertComponentAnnotation.name();
            if (StringUtils.isNotBlank(name)) {
                alertComponent.setName(name);
            }//from   w ww  .  j av  a 2 s  .com
        } else {
            throw new RuntimeException("@AlertComponent mark class must implement "
                    + "org.xmatthew.spy2servers.core.AlertComponent interface");
        }
    }
}

From source file:edu.umn.msi.tropix.common.jobqueue.execution.DelegatingExecutionJobQueueImpl.java

public void setExecutionJobQueues(final Iterable<ExecutionJobQueue<JobDescription>> executionJobQueues) {
    LOG.debug("Setting delegate job queues to " + Iterables.toString(executionJobQueues));
    for (final ExecutionJobQueue<JobDescription> executionJobQueue : executionJobQueues) {
        final ExecutionType executionType = AnnotationUtils.findAnnotation(executionJobQueue.getClass(),
                ExecutionType.class);
        executionJobQueueMap.put(executionType.value(), executionJobQueue);
    }/* w  w  w .  jav  a2 s . com*/
}