Coverage Report - org.mule.config.ConfigResource
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigResource
0%
0/36
0%
0/22
1.9
 
 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;
 8  
 
 9  
 import org.mule.util.IOUtils;
 10  
 
 11  
 import java.io.FileNotFoundException;
 12  
 import java.io.IOException;
 13  
 import java.io.InputStream;
 14  
 import java.net.URL;
 15  
 
 16  
 /**
 17  
  * A ConfigResource holds the url description (or location) and the url stream. It is useful to associate the two
 18  
  * for error reporting when the stream cannot be read.
 19  
  */
 20  
 public class ConfigResource
 21  
 {
 22  
     protected String resourceName;
 23  
     private URL url;
 24  
     private InputStream inputStream;
 25  
 
 26  
     public ConfigResource(String resourceName) throws IOException
 27  0
     {
 28  0
         this.resourceName = resourceName;
 29  0
         url = IOUtils.getResourceAsUrl(resourceName, getClass(), true, true);
 30  0
         if(url == null)
 31  
         {
 32  0
             throw new FileNotFoundException(resourceName);
 33  
         }
 34  0
     }
 35  
 
 36  
     public ConfigResource(URL url)
 37  0
     {
 38  0
         this.url = url;
 39  0
         this.resourceName = url.toExternalForm();
 40  0
     }
 41  
 
 42  
     public ConfigResource(String resourceName, InputStream inputStream)
 43  0
     {
 44  0
         this.inputStream = inputStream;
 45  0
         this.resourceName = resourceName;
 46  0
     }
 47  
 
 48  
     public InputStream getInputStream() throws IOException
 49  
     {
 50  0
         if(inputStream==null && url !=null)
 51  
         {
 52  0
             inputStream = url.openStream();
 53  
         }
 54  0
         return inputStream;
 55  
     }
 56  
 
 57  
     public URL getUrl()
 58  
     {
 59  0
         return url;
 60  
     }
 61  
 
 62  
     public String getResourceName()
 63  
     {
 64  0
         return resourceName;
 65  
     }
 66  
 
 67  
     public boolean isStreamOpen()
 68  
     {
 69  0
         return inputStream!=null;
 70  
     }
 71  
 
 72  
     public boolean equals(Object o)
 73  
     {
 74  0
         if (this == o)
 75  
         {
 76  0
             return true;
 77  
         }
 78  0
         if (o == null || getClass() != o.getClass())
 79  
         {
 80  0
             return false;
 81  
         }
 82  
 
 83  0
         ConfigResource that = (ConfigResource) o;
 84  
 
 85  0
         if (resourceName != null ? !resourceName.equals(that.resourceName) : that.resourceName != null)
 86  
         {
 87  0
             return false;
 88  
         }
 89  
 
 90  0
         return true;
 91  
     }
 92  
 
 93  
     public int hashCode()
 94  
     {
 95  0
         int result = 17;
 96  0
         result = 31 * result + (resourceName != null ? resourceName.hashCode() : 0);
 97  0
         return result;
 98  
     }
 99  
 
 100  
 
 101  
     public String toString()
 102  
     {
 103  0
         final StringBuffer sb = new StringBuffer();
 104  0
         sb.append("ConfigResource");
 105  0
         sb.append("{resourceName='").append(resourceName).append('\'');
 106  0
         sb.append('}');
 107  0
         return sb.toString();
 108  
     }
 109  
 }