KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > jetty > interceptor > WebApplicationContextBeforeAfter


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

17 package org.apache.geronimo.jetty.interceptor;
18
19 import org.mortbay.http.HttpRequest;
20 import org.mortbay.http.HttpResponse;
21 import org.mortbay.http.HttpContext;
22 import org.apache.geronimo.jetty.JettyWebAppContext;
23
24 /**
25  * @version $Rev: $ $Date: $
26  */

27 public class WebApplicationContextBeforeAfter implements BeforeAfter {
28
29     private final BeforeAfter next;
30     private final int index;
31     private final JettyWebAppContext webAppContext;
32
33     public WebApplicationContextBeforeAfter(BeforeAfter next, int index, JettyWebAppContext webAppContext) {
34         this.next = next;
35         this.index = index;
36         this.webAppContext = webAppContext;
37     }
38
39     public void before(Object JavaDoc[] context, HttpRequest httpRequest, HttpResponse httpResponse) {
40         if (httpResponse != null) {
41             context[index] = httpResponse.getHttpContext();
42             httpResponse.setHttpContext(webAppContext);
43         }
44         if (next != null) {
45             next.before(context, httpRequest, httpResponse);
46         }
47     }
48
49     public void after(Object JavaDoc[] context, HttpRequest httpRequest, HttpResponse httpResponse) {
50         if (next != null) {
51             next.after(context, httpRequest, httpResponse);
52         }
53         if (httpResponse != null) {
54             httpResponse.setHttpContext((HttpContext) context[index]);
55         }
56     }
57 }
58
Popular Tags