Java 类org.springframework.web.bind.annotation.SessionAttributes 实例源码

项目:lams    文件:SessionAttributesHandler.java   
/**
 * Create a new instance for a controller type. Session attribute names and
 * types are extracted from the {@code @SessionAttributes} annotation, if
 * present, on the given type.
 * @param handlerType the controller type
 * @param sessionAttributeStore used for session access
 */
public SessionAttributesHandler(Class<?> handlerType, SessionAttributeStore sessionAttributeStore) {
    Assert.notNull(sessionAttributeStore, "SessionAttributeStore may not be null.");
    this.sessionAttributeStore = sessionAttributeStore;

    SessionAttributes annotation = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    if (annotation != null) {
        this.attributeNames.addAll(Arrays.asList(annotation.value()));
        this.attributeTypes.addAll(Arrays.<Class<?>>asList(annotation.types()));
    }

    for (String attributeName : this.attributeNames) {
        this.knownAttributeNames.add(attributeName);
    }
}
项目:lams    文件:HandlerMethodResolver.java   
/**
 * Initialize a new HandlerMethodResolver for the specified handler type.
 * @param handlerType the handler class to introspect
 */
public void init(final Class<?> handlerType) {
    Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
    Class<?> specificHandlerType = null;
    if (!Proxy.isProxyClass(handlerType)) {
        handlerTypes.add(handlerType);
        specificHandlerType = handlerType;
    }
    handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
    for (Class<?> currentHandlerType : handlerTypes) {
        final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
        ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
            @Override
            public void doWith(Method method) {
                Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
                Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
                if (isHandlerMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isHandlerMethod(bridgedMethod))) {
                    handlerMethods.add(specificMethod);
                }
                else if (isInitBinderMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isInitBinderMethod(bridgedMethod))) {
                    initBinderMethods.add(specificMethod);
                }
                else if (isModelAttributeMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isModelAttributeMethod(bridgedMethod))) {
                    modelAttributeMethods.add(specificMethod);
                }
            }
        }, ReflectionUtils.USER_DECLARED_METHODS);
    }
    this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
    SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
        this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
        this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
}
项目:spring4-understanding    文件:AnnotationMethodHandlerAdapter.java   
@Override
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    Class<?> clazz = ClassUtils.getUserClass(handler);
    Boolean annotatedWithSessionAttributes = this.sessionAnnotatedClassesCache.get(clazz);
    if (annotatedWithSessionAttributes == null) {
        annotatedWithSessionAttributes = (AnnotationUtils.findAnnotation(clazz, SessionAttributes.class) != null);
        this.sessionAnnotatedClassesCache.put(clazz, annotatedWithSessionAttributes);
    }

    if (annotatedWithSessionAttributes) {
        checkAndPrepare(request, response, this.cacheSecondsForSessionAttributeHandlers, true);
    }
    else {
        checkAndPrepare(request, response, true);
    }

    // Execute invokeHandlerMethod in synchronized block if required.
    if (this.synchronizeOnSession) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
                return invokeHandlerMethod(request, response, handler);
            }
        }
    }

    return invokeHandlerMethod(request, response, handler);
}
项目:spring4-understanding    文件:SessionAttributesHandler.java   
/**
 * Create a new instance for a controller type. Session attribute names and
 * types are extracted from the {@code @SessionAttributes} annotation, if
 * present, on the given type.
 * @param handlerType the controller type
 * @param sessionAttributeStore used for session access
 */
public SessionAttributesHandler(Class<?> handlerType, SessionAttributeStore sessionAttributeStore) {
    Assert.notNull(sessionAttributeStore, "SessionAttributeStore may not be null.");
    this.sessionAttributeStore = sessionAttributeStore;

    SessionAttributes annotation = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    if (annotation != null) {
        this.attributeNames.addAll(Arrays.asList(annotation.names()));
        this.attributeTypes.addAll(Arrays.asList(annotation.types()));
    }

    for (String attributeName : this.attributeNames) {
        this.knownAttributeNames.add(attributeName);
    }
}
项目:spring4-understanding    文件:HandlerMethodResolver.java   
/**
 * Initialize a new HandlerMethodResolver for the specified handler type.
 * @param handlerType the handler class to introspect
 */
public void init(final Class<?> handlerType) {
    Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
    Class<?> specificHandlerType = null;
    if (!Proxy.isProxyClass(handlerType)) {
        handlerTypes.add(handlerType);
        specificHandlerType = handlerType;
    }
    handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
    for (Class<?> currentHandlerType : handlerTypes) {
        final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
        ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
            @Override
            public void doWith(Method method) {
                Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
                Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
                if (isHandlerMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isHandlerMethod(bridgedMethod))) {
                    handlerMethods.add(specificMethod);
                }
                else if (isInitBinderMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isInitBinderMethod(bridgedMethod))) {
                    initBinderMethods.add(specificMethod);
                }
                else if (isModelAttributeMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isModelAttributeMethod(bridgedMethod))) {
                    modelAttributeMethods.add(specificMethod);
                }
            }
        }, ReflectionUtils.USER_DECLARED_METHODS);
    }
    this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
    SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
        this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.names()));
        this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
}
项目:class-guard    文件:AnnotationMethodHandlerAdapter.java   
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    Class<?> clazz = ClassUtils.getUserClass(handler);
    Boolean annotatedWithSessionAttributes = this.sessionAnnotatedClassesCache.get(clazz);
    if (annotatedWithSessionAttributes == null) {
        annotatedWithSessionAttributes = (AnnotationUtils.findAnnotation(clazz, SessionAttributes.class) != null);
        this.sessionAnnotatedClassesCache.put(clazz, annotatedWithSessionAttributes);
    }

    if (annotatedWithSessionAttributes) {
        // Always prevent caching in case of session attribute management.
        checkAndPrepare(request, response, this.cacheSecondsForSessionAttributeHandlers, true);
        // Prepare cached set of session attributes names.
    }
    else {
        // Uses configured default cacheSeconds setting.
        checkAndPrepare(request, response, true);
    }

    // Execute invokeHandlerMethod in synchronized block if required.
    if (this.synchronizeOnSession) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
                return invokeHandlerMethod(request, response, handler);
            }
        }
    }

    return invokeHandlerMethod(request, response, handler);
}
项目:class-guard    文件:SessionAttributesHandler.java   
/**
 * Create a new instance for a controller type. Session attribute names and
 * types are extracted from the {@code @SessionAttributes} annotation, if
 * present, on the given type.
 * @param handlerType the controller type
 * @param sessionAttributeStore used for session access
 */
public SessionAttributesHandler(Class<?> handlerType, SessionAttributeStore sessionAttributeStore) {
    Assert.notNull(sessionAttributeStore, "SessionAttributeStore may not be null.");
    this.sessionAttributeStore = sessionAttributeStore;

    SessionAttributes annotation = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    if (annotation != null) {
        this.attributeNames.addAll(Arrays.asList(annotation.value()));
        this.attributeTypes.addAll(Arrays.<Class<?>>asList(annotation.types()));
    }

    for (String attributeName : this.attributeNames) {
        this.knownAttributeNames.put(attributeName, Boolean.TRUE);
    }
}
项目:class-guard    文件:HandlerMethodResolver.java   
/**
 * Initialize a new HandlerMethodResolver for the specified handler type.
 * @param handlerType the handler class to introspect
 */
public void init(final Class<?> handlerType) {
    Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
    Class<?> specificHandlerType = null;
    if (!Proxy.isProxyClass(handlerType)) {
        handlerTypes.add(handlerType);
        specificHandlerType = handlerType;
    }
    handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
    for (Class<?> currentHandlerType : handlerTypes) {
        final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
        ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) {
                Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
                Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
                if (isHandlerMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isHandlerMethod(bridgedMethod))) {
                    handlerMethods.add(specificMethod);
                }
                else if (isInitBinderMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isInitBinderMethod(bridgedMethod))) {
                    initBinderMethods.add(specificMethod);
                }
                else if (isModelAttributeMethod(specificMethod) &&
                        (bridgedMethod == specificMethod || !isModelAttributeMethod(bridgedMethod))) {
                    modelAttributeMethods.add(specificMethod);
                }
            }
        }, ReflectionUtils.USER_DECLARED_METHODS);
    }
    this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
    SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
        this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
        this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
}
项目:jresplus    文件:ExtendableAnnotationMethodHandlerAdapter.java   
public ModelAndView handle(HttpServletRequest request,
        HttpServletResponse response, Object handler) throws Exception {

    if (AnnotationUtils.findAnnotation(handler.getClass(),
            SessionAttributes.class) != null) {
        // Always prevent caching in case of session attribute management.
        checkAndPrepare(request, response,
                this.cacheSecondsForSessionAttributeHandlers, true);
        // Prepare cached set of session attributes names.
    } else {
        // Uses configured default cacheSeconds setting.
        checkAndPrepare(request, response, true);
    }

    // Execute invokeHandlerMethod in synchronized block if required.
    if (this.synchronizeOnSession) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
                return invokeHandlerMethod(request, response, handler);
            }
        }
    }

    return invokeHandlerMethod(request, response, handler);
}
项目:sinavi-jfw    文件:Controllers.java   
/**
 * {@inheritDoc}
 */
static String[] findSessionAttributeNames(Class<?> controllerClass) {
    SessionAttributes attrs = AnnotationUtils.findAnnotation(controllerClass, SessionAttributes.class);
    if (attrs != null) {
      return attrs.value();
    }
    return null;
}
项目:sinavi-jfw    文件:Controllers.java   
/**
 * {@inheritDoc}
 */
static Class<?>[] findSessionAttributeTypes(Class<?> controllerClass) {
    SessionAttributes attrs = AnnotationUtils.findAnnotation(controllerClass, SessionAttributes.class);
    if (attrs != null) {
      return attrs.types();
    }
    return null;
}