Java tutorial
/* * Copyright 2008-2009 MOPAS(Ministry of Public Administration and Security). * * 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 egovframework.rte.ptl.mvc.bind; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.core.MethodParameter; import org.springframework.web.bind.support.WebArgumentResolver; import org.springframework.web.context.request.NativeWebRequest; /** * CommandMapArgumentResolver.java * <p><b>NOTE:</b> <pre> Controller? (JSP) ? ?? Command(Form Class) ? , Map ? . * Sping MVC Controller? argument ? argument? customizing WebArgumentResolver? interface . * CommandMapArgumentResolver WebArgumentResolver? ??. * CommandMapArgumentResolver Controller ? argument? commandMap?? Map ? * HTTP request ?? ?? ? commandMap? .</b> * </pre> * @author * @since 2009.06.01 * @version 1.0 * @see * * <pre> * << ?(Modification Information) >> * * ? ? * ------- -------- --------------------------- * 2009.05.30 ? * * </pre> */ public class CommandMapArgumentResolver implements WebArgumentResolver { /** * Controller? argument? commandMap?? Map ? * HTTP request ?? ?? ? commandMap? returng. * ? ? ? Map? . * * @param methodParameter - ?? ,??? * @param webRequest - web request ? * @return argument? commandMap(java.util.Map)? commandMap, <code>UNRESOLVED</code>. * @exception Exception */ public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception { Class<?> clazz = methodParameter.getParameterType(); String paramName = methodParameter.getParameterName(); if (clazz.equals(Map.class) && paramName.equals("commandMap")) { Map<String, Object> commandMap = new HashMap<String, Object>(); HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); Enumeration<?> enumeration = request.getParameterNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); String[] values = request.getParameterValues(key); if (values != null) { commandMap.put(key, (values.length > 1) ? values : values[0]); } } return commandMap; } return UNRESOLVED; } }