/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.spring.web.event.builder;

import static com.feilong.core.bean.ToStringConfig.DEFAULT_CONFIG;

import java.lang.annotation.Annotation;
import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.HeadersRequestCondition;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;

import com.feilong.core.bean.ConvertUtil;
import com.feilong.core.lang.annotation.AnnotationToStringBuilder;

/**
 * HandlerMethodInfo 信息提取.
 * 
 * @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
 * @since 1.10.4
 */
public class HandlerMethodInfoExtractor{

    /**
     * 提取.
     *
     * @param requestMappingInfo
     *            the request mapping info
     * @param handlerMethod
     *            the handler method
     * @param annotationAndAnnotationToStringBuilderMap
     *            the annotation and annotation to string builder map
     * @return the map
     */
    public static Map<String, Object> extract(
                    RequestMappingInfo requestMappingInfo,
                    HandlerMethod handlerMethod,
                    Map<Class<Annotation>, AnnotationToStringBuilder<Annotation>> annotationAndAnnotationToStringBuilderMap){
        Map<String, Object> keyAndValueMap = new LinkedHashMap<>();

        //塞RequestMappingInfo 本身的信息,比如 url ,method,header 等信息进去.
        putRequestMappingInfo(keyAndValueMap, requestMappingInfo);

        //塞配置的要提取的annotaion信息进去.
        putAnnotationInfo(keyAndValueMap, handlerMethod, annotationAndAnnotationToStringBuilderMap);

        return keyAndValueMap;
    }

    /**
     * 塞RequestMappingInfo 本身的信息,比如 url ,method,header 等信息进去.
     *
     * @param keyAndValueMap
     *            the key and value map
     * @param requestMappingInfo
     *            the request mapping info
     */
    private static void putRequestMappingInfo(Map<String, Object> keyAndValueMap,RequestMappingInfo requestMappingInfo){
        PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
        RequestMethodsRequestCondition requestMethodsRequestCondition = requestMappingInfo.getMethodsCondition();
        HeadersRequestCondition headersRequestCondition = requestMappingInfo.getHeadersCondition();

        keyAndValueMap.put("url", ConvertUtil.toString(patternsRequestCondition.getPatterns(), DEFAULT_CONFIG));
        keyAndValueMap.put("method", ConvertUtil.toString(requestMethodsRequestCondition.getMethods(), DEFAULT_CONFIG));
        keyAndValueMap.put("header", ConvertUtil.toString(headersRequestCondition.getExpressions(), DEFAULT_CONFIG));
    }

    /**
     * 塞配置的要提取的annotaion信息进去.
     *
     * @param keyAndValueMap
     *            the key and value map
     * @param handlerMethod
     *            the handler method
     * @param annotationAndAnnotationToStringBuilderMap
     *            the annotation and annotation to string builder map
     */
    private static void putAnnotationInfo(
                    Map<String, Object> keyAndValueMap,
                    HandlerMethod handlerMethod,
                    Map<Class<Annotation>, AnnotationToStringBuilder<Annotation>> annotationAndAnnotationToStringBuilderMap){

        for (Map.Entry<Class<Annotation>, AnnotationToStringBuilder<Annotation>> annotationEntry : annotationAndAnnotationToStringBuilderMap
                        .entrySet()){
            Class<Annotation> annotationClass = annotationEntry.getKey();
            AnnotationToStringBuilder<Annotation> annotationToStringBuilder = annotationEntry.getValue();

            Annotation annotation = handlerMethod.getMethodAnnotation(annotationClass);

            keyAndValueMap.put(annotationClass.getSimpleName(), annotationToStringBuilder.build(annotation));
        }
    }
}

@@ -1441,16 +1441,311 @@
 actor%7B%0A%0A
+    /** Don't let anyone instantiate this class. */%0A    private HandlerMethodInfoExtractor()%7B%0A        //AssertionError%E4%B8%8D%E6%98%AF%E5%BF%85%E9%A1%BB%E7%9A%84. %E4%BD%86%E5%AE%83%E5%8F%AF%E4%BB%A5%E9%81%BF%E5%85%8D%E4%B8%8D%E5%B0%8F%E5%BF%83%E5%9C%A8%E7%B1%BB%E7%9A%84%E5%86%85%E9%83%A8%E8%B0%83%E7%94%A8%E6%9E%84%E9%80%A0%E5%99%A8. %E4%BF%9D%E8%AF%81%E8%AF%A5%E7%B1%BB%E5%9C%A8%E4%BB%BB%E4%BD%95%E6%83%85%E5%86%B5%E4%B8%8B%E9%83%BD%E4%B8%8D%E4%BC%9A%E8%A2%AB%E5%AE%9E%E4%BE%8B%E5%8C%96.%0A        //see %E3%80%8AEffective Java%E3%80%8B 2nd%0A        throw new AssertionError(%22No %22 + getClass().getName() + %22 instances for you!%22);%0A    %7D%0A%0A
     /**%0A

write private HandlerMethodInfoExtractor