KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Set JavaDoc;
20 import javax.resource.ResourceException JavaDoc;
21
22 import org.apache.geronimo.transaction.DefaultInstanceContext;
23 import org.apache.geronimo.transaction.InstanceContext;
24 import org.apache.geronimo.transaction.TrackedConnectionAssociator;
25 import org.mortbay.http.HttpRequest;
26 import org.mortbay.http.HttpResponse;
27
28 /**
29  * @version $Rev: $ $Date: $
30  */

31 public class InstanceContextBeforeAfter implements BeforeAfter {
32     
33     private final BeforeAfter next;
34     private final int index;
35     private final Set JavaDoc unshareableResources;
36     private final Set JavaDoc applicationManagedSecurityResources;
37     private final TrackedConnectionAssociator trackedConnectionAssociator;
38
39     public InstanceContextBeforeAfter(BeforeAfter next, int index, Set JavaDoc unshareableResources, Set JavaDoc applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator) {
40         this.next = next;
41         this.index = index;
42         this.unshareableResources = unshareableResources;
43         this.applicationManagedSecurityResources = applicationManagedSecurityResources;
44         this.trackedConnectionAssociator = trackedConnectionAssociator;
45     }
46
47     public void before(Object JavaDoc[] context, HttpRequest httpRequest, HttpResponse httpResponse) {
48         try {
49             context[index] = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources));
50         } catch (ResourceException JavaDoc e) {
51             throw new RuntimeException JavaDoc(e);
52         }
53         if (next != null) {
54             next.before(context, httpRequest, httpResponse);
55         }
56     }
57
58     public void after(Object JavaDoc[] context, HttpRequest httpRequest, HttpResponse httpResponse) {
59         if (next != null) {
60             next.after(context, httpRequest, httpResponse);
61         }
62         try {
63             trackedConnectionAssociator.exit((InstanceContext) context[index]);
64         } catch (ResourceException JavaDoc e) {
65             throw new RuntimeException JavaDoc(e);
66         }
67     }
68     
69 }
70
Popular Tags