Example usage for org.springframework.beans.factory.config DependencyDescriptor getAnnotations

List of usage examples for org.springframework.beans.factory.config DependencyDescriptor getAnnotations

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config DependencyDescriptor getAnnotations.

Prototype

public Annotation[] getAnnotations() 

Source Link

Document

Obtain the annotations associated with the wrapped field or method/constructor parameter.

Usage

From source file:com.payu.ratel.client.RemoteAutowireCandidateResolver.java

private static Optional<Annotation> getAnnotationWithType(DependencyDescriptor descriptor, final Class clazz) {
    return Iterables.tryFind(Arrays.asList(descriptor.getAnnotations()), new Predicate<Annotation>() {
        @Override/*from  w  w  w  .j  a v  a 2  s.  c o m*/
        public boolean apply(Annotation input) {
            return clazz.getName().equals(input.annotationType().getName());
        }
    });
}

From source file:com.payu.ratel.client.ContextAnnotationAutowireCandidateResolver.java

protected boolean isLazy(DependencyDescriptor descriptor) {
    for (Annotation ann : descriptor.getAnnotations()) {
        Lazy lazy = AnnotationUtils.getAnnotation(ann, Lazy.class);
        if (lazy != null && lazy.value()) {
            return true;
        }/* www .  ja v a  2 s.  co m*/
    }
    MethodParameter methodParam = descriptor.getMethodParameter();
    if (methodParam == null) {
        return false;
    }
    Method method = methodParam.getMethod();
    if (method == null || void.class.equals(method.getReturnType())) {
        Lazy lazy = AnnotationUtils.getAnnotation(methodParam.getAnnotatedElement(), Lazy.class);
        if (lazy != null && lazy.value()) {
            return true;
        }
    }

    return false;
}

From source file:com.geodevv.testing.irmina.IrminaListableBeanFactory.java

@Override
public Object resolveDependency(DependencyDescriptor descriptor, String beanName,
        Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {

    InjectionPointDefinition injectionPointDefinition = new InjectionPointDefinition(
            descriptor.getAnnotations(), descriptor.getDependencyType());

    Object mockedBean = mockedInjectionPointsRegister.findBy(injectionPointDefinition);

    if (mockedBean != null) {
        return mockedBean;
    }/*from w  ww  . j av a2s .  c  o  m*/

    Object spiedBean = spiedInjectionPointsRegister.findBy(injectionPointDefinition);

    if (spiedBean != null) {
        return spiedBean;
    }

    try {

        Object resolvedBean = super.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);

        if (spiedInjectionPointsRegister.hasDefinition(injectionPointDefinition)) {
            LOGGER.warn("[SPYING DEPENDENCY] " + injectionPointDefinition + " in " + beanName);
            return spiedInjectionPointsRegister.registerSpy(injectionPointDefinition, resolvedBean);
        } else {
            return resolvedBean;
        }

    } catch (NoSuchBeanDefinitionException e) {

        LOGGER.warn("[MOCKING DEPENDENCY] " + injectionPointDefinition + " in " + beanName);
        return mockedInjectionPointsRegister.registerMock(injectionPointDefinition);
    }

}

From source file:com.payu.ratel.client.RemoteAutowireCandidateResolver.java

private Collection<String> getAnnotationsTypes(DependencyDescriptor descriptor) {
    Function<Annotation, String> function = new Function<Annotation, String>() {

        @Override//  w w w .  j a  va 2s . c o  m
        public String apply(Annotation annotation) {
            return annotation.annotationType().getName();
        }
    };

    return Collections2.transform(Arrays.asList(descriptor.getAnnotations()), function);
}