Search in sources :

Example 1 with PetiteInitMethod

use of jodd.petite.meta.PetiteInitMethod in project jodd by oblac.

the class InjectorsManager method createInjectors.

@PetiteInitMethod(order = 1, invoke = POST_DEFINE)
void createInjectors() {
    requestScopeInjector = new RequestScopeInjector(madvocConfig, scopeDataResolver);
    sessionScopeInjector = new SessionScopeInjector(scopeDataResolver);
    actionPathMacroInjector = new ActionPathMacroInjector(scopeDataResolver);
    madvocContextScopeInjector = new MadvocContextScopeInjector(scopeDataResolver, madpc);
    madvocParamsInjector = new MadvocParamsInjector(madvocConfig);
    applicationScopeInjector = new ApplicationScopeInjector(scopeDataResolver);
    servletContextScopeInjector = new ServletContextScopeInjector(scopeDataResolver);
}
Also used : SessionScopeInjector(jodd.madvoc.injector.SessionScopeInjector) RequestScopeInjector(jodd.madvoc.injector.RequestScopeInjector) MadvocContextScopeInjector(jodd.madvoc.injector.MadvocContextScopeInjector) MadvocParamsInjector(jodd.madvoc.injector.MadvocParamsInjector) ActionPathMacroInjector(jodd.madvoc.injector.ActionPathMacroInjector) ApplicationScopeInjector(jodd.madvoc.injector.ApplicationScopeInjector) ServletContextScopeInjector(jodd.madvoc.injector.ServletContextScopeInjector) PetiteInitMethod(jodd.petite.meta.PetiteInitMethod)

Example 2 with PetiteInitMethod

use of jodd.petite.meta.PetiteInitMethod 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

PetiteInitMethod (jodd.petite.meta.PetiteInitMethod)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 MethodDescriptor (jodd.introspector.MethodDescriptor)1 ActionPathMacroInjector (jodd.madvoc.injector.ActionPathMacroInjector)1 ApplicationScopeInjector (jodd.madvoc.injector.ApplicationScopeInjector)1 MadvocContextScopeInjector (jodd.madvoc.injector.MadvocContextScopeInjector)1 MadvocParamsInjector (jodd.madvoc.injector.MadvocParamsInjector)1 RequestScopeInjector (jodd.madvoc.injector.RequestScopeInjector)1 ServletContextScopeInjector (jodd.madvoc.injector.ServletContextScopeInjector)1 SessionScopeInjector (jodd.madvoc.injector.SessionScopeInjector)1 InitMethodPoint (jodd.petite.InitMethodPoint)1 PetiteException (jodd.petite.PetiteException)1