Coverage Report - org.mule.transport.jms.jndi.SimpleJndiNameResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleJndiNameResolver
0%
0/17
0%
0/4
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.jms.jndi;
 8  
 
 9  
 import org.mule.api.lifecycle.InitialisationException;
 10  
 
 11  
 import javax.naming.Context;
 12  
 import javax.naming.NamingException;
 13  
 
 14  
 /**
 15  
  * Defines a simple {@link JndiNameResolver} that maintains a {@link Context}
 16  
  * instance opened all the time and always relies on the context to do the look
 17  
  * ups.
 18  
  */
 19  0
 public class SimpleJndiNameResolver extends AbstractJndiNameResolver
 20  
 {
 21  
 
 22  
     // @GuardedBy(this)
 23  
     private Context jndiContext;
 24  
 
 25  
     public synchronized Object lookup(String name) throws NamingException
 26  
     {
 27  0
         return jndiContext.lookup(name);
 28  
     }
 29  
 
 30  
     public void initialise() throws InitialisationException
 31  
     {
 32  0
         if (jndiContext == null)
 33  
         {
 34  
             try
 35  
             {
 36  0
                 jndiContext = createInitialContext();
 37  
             }
 38  0
             catch (NamingException e)
 39  
             {
 40  0
                 throw new InitialisationException(e, this);
 41  0
             }
 42  
         }
 43  0
     }
 44  
 
 45  
     @Override
 46  
     public void dispose()
 47  
     {
 48  0
         if (jndiContext != null)
 49  
         {
 50  
             try
 51  
             {
 52  0
                 jndiContext.close();
 53  0
             }
 54  0
             catch (NamingException e)
 55  
             {
 56  0
                 logger.error("Jms connector failed to dispose properly: ", e);
 57  0
             }
 58  
             finally
 59  
             {
 60  0
                 jndiContext = null;
 61  0
             }
 62  
         }
 63  0
     }
 64  
 }