Clover coverage report - Code Coverage for hivemind release 1.0-rc-2
Coverage timestamp: Sat Sep 11 2004 09:09:48 EDT
file stats: LOC: 97   Methods: 6
NCLOC: 54   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
URLResource.java 100% 85.7% 83.3% 86.4%
coverage coverage
 1   
 //  Copyright 2004 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.util;
 16   
 
 17   
 import java.io.IOException;
 18   
 import java.io.InputStream;
 19   
 import java.net.MalformedURLException;
 20   
 import java.net.URL;
 21   
 import java.util.Locale;
 22   
 
 23   
 import org.apache.hivemind.ApplicationRuntimeException;
 24   
 import org.apache.hivemind.Resource;
 25   
 
 26   
 /**
 27   
  * An implementation of {@link org.apache.hivemind.Resource}
 28   
  * built around a string representation of a URL.  
 29   
  *
 30   
  * @author Howard Lewis Ship
 31   
  */
 32   
 public class URLResource extends AbstractResource
 33   
 {
 34   
     private URL _url;
 35   
 
 36  229
     public URLResource(URL url)
 37   
     {
 38  229
         super(url.toString());
 39   
 
 40  229
         _url = url;
 41   
     }
 42   
 
 43  49
     public URLResource(String path)
 44   
     {
 45  49
         super(path);
 46   
     }
 47   
 
 48  55
     public String toString()
 49   
     {
 50  55
         return getPath();
 51   
     }
 52   
 
 53  49
     protected Resource newResource(String path)
 54   
     {
 55  49
         return new URLResource(path);
 56   
     }
 57   
 
 58  265
     public URL getResourceURL()
 59   
     {
 60  265
         if (_url == null)
 61   
         {
 62  49
             try
 63   
             {
 64  49
                 URL test = new URL(getPath());
 65   
 
 66  49
                 InputStream stream = test.openStream();
 67   
 
 68  16
                 stream.close();
 69   
 
 70  16
                 _url = test;
 71   
             }
 72   
             catch (MalformedURLException ex)
 73   
             {
 74  0
                 throw new ApplicationRuntimeException(ex);
 75   
             }
 76   
             catch (IOException ex)
 77   
             {
 78   
                 // If the resource can't be opened,
 79   
                 // then return null.
 80   
             }
 81   
 
 82   
         }
 83   
 
 84  265
         return _url;
 85   
 
 86   
     }
 87   
 
 88   
     /**
 89   
      * Always returns this location; no localization check occurs.
 90   
      */
 91  0
     public Resource getLocalization(Locale locale)
 92   
     {
 93  0
         return this;
 94   
     }
 95   
 
 96   
 }
 97