1 16 17 package org.springframework.web.servlet.mvc.multiaction; 18 19 import java.util.Iterator ; 20 import java.util.Properties ; 21 22 import org.springframework.beans.factory.InitializingBean; 23 import org.springframework.util.AntPathMatcher; 24 import org.springframework.util.Assert; 25 import org.springframework.util.PathMatcher; 26 27 49 public class PropertiesMethodNameResolver extends AbstractUrlMethodNameResolver 50 implements InitializingBean { 51 52 private Properties mappings; 53 54 private PathMatcher pathMatcher = new AntPathMatcher(); 55 56 57 61 public void setMappings(Properties mappings) { 62 this.mappings = mappings; 63 } 64 65 70 public void setPathMatcher(PathMatcher pathMatcher) { 71 Assert.notNull(pathMatcher, "PathMatcher must not be null"); 72 this.pathMatcher = pathMatcher; 73 } 74 75 public void afterPropertiesSet() { 76 if (this.mappings == null || this.mappings.isEmpty()) { 77 throw new IllegalArgumentException ("'mappings' property is required"); 78 } 79 } 80 81 82 protected String getHandlerMethodNameForUrlPath(String urlPath) { 83 String methodName = this.mappings.getProperty(urlPath); 84 if (methodName != null) { 85 return methodName; 86 } 87 for (Iterator it = this.mappings.keySet().iterator(); it.hasNext();) { 88 String registeredPath = (String ) it.next(); 89 if (this.pathMatcher.match(registeredPath, urlPath)) { 90 return (String ) this.mappings.get(registeredPath); 91 } 92 } 93 return null; 94 } 95 96 } 97 | Popular Tags |