Home » geronimo-2.2-source-release » org.apache.geronimo.tomcat.interceptor » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  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.tomcat.interceptor;
   18   
   19   import java.util.Set;
   20   
   21   import javax.resource.ResourceException;
   22   import javax.servlet.ServletRequest;
   23   import javax.servlet.ServletResponse;
   24   
   25   import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
   26   import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext;
   27   
   28   public class InstanceContextBeforeAfter implements BeforeAfter{
   29   
   30       private final BeforeAfter next;
   31       private final int oldIndex;
   32       private final int newIndex;
   33       private final Set unshareableResources;
   34       private final Set applicationManagedSecurityResources;
   35       private final TrackedConnectionAssociator trackedConnectionAssociator;
   36   
   37       public InstanceContextBeforeAfter(BeforeAfter next, int oldIndex, int newIndex, Set unshareableResources, Set applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator) {
   38           this.next = next;
   39           this.oldIndex = oldIndex;
   40           this.newIndex = newIndex;
   41           this.unshareableResources = unshareableResources;
   42           this.applicationManagedSecurityResources = applicationManagedSecurityResources;
   43           this.trackedConnectionAssociator = trackedConnectionAssociator;
   44       }
   45   
   46       public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse, int dispatch) {
   47           try {
   48               SharedConnectorInstanceContext newConnectorInstanceContext = new SharedConnectorInstanceContext(unshareableResources, applicationManagedSecurityResources, false);
   49               SharedConnectorInstanceContext oldContext = (SharedConnectorInstanceContext) trackedConnectionAssociator.enter(newConnectorInstanceContext);
   50               if (oldContext != null) {
   51                   newConnectorInstanceContext.share(oldContext);
   52               }
   53               context[oldIndex] = oldContext;
   54               context[newIndex] = newConnectorInstanceContext;
   55           } catch (ResourceException e) {
   56               throw new RuntimeException(e);
   57           }
   58           if (next != null) {
   59               next.before(context, httpRequest, httpResponse, dispatch);
   60           }
   61       }
   62   
   63       public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse, int dispatch) {
   64           if (next != null) {
   65               next.after(context, httpRequest, httpResponse, dispatch);
   66           }
   67           try {
   68               SharedConnectorInstanceContext oldConnectorInstanceContext = (SharedConnectorInstanceContext) context[oldIndex];
   69               SharedConnectorInstanceContext newConnectorInstanceContext = (SharedConnectorInstanceContext) context[newIndex];
   70               if (oldConnectorInstanceContext != null) {
   71                   newConnectorInstanceContext.hide();
   72               }
   73               trackedConnectionAssociator.exit(oldConnectorInstanceContext);
   74           } catch (ResourceException e) {
   75               throw new RuntimeException(e);
   76           }
   77       }
   78   }

Home » geronimo-2.2-source-release » org.apache.geronimo.tomcat.interceptor » [javadoc | source]