1 17 package org.apache.geronimo.jetty.interceptor; 18 19 import java.util.Set ; 20 import javax.resource.ResourceException ; 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 31 public class InstanceContextBeforeAfter implements BeforeAfter { 32 33 private final BeforeAfter next; 34 private final int index; 35 private final Set unshareableResources; 36 private final Set applicationManagedSecurityResources; 37 private final TrackedConnectionAssociator trackedConnectionAssociator; 38 39 public InstanceContextBeforeAfter(BeforeAfter next, int index, Set unshareableResources, Set 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 [] context, HttpRequest httpRequest, HttpResponse httpResponse) { 48 try { 49 context[index] = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources)); 50 } catch (ResourceException e) { 51 throw new RuntimeException (e); 52 } 53 if (next != null) { 54 next.before(context, httpRequest, httpResponse); 55 } 56 } 57 58 public void after(Object [] 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 e) { 65 throw new RuntimeException (e); 66 } 67 } 68 69 } 70 | Popular Tags |