KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > handler > WebRequestHandlerInterceptorAdapter


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.handler;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.springframework.util.Assert;
23 import org.springframework.web.context.request.WebRequestInterceptor;
24 import org.springframework.web.servlet.HandlerInterceptor;
25 import org.springframework.web.servlet.ModelAndView;
26
27 /**
28  * Adapter that implements the Servlet HandlerInterceptor interface
29  * and wraps an underlying WebRequestInterceptor.
30  *
31  * @author Juergen Hoeller
32  * @since 2.0
33  * @see org.springframework.web.context.request.WebRequestInterceptor
34  * @see org.springframework.web.servlet.HandlerInterceptor
35  */

36 public class WebRequestHandlerInterceptorAdapter implements HandlerInterceptor {
37
38     private final WebRequestInterceptor requestInterceptor;
39
40
41     /**
42      * Create a new WebRequestHandlerInterceptorAdapter for the given WebRequestInterceptor.
43      * @param requestInterceptor the WebRequestInterceptor to wrap
44      */

45     public WebRequestHandlerInterceptorAdapter(WebRequestInterceptor requestInterceptor) {
46         Assert.notNull(requestInterceptor, "WebRequestInterceptor must not be null");
47         this.requestInterceptor = requestInterceptor;
48     }
49
50
51     public boolean preHandle(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Object JavaDoc handler)
52             throws Exception JavaDoc {
53
54         this.requestInterceptor.preHandle(new DispatcherServletWebRequest(request));
55         return true;
56     }
57
58     public void postHandle(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Object JavaDoc handler, ModelAndView modelAndView)
59             throws Exception JavaDoc {
60
61         this.requestInterceptor.postHandle(new DispatcherServletWebRequest(request),
62                 (modelAndView != null ? modelAndView.getModelMap() : null));
63     }
64
65     public void afterCompletion(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Object JavaDoc handler, Exception JavaDoc ex)
66             throws Exception JavaDoc {
67
68         this.requestInterceptor.afterCompletion(new DispatcherServletWebRequest(request), ex);
69     }
70
71 }
72
Popular Tags