Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
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 */
28 package ch.boye.httpclientandroidlib.protocol;
30 import java.util.Map;
32 /**
33 * Maintains a map of HTTP request handlers keyed by a request URI pattern.
34 * <br>
35 * Patterns may have three formats:
36 * <ul>
37 * <li><code>*</code></li>
38 * <li><code>*<uri></code></li>
39 * <li><code><uri>*</code></li>
40 * </ul>
41 * <br>
42 * This class can be used to resolve an instance of
43 * {@link HttpRequestHandler} matching a particular request URI. Usually the
44 * resolved request handler will be used to process the request with the
45 * specified request URI.
46 *
47 * @since 4.0
48 */
49 public class HttpRequestHandlerRegistry implements HttpRequestHandlerResolver {
51 private final UriPatternMatcher matcher;
53 public HttpRequestHandlerRegistry() {
54 matcher = new UriPatternMatcher();
55 }
57 /**
58 * Registers the given {@link HttpRequestHandler} as a handler for URIs
59 * matching the given pattern.
60 *
61 * @param pattern the pattern to register the handler for.
62 * @param handler the handler.
63 */
64 public void register(final String pattern, final HttpRequestHandler handler) {
65 if (pattern == null) {
66 throw new IllegalArgumentException("URI request pattern may not be null");
67 }
68 if (handler == null) {
69 throw new IllegalArgumentException("Request handler may not be null");
70 }
71 matcher.register(pattern, handler);
72 }
74 /**
75 * Removes registered handler, if exists, for the given pattern.
76 *
77 * @param pattern the pattern to unregister the handler for.
78 */
79 public void unregister(final String pattern) {
80 matcher.unregister(pattern);
81 }
83 /**
84 * Sets handlers from the given map.
85 * @param map the map containing handlers keyed by their URI patterns.
86 */
87 public void setHandlers(final Map map) {
88 matcher.setObjects(map);
89 }
91 public HttpRequestHandler lookup(final String requestURI) {
92 return (HttpRequestHandler) matcher.lookup(requestURI);
93 }
95 /**
96 * @deprecated
97 */
98 protected boolean matchUriRequestPattern(final String pattern, final String requestUri) {
99 return matcher.matchUriRequestPattern(pattern, requestUri);
100 }
102 }