Coverage Report - org.mule.config.ReaderResource
 
Classes in this File Line Coverage Branch Coverage Complexity
ReaderResource
0%
0/16
0%
0/3
1.6
 
 1  
 /*
 2  
  * $Id: ReaderResource.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.util.IOUtils;
 15  
 import org.mule.util.StringUtils;
 16  
 
 17  
 import java.io.IOException;
 18  
 import java.io.InputStream;
 19  
 import java.io.InputStreamReader;
 20  
 import java.io.Reader;
 21  
 
 22  
 /**
 23  
  * <code>ReaderResource</code> is a reader with a description associated with it.
 24  
  * This is useful for error resolution as the reader description can be included when
 25  
  * reporting errors during reading the resource.
 26  
  */
 27  
 public class ReaderResource
 28  
 {
 29  
 
 30  
     private String description;
 31  
     private Reader reader;
 32  
 
 33  
     public ReaderResource(String description, Reader reader)
 34  0
     {
 35  0
         this.description = description;
 36  0
         this.reader = reader;
 37  0
     }
 38  
 
 39  
     public String getDescription()
 40  
     {
 41  0
         return description;
 42  
     }
 43  
 
 44  
     public Reader getReader()
 45  
     {
 46  0
         return reader;
 47  
     }
 48  
 
 49  
     public static ReaderResource[] parseResources(String configResources, String encoding) throws IOException
 50  
     {
 51  0
         String[] resources = StringUtils.splitAndTrim(configResources, ",");
 52  0
         MuleManager.getConfiguration().setConfigResources(resources);
 53  0
         ReaderResource[] readers = new ReaderResource[resources.length];
 54  0
         for (int i = 0; i < resources.length; i++)
 55  
         {
 56  0
             InputStream is = IOUtils.getResourceAsStream(resources[i].trim(), ReaderResource.class);
 57  0
             if (is == null)
 58  
             {
 59  0
                 throw new IOException("could not load resource: " + resources[i].trim());
 60  
             }
 61  0
             readers[i] = new ReaderResource(resources[i].trim(), new InputStreamReader(is, encoding));
 62  
         }
 63  0
         return readers;
 64  
     }
 65  
 
 66  
     public static ReaderResource[] parseResources(String configResources) throws IOException
 67  
     {
 68  0
         return parseResources(configResources, MuleManager.getConfiguration().getEncoding());
 69  
     }
 70  
 }