Coverage Report - org.mule.transport.jms.jndi.AbstractJndiNameResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractJndiNameResolver
0%
0/32
0%
0/14
0
AbstractJndiNameResolver$1
0%
0/2
N/A
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.MuleException;
 10  
 import org.mule.api.lifecycle.InitialisationException;
 11  
 
 12  
 import java.util.Hashtable;
 13  
 import java.util.Map;
 14  
 
 15  
 import javax.naming.Context;
 16  
 import javax.naming.InitialContext;
 17  
 import javax.naming.NamingException;
 18  
 import javax.naming.spi.InitialContextFactory;
 19  
 
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 
 23  0
 public abstract class AbstractJndiNameResolver implements JndiNameResolver
 24  
 {
 25  
 
 26  0
     protected final Log logger = LogFactory.getLog(getClass());
 27  
 
 28  
     private String jndiProviderUrl;
 29  
     private String jndiInitialFactory;
 30  
     private Map jndiProviderProperties;
 31  
 
 32  
     // Default contextFactory
 33  0
     private InitialContextFactory contextFactory = new InitialContextFactory()
 34  0
     {
 35  
         public Context getInitialContext(Hashtable<?, ?> hashtable) throws NamingException
 36  
         {
 37  0
             return new InitialContext(hashtable);
 38  
         }
 39  
     };
 40  
 
 41  
     /**
 42  
      * Creates a JNDI context using the current {@link #contextFactory}
 43  
      *
 44  
      * @return a new {@link Context} instance. Callers must provide concurrent
 45  
      *         access control on the returned value.
 46  
      * @throws NamingException if there is a problem during the context creation.
 47  
      */
 48  
     protected Context createInitialContext() throws NamingException
 49  
     {
 50  0
         return contextFactory.getInitialContext(getContextProperties());
 51  
     }
 52  
 
 53  
     protected Hashtable getContextProperties()
 54  
     {
 55  0
         if ((jndiInitialFactory == null) && (jndiProviderProperties == null
 56  
                                              || !jndiProviderProperties.containsKey(Context.INITIAL_CONTEXT_FACTORY)))
 57  
         {
 58  0
             throw new IllegalArgumentException("Undefined value for jndiInitialFactory property");
 59  
         }
 60  
 
 61  0
         Hashtable<String, Object> props = new Hashtable<String, Object>();
 62  
 
 63  0
         if (jndiInitialFactory != null)
 64  
         {
 65  0
             props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory);
 66  
         }
 67  
 
 68  0
         if (jndiProviderUrl != null)
 69  
         {
 70  0
             props.put(Context.PROVIDER_URL, jndiProviderUrl);
 71  
         }
 72  
 
 73  0
         if (jndiProviderProperties != null)
 74  
         {
 75  0
             props.putAll(jndiProviderProperties);
 76  
         }
 77  
 
 78  0
         return props;
 79  
     }
 80  
 
 81  
     public String getJndiProviderUrl()
 82  
     {
 83  0
         return jndiProviderUrl;
 84  
     }
 85  
 
 86  
     public void setJndiProviderUrl(String jndiProviderUrl)
 87  
     {
 88  0
         this.jndiProviderUrl = jndiProviderUrl;
 89  0
     }
 90  
 
 91  
     public String getJndiInitialFactory()
 92  
     {
 93  0
         return jndiInitialFactory;
 94  
     }
 95  
 
 96  
     public void setJndiInitialFactory(String jndiInitialFactory)
 97  
     {
 98  0
         this.jndiInitialFactory = jndiInitialFactory;
 99  0
     }
 100  
 
 101  
     public Map getJndiProviderProperties()
 102  
     {
 103  0
         return jndiProviderProperties;
 104  
     }
 105  
 
 106  
     public void setJndiProviderProperties(Map jndiProviderProperties)
 107  
     {
 108  0
         this.jndiProviderProperties = jndiProviderProperties;
 109  0
     }
 110  
 
 111  
     public InitialContextFactory getContextFactory()
 112  
     {
 113  0
         return contextFactory;
 114  
     }
 115  
 
 116  
     public void setContextFactory(InitialContextFactory contextFactory)
 117  
     {
 118  0
         if (contextFactory == null)
 119  
         {
 120  0
             throw new IllegalArgumentException("Context factory cannot be null");
 121  
         }
 122  
 
 123  0
         this.contextFactory = contextFactory;
 124  0
     }
 125  
 
 126  
     public void dispose()
 127  
     {
 128  
         // Does nothing
 129  0
     }
 130  
 
 131  
     public void initialise() throws InitialisationException
 132  
     {
 133  
         // Does nothing
 134  0
     }
 135  
 
 136  
     public void start() throws MuleException
 137  
     {
 138  
         // Does nothing
 139  0
     }
 140  
 
 141  
     public void stop() throws MuleException
 142  
     {
 143  
         // Does nothing
 144  0
     }
 145  
 }