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.nio.protocol;
29
30 import java.util.Map;
31
32 import org.apache.http.annotation.ThreadSafe;
33 import org.apache.http.protocol.UriPatternMatcher;
34
35 /**
36 * Maintains a map of HTTP request handlers keyed by a request URI pattern.
37 * <br>
38 * Patterns may have three formats:
39 * <ul>
40 * <li><code>*</code></li>
41 * <li><code>*<uri></code></li>
42 * <li><code><uri>*</code></li>
43 * </ul>
44 * <br>
45 * This class can be used to resolve an instance of {@link HttpAsyncRequestHandler}
46 * matching a particular request URI. Usually the resolved request handler
47 * will be used to process the request with the specified request URI.
48 *
49 * @since 4.2
50 * @deprecated (4.3) use {@link UriHttpAsyncRequestHandlerMapper}
51 */
52 @ThreadSafe
53 @Deprecated
54 public class HttpAsyncRequestHandlerRegistry implements HttpAsyncRequestHandlerResolver {
55
56 private final UriPatternMatcher<HttpAsyncRequestHandler<?>> matcher;
57
58 public HttpAsyncRequestHandlerRegistry() {
59 matcher = new UriPatternMatcher<HttpAsyncRequestHandler<?>>();
60 }
61
62 /**
63 * Registers the given {@link HttpAsyncRequestHandler} as a handler for URIs
64 * matching the given pattern.
65 *
66 * @param pattern the pattern to register the handler for.
67 * @param handler the handler.
68 */
69 public void register(final String pattern, final HttpAsyncRequestHandler<?> handler) {
70 matcher.register(pattern, handler);
71 }
72
73 /**
74 * Removes registered handler, if exists, for the given pattern.
75 *
76 * @param pattern the pattern to unregister the handler for.
77 */
78 public void unregister(final String pattern) {
79 matcher.unregister(pattern);
80 }
81
82 /**
83 * Sets handlers from the given map.
84 * @param map the map containing handlers keyed by their URI patterns.
85 */
86 public void setHandlers(final Map<String, HttpAsyncRequestHandler<?>> map) {
87 matcher.setObjects(map);
88 }
89
90 /**
91 * Get the handler map.
92 * @return The map of handlers and their associated URI patterns.
93 */
94 public Map<String, HttpAsyncRequestHandler<?>> getHandlers() {
95 return matcher.getObjects();
96 }
97
98 public HttpAsyncRequestHandler<?> lookup(final String requestURI) {
99 return matcher.lookup(requestURI);
100 }
101
102 }