Home » geronimo-2.2-source-release » org.apache.geronimo.naming.enc » [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   
   18   package org.apache.geronimo.naming.enc;
   19   
   20   import java.util.Collections;
   21   import java.util.HashMap;
   22   import java.util.Iterator;
   23   import java.util.Map;
   24   
   25   import javax.naming.Context;
   26   import javax.naming.NamingException;
   27   import javax.transaction.UserTransaction;
   28   
   29   import org.apache.geronimo.kernel.Kernel;
   30   import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
   31   import org.apache.geronimo.naming.reference.EntryFactory;
   32   import org.apache.geronimo.naming.reference.KernelAwareReference;
   33   import org.apache.xbean.naming.context.ImmutableContext;
   34   
   35   /**
   36    * @version $Rev: 607943 $ $Date: 2008-01-01 15:07:17 -0800 (Tue, 01 Jan 2008) $
   37    */
   38   public final class EnterpriseNamingContext {
   39   
   40       public static Context createEnterpriseNamingContext(Map<String, Object> componentContext, UserTransaction userTransaction, Kernel kernel, ClassLoader classLoader) throws NamingException {
   41           Map<String, Object> map = new HashMap<String, Object>();
   42           if (componentContext != null) {
   43               map.putAll(componentContext);
   44           }
   45   
   46           boolean containsEnv = false;
   47           for (Map.Entry<String, Object> entry: map.entrySet()) {
   48               String name = entry.getKey();
   49               Object value = entry.getValue();
   50   
   51               if (name.startsWith("env/")) {
   52                   containsEnv = true;
   53               }
   54               if (value instanceof EntryFactory) {
   55                   value = ((EntryFactory)value).buildEntry(kernel, classLoader);
   56                   entry.setValue(value);
   57               }
   58               if (value instanceof KernelAwareReference) {
   59                   ((KernelAwareReference) value).setKernel(kernel);
   60               }
   61               if (value instanceof ClassLoaderAwareReference) {
   62                   ((ClassLoaderAwareReference) value).setClassLoader(classLoader);
   63               }
   64           }
   65   
   66           if (!containsEnv) {
   67               Context env = new ImmutableContext("java:comp/env", Collections.EMPTY_MAP, false);
   68               map.put("env", env);
   69           }
   70   
   71           if (userTransaction != null) {
   72               map.put("UserTransaction", userTransaction);
   73           }
   74   
   75           return createEnterpriseNamingContext(map);
   76       }
   77   
   78       public static Context createEnterpriseNamingContext(Map context) throws NamingException {
   79           return new ImmutableContext(context, false);
   80       }
   81   
   82   }

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