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

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

Introduction

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

Prototype

@Nullable
public Field getField() 

Source Link

Document

Return the wrapped Field, if any.

Usage

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

protected ProxywiredField(final DependencyDescriptor descriptor, final String wiredClassName) {
    super();/*w ww . ja v a2 s.c o m*/

    Assert.notNull(descriptor, "No DependencyDescriptor provided !");
    final Field field = descriptor.getField();
    Assert.notNull(field, "DependencyDescriptor provided don't describe a Field !");
    final String fieldName = field.getName();

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

    this.buildNodePath(wiredClassName, fieldName);
}

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

/**
 * Find Bean Type to inject (not the generic type like Collection or Set).
 * /*  ww w .  j a  va 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;
}

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

/**
 * Build the identifier for a Proxywired dependency.
 * //from   www .j  a  va2  s .c om
 * @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;
}