Coverage Report - org.mule.impl.container.JndiContainerContext
 
Classes in this File Line Coverage Branch Coverage Complexity
JndiContainerContext
77%
20/26
88%
7/8
2.444
 
 1  
 /*
 2  
  * $Id: JndiContainerContext.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.impl.container;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.umo.lifecycle.InitialisationException;
 15  
 import org.mule.umo.manager.ContainerException;
 16  
 import org.mule.umo.manager.ObjectNotFoundException;
 17  
 import org.mule.util.ObjectUtils;
 18  
 
 19  
 import java.io.Reader;
 20  
 import java.util.Map;
 21  
 
 22  
 import javax.naming.Context;
 23  
 import javax.naming.InitialContext;
 24  
 import javax.naming.Name;
 25  
 import javax.naming.NamingException;
 26  
 
 27  
 /**
 28  
  * <code>JndiContainerContext</code> is a container implementaiton that exposes a
 29  
  * jndi context. Whatever properties are set on the container in configuration will
 30  
  * be passed to the initial context.
 31  
  */
 32  
 public class JndiContainerContext extends AbstractContainerContext
 33  
 {
 34  
     protected volatile Context context;
 35  
     private volatile Map environment;
 36  
 
 37  
     public JndiContainerContext()
 38  
     {
 39  6
         super("jndi");
 40  6
     }
 41  
 
 42  
     protected JndiContainerContext(String name)
 43  
     {
 44  0
         super(name);
 45  0
     }
 46  
 
 47  
     public Map getEnvironment()
 48  
     {
 49  10
         return environment;
 50  
     }
 51  
 
 52  
     public void setEnvironment(Map environment)
 53  
     {
 54  10
         this.environment = environment;
 55  10
     }
 56  
 
 57  
     public Context getContext()
 58  
     {
 59  12
         return context;
 60  
     }
 61  
 
 62  
     public void setContext(InitialContext context)
 63  
     {
 64  4
         this.context = context;
 65  4
     }
 66  
 
 67  
     public Object getComponent(Object key) throws ObjectNotFoundException
 68  
     {
 69  
         try
 70  
         {
 71  8
             if (key == null)
 72  
             {
 73  2
                 throw new ObjectNotFoundException("null");
 74  
             }
 75  6
             if (key instanceof Name)
 76  
             {
 77  0
                 return context.lookup((Name) key);
 78  
             }
 79  6
             else if (key instanceof Class)
 80  
             {
 81  2
                 return context.lookup(((Class) key).getName());
 82  
             }
 83  
             else
 84  
             {
 85  4
                 return context.lookup(key.toString());
 86  
             }
 87  
         }
 88  2
         catch (NamingException e)
 89  
         {
 90  2
             throw new ObjectNotFoundException(ObjectUtils.toString(key, "null"), e);
 91  
         }
 92  
     }
 93  
 
 94  
     public void configure(Reader configuration) throws ContainerException
 95  
     {
 96  0
         throw new UnsupportedOperationException("configure(Reader)");
 97  
     }
 98  
 
 99  
     public void initialise() throws InitialisationException
 100  
     {
 101  
         try
 102  
         {
 103  12
             if (context == null)
 104  
             {
 105  10
                 context = JndiContextHelper.initialise(getEnvironment());
 106  
             }
 107  
         }
 108  0
         catch (NamingException e)
 109  
         {
 110  0
             throw new InitialisationException(CoreMessages.failedToCreate("Jndi context"), e, this);
 111  12
         }
 112  12
     }
 113  
 }