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.tomcat.interceptor;
17:
18: import java.util.Set;
19:
20: import javax.resource.ResourceException;
21: import javax.servlet.ServletRequest;
22: import javax.servlet.ServletResponse;
23:
24: import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
25: import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext;
26:
27: public class InstanceContextBeforeAfter implements BeforeAfter {
28:
29: private final BeforeAfter next;
30: private final int oldIndex;
31: private final int newIndex;
32: private final Set unshareableResources;
33: private final Set applicationManagedSecurityResources;
34: private final TrackedConnectionAssociator trackedConnectionAssociator;
35:
36: public InstanceContextBeforeAfter(BeforeAfter next, int oldIndex,
37: int newIndex, Set unshareableResources,
38: Set applicationManagedSecurityResources,
39: TrackedConnectionAssociator trackedConnectionAssociator) {
40: this .next = next;
41: this .oldIndex = oldIndex;
42: this .newIndex = newIndex;
43: this .unshareableResources = unshareableResources;
44: this .applicationManagedSecurityResources = applicationManagedSecurityResources;
45: this .trackedConnectionAssociator = trackedConnectionAssociator;
46: }
47:
48: public void before(Object[] context, ServletRequest httpRequest,
49: ServletResponse httpResponse, int dispatch) {
50: try {
51: SharedConnectorInstanceContext newConnectorInstanceContext = new SharedConnectorInstanceContext(
52: unshareableResources,
53: applicationManagedSecurityResources, false);
54: SharedConnectorInstanceContext oldContext = (SharedConnectorInstanceContext) trackedConnectionAssociator
55: .enter(newConnectorInstanceContext);
56: if (oldContext != null) {
57: newConnectorInstanceContext.share(oldContext);
58: }
59: context[oldIndex] = oldContext;
60: context[newIndex] = newConnectorInstanceContext;
61: } catch (ResourceException e) {
62: throw new RuntimeException(e);
63: }
64: if (next != null) {
65: next.before(context, httpRequest, httpResponse, dispatch);
66: }
67: }
68:
69: public void after(Object[] context, ServletRequest httpRequest,
70: ServletResponse httpResponse, int dispatch) {
71: if (next != null) {
72: next.after(context, httpRequest, httpResponse, dispatch);
73: }
74: try {
75: SharedConnectorInstanceContext oldConnectorInstanceContext = (SharedConnectorInstanceContext) context[oldIndex];
76: SharedConnectorInstanceContext newConnectorInstanceContext = (SharedConnectorInstanceContext) context[newIndex];
77: if (oldConnectorInstanceContext != null) {
78: newConnectorInstanceContext.hide();
79: }
80: trackedConnectionAssociator
81: .exit(oldConnectorInstanceContext);
82: } catch (ResourceException e) {
83: throw new RuntimeException(e);
84: }
85: }
86: }
|