Search in sources :

Example 1 with PropertyInjectionPoint

use of jodd.petite.PropertyInjectionPoint in project jodd by oblac.

the class PropertyResolver method resolve.

/**
	 * Resolves all properties for given type.
	 */
public PropertyInjectionPoint[] resolve(Class type, boolean autowire) {
    // lookup fields
    ClassDescriptor cd = ClassIntrospector.lookup(type);
    List<PropertyInjectionPoint> list = new ArrayList<>();
    PropertyDescriptor[] allPropertyDescriptors = cd.getAllPropertyDescriptors();
    for (PropertyDescriptor propertyDescriptor : allPropertyDescriptors) {
        if (propertyDescriptor.isGetterOnly()) {
            continue;
        }
        Class propertyType = propertyDescriptor.getType();
        if (ReflectUtil.isTypeOf(propertyType, Collection.class)) {
            continue;
        }
        MethodDescriptor writeMethodDescriptor = propertyDescriptor.getWriteMethodDescriptor();
        FieldDescriptor fieldDescriptor = propertyDescriptor.getFieldDescriptor();
        PetiteInject ref = null;
        if (writeMethodDescriptor != null) {
            ref = writeMethodDescriptor.getMethod().getAnnotation(PetiteInject.class);
        }
        if (ref == null && fieldDescriptor != null) {
            ref = fieldDescriptor.getField().getAnnotation(PetiteInject.class);
        }
        if ((!autowire) && (ref == null)) {
            continue;
        }
        String[] refName = null;
        if (ref != null) {
            String name = ref.value().trim();
            if (name.length() != 0) {
                refName = new String[] { name };
            }
        }
        list.add(injectionPointFactory.createPropertyInjectionPoint(propertyDescriptor, refName));
    }
    PropertyInjectionPoint[] fields;
    if (list.isEmpty()) {
        fields = PropertyInjectionPoint.EMPTY;
    } else {
        fields = list.toArray(new PropertyInjectionPoint[list.size()]);
    }
    return fields;
}
Also used : ClassDescriptor(jodd.introspector.ClassDescriptor) PropertyDescriptor(jodd.introspector.PropertyDescriptor) ArrayList(java.util.ArrayList) PetiteInject(jodd.petite.meta.PetiteInject) MethodDescriptor(jodd.introspector.MethodDescriptor) FieldDescriptor(jodd.introspector.FieldDescriptor) PropertyInjectionPoint(jodd.petite.PropertyInjectionPoint)

Aggregations

ArrayList (java.util.ArrayList)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 FieldDescriptor (jodd.introspector.FieldDescriptor)1 MethodDescriptor (jodd.introspector.MethodDescriptor)1 PropertyDescriptor (jodd.introspector.PropertyDescriptor)1 PropertyInjectionPoint (jodd.petite.PropertyInjectionPoint)1 PetiteInject (jodd.petite.meta.PetiteInject)1