1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.http.protocol; 29 30 import java.util.Map; 31 32 import org.apache.http.annotation.ThreadingBehavior; 33 import org.apache.http.annotation.Contract; 34 import org.apache.http.util.Args; 35 36 /** 37 * Maintains a map of HTTP request handlers keyed by a request URI pattern. 38 * <br> 39 * Patterns may have three formats: 40 * <ul> 41 * <li>{@code *}</li> 42 * <li>{@code *<uri>}</li> 43 * <li>{@code <uri>*}</li> 44 * </ul> 45 * <br> 46 * This class can be used to resolve an instance of 47 * {@link HttpRequestHandler} matching a particular request URI. Usually the 48 * resolved request handler will be used to process the request with the 49 * specified request URI. 50 * 51 * @since 4.0 52 * @deprecated (4.3) use {@link UriHttpRequestHandlerMapper} 53 */ 54 @Contract(threading = ThreadingBehavior.SAFE) 55 @Deprecated 56 public class HttpRequestHandlerRegistry implements HttpRequestHandlerResolver { 57 58 private final UriPatternMatcher<HttpRequestHandler> matcher; 59 60 public HttpRequestHandlerRegistry() { 61 matcher = new UriPatternMatcher<HttpRequestHandler>(); 62 } 63 64 /** 65 * Registers the given {@link HttpRequestHandler} as a handler for URIs 66 * matching the given pattern. 67 * 68 * @param pattern the pattern to register the handler for. 69 * @param handler the handler. 70 */ 71 public void register(final String pattern, final HttpRequestHandler handler) { 72 Args.notNull(pattern, "URI request pattern"); 73 Args.notNull(handler, "Request handler"); 74 matcher.register(pattern, handler); 75 } 76 77 /** 78 * Removes registered handler, if exists, for the given pattern. 79 * 80 * @param pattern the pattern to unregister the handler for. 81 */ 82 public void unregister(final String pattern) { 83 matcher.unregister(pattern); 84 } 85 86 /** 87 * Sets handlers from the given map. 88 * @param map the map containing handlers keyed by their URI patterns. 89 */ 90 public void setHandlers(final Map<String, HttpRequestHandler> map) { 91 matcher.setObjects(map); 92 } 93 94 /** 95 * Get the handler map. 96 * @return The map of handlers and their associated URI patterns. 97 * 98 * @since 4.2 99 */ 100 public Map<String, HttpRequestHandler> getHandlers() { 101 return matcher.getObjects(); 102 } 103 104 @Override 105 public HttpRequestHandler lookup(final String requestURI) { 106 return matcher.lookup(requestURI); 107 } 108 109 }