Coverage Report - org.naftulin.configmgr.parsers.JndiParserImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JndiParserImpl
82%
14/17
N/A
0
 
 1  
 package org.naftulin.configmgr.parsers;
 2  
 
 3  
 import java.net.URL;
 4  
 import java.util.List;
 5  
 import java.util.Properties;
 6  
 
 7  
 import javax.naming.InitialContext;
 8  
 import javax.naming.NamingException;
 9  
 
 10  
 import org.naftulin.configmgr.ConfigurationManagementEntry;
 11  
 import org.naftulin.configmgr.ConfigurationManagementEntryImpl;
 12  
 import org.naftulin.configmgr.ConfigurationManagerException;
 13  
 import org.naftulin.configmgr.ConfigurationType;
 14  
 import org.naftulin.configmgr.content.NameValuePairImpl;
 15  
 
 16  
 /*
 17  
  * 
 18  
  */
 19  
 public class JndiParserImpl extends AbstractJndiParser implements ConfigEntryParser {
 20  
         private static final long serialVersionUID = 1L;
 21  
         public JndiParserImpl(final String jndiName, final String initialContextFactory, final List<NameValuePairImpl> nameValuePairs) {
 22  5
                 super(jndiName, initialContextFactory, nameValuePairs);                
 23  5
         }
 24  
 
 25  
         /**
 26  
          * Returns configuratoin management entry that contains an object stored in JNDI under JNDI name provided in configuration descriotion. 
 27  
          * Second sql provided is executed against the database connection and lastly the results are read based on the columns provided in the
 28  
          * configuration.
 29  
          * @param key configuration management key
 30  
          * @param fileUrl file url is null, since jndi configuration is not file URL based.
 31  
          * @return Configuration management entry.
 32  
          */
 33  
         public ConfigurationManagementEntry getConfigurationManagementEntry(
 34  
                         String key, URL fileUrl) throws ConfigurationManagerException {
 35  5
                 ConfigurationManagementEntry entry = null;
 36  
                 // at this point connect to the database, and get the info
 37  5
                 validateParameters(key);
 38  
                 
 39  
                 
 40  5
                 final Properties props = new Properties();
 41  5
                 prepareJndiProperties(props);
 42  
                 
 43  
                 try {
 44  5
                         InitialContext context = null;
 45  5
                         context = getJndiContext(key, props, context);
 46  
                         
 47  5
                         log.info("Initial context created for jndiName " + jndiName);
 48  5
                         final Object content =  context.lookup(jndiName);
 49  5
                         final String fileName = "jndiName : " + jndiName;
 50  
                         
 51  5
                         entry = new ConfigurationManagementEntryImpl(key, fileName, content, this, ConfigurationType.JNDI);
 52  5
                         log.info("configuration management entry created for key " + key + " with jndi name " + jndiName);
 53  0
                 } catch (NamingException e) {
 54  0
                         log.error("Could not lookup jndi name: " + jndiName + " and other parameters from configuration " + key, e);
 55  0
                         throw new ConfigurationManagerException("Could not lookup jndi name: " + jndiName + " and other parameters from configuration " + key, e);
 56  
                 } 
 57  
                 
 58  5
                 return entry;
 59  
         }
 60  
 
 61  
 
 62  
 
 63  
 }