Home » geronimo-2.2-source-release » org.apache.geronimo.naming.java » [javadoc | source]

    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   
   18   package org.apache.geronimo.naming.java;
   19   
   20   import java.util.Properties;
   21   import java.util.Iterator;
   22   import java.util.Map;
   23   import javax.naming.Context;
   24   import javax.naming.InitialContext;
   25   import javax.naming.NamingException;
   26   
   27   import org.apache.geronimo.core.service.Interceptor;
   28   import org.apache.geronimo.core.service.Invocation;
   29   import org.apache.geronimo.core.service.InvocationResult;
   30   
   31   /**
   32    * An interceptor that pushes the current component's java:comp context into
   33    * the java: JNDI namespace
   34    *
   35    * @version $Rev: 149431 $ $Date: 2005-02-01 11:01:15 -0800 (Tue, 01 Feb 2005) $
   36    */
   37   public class ComponentContextInterceptor implements Interceptor {
   38       private final Interceptor next;
   39       private final Context compContext;
   40   
   41       /**
   42        * Constructor specifying the components JNDI Context (java:comp)
   43        * @param compContext the component's JNDI Context
   44        */
   45       public ComponentContextInterceptor(Interceptor next, Context compContext) {
   46           assert next != null;
   47           assert compContext != null;
   48           this.next = next;
   49           this.compContext = compContext;
   50       }
   51   
   52       public InvocationResult invoke(Invocation invocation) throws Throwable {
   53           Context oldContext = RootContext.getComponentContext();
   54           try {
   55               RootContext.setComponentContext(compContext);
   56               return next.invoke(invocation);
   57           } finally {
   58               RootContext.setComponentContext(oldContext);
   59           }
   60       }
   61   }

Home » geronimo-2.2-source-release » org.apache.geronimo.naming.java » [javadoc | source]