Coverage Report - org.mule.config.spring.MuleResourceLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleResourceLoader
0%
0/20
0%
0/6
3.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.spring;
 8  
 
 9  
 import org.mule.util.IOUtils;
 10  
 
 11  
 import java.io.IOException;
 12  
 import java.io.InputStream;
 13  
 
 14  
 import org.apache.commons.logging.Log;
 15  
 import org.apache.commons.logging.LogFactory;
 16  
 import org.springframework.core.io.DefaultResourceLoader;
 17  
 import org.springframework.core.io.InputStreamResource;
 18  
 import org.springframework.core.io.Resource;
 19  
 import org.springframework.core.io.support.ResourcePatternResolver;
 20  
 
 21  
 /**
 22  
  * <code>MuleResourceLoader</code> is a custom Spring resource loader that calls
 23  
  * standard Mule methods for loading resource files.
 24  
  */
 25  0
 public class MuleResourceLoader extends DefaultResourceLoader implements ResourcePatternResolver
 26  
 {
 27  0
     protected transient Log logger = LogFactory.getLog(MuleResourceLoader.class);
 28  
 
 29  
     public Resource getResource(String rsc)
 30  
     {
 31  0
         return getResourceByPath(rsc);
 32  
     }
 33  
 
 34  
     protected Resource getResourceByPath(String path)
 35  
     {
 36  0
         InputStream is = null;
 37  
         try
 38  
         {
 39  0
             is = IOUtils.getResourceAsStream(path, getClass());
 40  
         }
 41  0
         catch (IOException e)
 42  
         {
 43  0
             logger.error("Unable to load Spring resource " + path + " : " + e.getMessage());
 44  0
             return null;
 45  0
         }
 46  
 
 47  0
         if (is != null)
 48  
         {
 49  0
             return new InputStreamResource(is);
 50  
         }
 51  
         else
 52  
         {
 53  0
             logger.error("Unable to locate Spring resource " + path);
 54  0
             return null;
 55  
         }
 56  
     }
 57  
 
 58  
     public Resource[] getResources(String rsc) throws IOException
 59  
     {
 60  0
         if (rsc == null)
 61  
         {
 62  0
             throw new IOException("No resources to read");
 63  
         }
 64  0
         String[] resourcesNames = org.springframework.util.StringUtils.tokenizeToStringArray(rsc, ",;", true,
 65  
             true);
 66  0
         Resource[] resources = new Resource[resourcesNames.length];
 67  0
         for (int i = 0; i < resourcesNames.length; ++i)
 68  
         {
 69  0
             resources[i] = getResourceByPath(resourcesNames[i]);
 70  
         }
 71  0
         return resources;
 72  
     }
 73  
 }