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  
  * $Id: MuleResourceLoader.java 10256 2008-01-08 15:20:25Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.config.spring;
 12  
 
 13  
 import org.mule.util.IOUtils;
 14  
 
 15  
 import java.io.IOException;
 16  
 import java.io.InputStream;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 import org.springframework.core.io.DefaultResourceLoader;
 21  
 import org.springframework.core.io.InputStreamResource;
 22  
 import org.springframework.core.io.Resource;
 23  
 import org.springframework.core.io.support.ResourcePatternResolver;
 24  
 
 25  
 /**
 26  
  * <code>MuleResourceLoader</code> is a custom Spring resource loader that calls
 27  
  * standard Mule methods for loading resource files.
 28  
  */
 29  0
 public class MuleResourceLoader extends DefaultResourceLoader implements ResourcePatternResolver
 30  
 {
 31  0
     protected transient Log logger = LogFactory.getLog(MuleResourceLoader.class);
 32  
 
 33  
     public Resource getResource(String rsc)
 34  
     {
 35  0
         return getResourceByPath(rsc);
 36  
     }
 37  
 
 38  
     protected Resource getResourceByPath(String path)
 39  
     {
 40  0
         InputStream is = null;
 41  
         try
 42  
         {
 43  0
             is = IOUtils.getResourceAsStream(path, getClass());
 44  
         }
 45  0
         catch (IOException e)
 46  
         {
 47  0
             logger.error("Unable to load Spring resource " + path + " : " + e.getMessage());
 48  0
             return null;
 49  0
         }
 50  
 
 51  0
         if (is != null)
 52  
         {
 53  0
             return new InputStreamResource(is);
 54  
         }
 55  
         else
 56  
         {
 57  0
             logger.error("Unable to locate Spring resource " + path);
 58  0
             return null;
 59  
         }
 60  
     }
 61  
 
 62  
     public Resource[] getResources(String rsc) throws IOException
 63  
     {
 64  0
         if (rsc == null)
 65  
         {
 66  0
             throw new IOException("No resources to read");
 67  
         }
 68  0
         String[] resourcesNames = org.springframework.util.StringUtils.tokenizeToStringArray(rsc, ",;", true,
 69  
             true);
 70  0
         Resource[] resources = new Resource[resourcesNames.length];
 71  0
         for (int i = 0; i < resourcesNames.length; ++i)
 72  
         {
 73  0
             resources[i] = getResourceByPath(resourcesNames[i]);
 74  
         }
 75  0
         return resources;
 76  
     }
 77  
 }