Coverage Report - org.mule.config.builders.AbstractResourceConfigurationBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractResourceConfigurationBuilder
0%
0/29
0%
0/8
2.333
 
 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.config.builders;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.config.ConfigurationBuilder;
 11  
 import org.mule.api.config.ConfigurationException;
 12  
 import org.mule.config.ConfigResource;
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.util.StringUtils;
 15  
 
 16  
 import java.io.IOException;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  
 /**
 22  
  * Abstract {@link ConfigurationBuilder} implementation used for
 23  
  * ConfigurationBuider's that use one of more configuration resources of the same
 24  
  * type that are defined using strings or {@link ConfigResource} objects.  It is recommended that
 25  
  * {@link org.mule.config.ConfigResource} objects are used over strings since they can be more descriptive, but
 26  
  * Strings will be supported for quite some time.
 27  
  */
 28  
 public abstract class AbstractResourceConfigurationBuilder extends AbstractConfigurationBuilder
 29  
 {
 30  
 
 31  0
     protected static final Log logger = LogFactory.getLog(AutoConfigurationBuilder.class);
 32  
 
 33  
     protected ConfigResource[] configResources;
 34  
 
 35  
     /**
 36  
      * @param configResources a comma separated list of configuration files to load,
 37  
      *            this should be accessible on the classpath or filesystem
 38  
      * @throws org.mule.api.config.ConfigurationException usually if the config resources cannot be loaded
 39  
      */
 40  
     public AbstractResourceConfigurationBuilder(String configResources) throws ConfigurationException
 41  0
     {
 42  0
         this.configResources = loadConfigResources(StringUtils.splitAndTrim(configResources, ",; "));
 43  0
     }
 44  
 
 45  
     /**
 46  
      * @param configResources an array of configuration files to load, this should be
 47  
      *            accessible on the classpath or filesystem
 48  
      * @throws org.mule.api.config.ConfigurationException usually if the config resources cannot be loaded
 49  
      */
 50  
     public AbstractResourceConfigurationBuilder(String[] configResources) throws ConfigurationException
 51  0
     {
 52  0
         this.configResources = loadConfigResources(configResources);
 53  0
     }
 54  
 
 55  
     /**
 56  
      * @param configResources an array Reader oject that provides acces to a configuration either locally or remotely
 57  
      */
 58  
     public AbstractResourceConfigurationBuilder(ConfigResource[] configResources)
 59  0
     {
 60  0
         this.configResources = configResources;
 61  0
     }
 62  
 
 63  
     /**
 64  
      * Override to check for existence of configResouce before invocation, and set
 65  
      * resources n configuration afterwards.
 66  
      */
 67  
     public void configure(MuleContext muleContext) throws ConfigurationException
 68  
     {
 69  0
         if (configResources == null)
 70  
         {
 71  0
             throw new ConfigurationException(CoreMessages.objectIsNull("Configuration Resources"));
 72  
         }
 73  
 
 74  0
         super.configure(muleContext);
 75  
 
 76  0
         logger.info(CoreMessages.configurationBuilderSuccess(this, createConfigResourcesString()));
 77  0
     }
 78  
 
 79  
     protected ConfigResource[] loadConfigResources(String[] configs) throws ConfigurationException
 80  
     {
 81  
         try
 82  
         {
 83  0
             configResources = new ConfigResource[configs.length];
 84  0
             for (int i = 0; i < configs.length; i++)
 85  
             {
 86  0
                 configResources[i] = new ConfigResource(configs[i]);
 87  
             }
 88  0
             return configResources;
 89  
         }
 90  0
         catch (IOException e)
 91  
         {
 92  0
             throw new ConfigurationException(e);
 93  
         }
 94  
     }
 95  
 
 96  
     protected String createConfigResourcesString()
 97  
     {
 98  0
         StringBuffer configResourcesString = new StringBuffer();
 99  0
         configResourcesString.append("[");
 100  0
         for (int i = 0; i < configResources.length; i++)
 101  
         {
 102  0
             configResourcesString.append(configResources[i]);
 103  0
             if (i < configResources.length - 1)
 104  
             {
 105  0
                 configResourcesString.append(", ");
 106  
             }
 107  
         }
 108  0
         configResourcesString.append("]");
 109  0
         return configResourcesString.toString();
 110  
     }
 111  
 }