Search in sources :

Example 1 with InitMethodPoint

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

the class InitMethodResolver method resolve.

public InitMethodPoint[] resolve(Object bean) {
    Class<?> type = bean.getClass();
    // lookup methods
    List<InitMethodPoint> list = new ArrayList<>();
    ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null);
    MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
    for (MethodDescriptor methodDescriptor : allMethods) {
        Method method = methodDescriptor.getMethod();
        PetiteInitMethod petiteInitMethod = method.getAnnotation(PetiteInitMethod.class);
        if (petiteInitMethod == null) {
            continue;
        }
        if (method.getParameterTypes().length > 0) {
            throw new PetiteException("Arguments are not allowed for Petite init method: " + type.getName() + '#' + method.getName());
        }
        int order = petiteInitMethod.order();
        list.add(new InitMethodPoint(method, order, petiteInitMethod.invoke()));
    }
    InitMethodPoint[] methods;
    if (list.isEmpty()) {
        methods = InitMethodPoint.EMPTY;
    } else {
        Collections.sort(list);
        methods = list.toArray(new InitMethodPoint[list.size()]);
    }
    return methods;
}
Also used : InitMethodPoint(jodd.petite.InitMethodPoint) PetiteInitMethod(jodd.petite.meta.PetiteInitMethod) ClassDescriptor(jodd.introspector.ClassDescriptor) ArrayList(java.util.ArrayList) PetiteInitMethod(jodd.petite.meta.PetiteInitMethod) Method(java.lang.reflect.Method) MethodDescriptor(jodd.introspector.MethodDescriptor) PetiteException(jodd.petite.PetiteException) InitMethodPoint(jodd.petite.InitMethodPoint)

Aggregations

Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 MethodDescriptor (jodd.introspector.MethodDescriptor)1 InitMethodPoint (jodd.petite.InitMethodPoint)1 PetiteException (jodd.petite.PetiteException)1 PetiteInitMethod (jodd.petite.meta.PetiteInitMethod)1