Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl.handlers » [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.concurrent.impl.handlers;
   18   
   19   import java.util.Map;
   20   
   21   import javax.naming.Context;
   22   
   23   import org.apache.commons.logging.Log;
   24   import org.apache.commons.logging.LogFactory;
   25   import org.apache.geronimo.concurrent.ManagedContextHandler;
   26   import org.apache.geronimo.naming.java.RootContext;
   27   
   28   /**
   29    * Geronimo naming context handler. 
   30    */
   31   public class NamingContextHandler implements ManagedContextHandler {
   32   
   33       private final static Log LOG = LogFactory.getLog(NamingContextHandler.class);
   34       
   35       private final static String OLD_CONTEXT = 
   36           NamingContextHandler.class.getName() + ".oldContext";
   37       
   38       private final static String NEW_CONTEXT = 
   39           NamingContextHandler.class.getName() + ".newContext";
   40           
   41       public void saveContext(Map<String, Object> context) {
   42           LOG.debug("saveContext");
   43           
   44           Context componentContext = RootContext.getComponentContext();
   45           if (!UserTransactionContext.hasUserTransaction(componentContext)) {
   46               componentContext = new UserTransactionContext(componentContext);
   47               LOG.debug("java:comp/UserTransaction not found. Using UserTransactionContext");
   48           }
   49           context.put(NEW_CONTEXT, componentContext);
   50       }
   51   
   52       public void setContext(Map<String, Object> threadContext) {
   53           LOG.debug("setContext");
   54           
   55           // save existing context
   56           threadContext.put(OLD_CONTEXT,
   57                             RootContext.getComponentContext());
   58           
   59           // set new context
   60           Context context = (Context)threadContext.get(NEW_CONTEXT);
   61           RootContext.setComponentContext(context);
   62       }
   63   
   64       public void unsetContext(Map<String, Object> threadContext) {
   65           LOG.debug("unsetContext");
   66           
   67           // restore old context
   68           Context context = (Context)threadContext.get(OLD_CONTEXT);
   69           RootContext.setComponentContext(context);       
   70       }
   71     
   72   }

Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl.handlers » [javadoc | source]