01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.jetty6.handler;
17:
18: import java.io.IOException;
19:
20: import javax.naming.Context;
21: import javax.servlet.ServletException;
22: import javax.servlet.http.HttpServletRequest;
23: import javax.servlet.http.HttpServletResponse;
24:
25: import org.apache.geronimo.naming.java.RootContext;
26: import org.mortbay.jetty.Handler;
27:
28: /**
29: * @version $Rev: 601149 $ $Date: 2007-12-04 15:30:18 -0800 (Tue, 04 Dec 2007) $
30: */
31: public class ComponentContextHandler extends AbstractImmutableHandler {
32:
33: private final Context componentContext;
34:
35: public ComponentContextHandler(Handler next,
36: Context componentContext) {
37: super (next);
38: this .componentContext = componentContext;
39: }
40:
41: public void handle(String target, HttpServletRequest request,
42: HttpServletResponse response, int dispatch)
43: throws IOException, ServletException {
44: Context oldContext = RootContext.getComponentContext();
45: try {
46: RootContext.setComponentContext(componentContext);
47: next.handle(target, request, response, dispatch);
48: } finally {
49: RootContext.setComponentContext(oldContext);
50: }
51: }
52:
53: public void lifecycleCommand(LifecycleCommand lifecycleCommand)
54: throws Exception {
55: Context oldContext = RootContext.getComponentContext();
56: try {
57: RootContext.setComponentContext(componentContext);
58: super.lifecycleCommand(lifecycleCommand);
59: } finally {
60: RootContext.setComponentContext(oldContext);
61: }
62: }
63: }
|