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

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

Introduction

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

Prototype

@Nullable
public MethodParameter getMethodParameter() 

Source Link

Document

Return the wrapped MethodParameter, if any.

Usage

From source file:fr.mby.utils.spring.beans.factory.ProxywiredMethodParam.java

protected ProxywiredMethodParam(final DependencyDescriptor descriptor, final String wiredClassName) {
    super();//from   ww  w  .j  a va 2 s.com

    Assert.notNull(descriptor, "No DependencyDescriptor provided !");
    final MethodParameter methodParam = descriptor.getMethodParameter();
    Assert.notNull(methodParam, "DependencyDescriptor provided don't describe a Method parameter !");
    final String methodName = methodParam.getMethod().getName();
    final String paramName = methodParam.getParameterName();

    Assert.hasText(wiredClassName, "Wired class name cannot be found !");

    this.buildNodePath(wiredClassName, methodName, paramName);
}

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;
        }/*w  ww . j ava 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:fr.mby.utils.spring.beans.factory.BasicProxywiredManager.java

/**
 * Build the identifier for a Proxywired dependency.
 * // ww  w  . ja v  a2s.co m
 * @param descriptor
 *            the dependency descriptor
 * @param wiredClassName
 *            the class name of the in wich contain the annotation
 * @return the identifier
 */
protected IProxywiredIdentifier buildIdentifier(final DependencyDescriptor descriptor,
        final String wiredClassName) {
    Assert.notNull(descriptor, "No DependencyDescriptor provided !");
    Assert.hasText(wiredClassName, "No wiredClassName provided !");

    IProxywiredIdentifier identifier = null;

    if (descriptor.getMethodParameter() != null) {
        identifier = new ProxywiredMethodParam(descriptor, wiredClassName);
    } else if (descriptor.getField() != null) {
        identifier = new ProxywiredField(descriptor, wiredClassName);
    } else {
        throw new IllegalStateException("Unkown Proxywiring method !");
    }

    return identifier;
}

From source file:fr.mby.utils.spring.beans.factory.BasicProxywiredManager.java

/**
 * Find Bean Type to inject (not the generic type like Collection or Set).
 * /*from ww w . j  av  a  2 s  .c  o  m*/
 * @param descriptor
 * @param autowiredBeanNames
 * @return
 */
protected Class<?> getBeanType(final DependencyDescriptor descriptor, final Set<String> autowiredBeanNames) {
    final Class<?> result;

    Type fieldType = null;

    final Field field = descriptor.getField();
    if (field == null) {
        // Annotation on the method
        final MethodParameter methodParameter = descriptor.getMethodParameter();
        if (methodParameter != null) {
            fieldType = methodParameter.getGenericParameterType();
        }
    } else {
        fieldType = field.getGenericType();
    }

    if (fieldType != null) {
        final Class<?> type = descriptor.getDependencyType();
        if (Collection.class.isAssignableFrom(type)) {
            final ParameterizedType parameterizedType = (ParameterizedType) fieldType;
            result = (Class<?>) parameterizedType.getActualTypeArguments()[0];
        } else if (Map.class.isAssignableFrom(type)) {
            final ParameterizedType parameterizedType = (ParameterizedType) fieldType;
            result = (Class<?>) parameterizedType.getActualTypeArguments()[1];
        } else if (type.isArray()) {
            // We can't do anything
            throw new IllegalStateException("You cannot use Proxywired annotation on an Array !");
        } else {
            result = type;
        }
    } else {
        throw new IllegalStateException("Unable to find the Bean type !");
    }

    return result;
}