Search in sources :

Example 1 with SessionAttributesHandler

use of org.springframework.web.method.annotation.SessionAttributesHandler in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapter method getModelFactory.

private ModelFactory getModelFactory(HandlerMethod handlerMethod, WebDataBinderFactory binderFactory) {
    SessionAttributesHandler sessionAttrHandler = getSessionAttributesHandler(handlerMethod);
    Class<?> handlerType = handlerMethod.getBeanType();
    Set<Method> methods = this.modelAttributeCache.get(handlerType);
    if (methods == null) {
        methods = MethodIntrospector.selectMethods(handlerType, MODEL_ATTRIBUTE_METHODS);
        this.modelAttributeCache.put(handlerType, methods);
    }
    List<InvocableHandlerMethod> attrMethods = new ArrayList<>();
    // Global methods first
    for (Entry<ControllerAdviceBean, Set<Method>> entry : this.modelAttributeAdviceCache.entrySet()) {
        if (entry.getKey().isApplicableToBeanType(handlerType)) {
            Object bean = entry.getKey().resolveBean();
            for (Method method : entry.getValue()) {
                attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
            }
        }
    }
    for (Method method : methods) {
        Object bean = handlerMethod.getBean();
        attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
    }
    return new ModelFactory(attrMethods, binderFactory, sessionAttrHandler);
}
Also used : SessionAttributesHandler(org.springframework.web.method.annotation.SessionAttributesHandler) Set(java.util.Set) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) ArrayList(java.util.ArrayList) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) ModelFactory(org.springframework.web.method.annotation.ModelFactory) ControllerAdviceBean(org.springframework.web.method.ControllerAdviceBean)

Example 2 with SessionAttributesHandler

use of org.springframework.web.method.annotation.SessionAttributesHandler in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapter method getSessionAttributesHandler.

/**
	 * Return the {@link SessionAttributesHandler} instance for the given handler type
	 * (never {@code null}).
	 */
private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handlerMethod) {
    Class<?> handlerType = handlerMethod.getBeanType();
    SessionAttributesHandler sessionAttrHandler = this.sessionAttributesHandlerCache.get(handlerType);
    if (sessionAttrHandler == null) {
        synchronized (this.sessionAttributesHandlerCache) {
            sessionAttrHandler = this.sessionAttributesHandlerCache.get(handlerType);
            if (sessionAttrHandler == null) {
                sessionAttrHandler = new SessionAttributesHandler(handlerType, sessionAttributeStore);
                this.sessionAttributesHandlerCache.put(handlerType, sessionAttrHandler);
            }
        }
    }
    return sessionAttrHandler;
}
Also used : SessionAttributesHandler(org.springframework.web.method.annotation.SessionAttributesHandler)

Aggregations

SessionAttributesHandler (org.springframework.web.method.annotation.SessionAttributesHandler)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 ControllerAdviceBean (org.springframework.web.method.ControllerAdviceBean)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1 ModelFactory (org.springframework.web.method.annotation.ModelFactory)1 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)1