Clover coverage report - Code Coverage for hivemind release 1.1-beta-2
Coverage timestamp: Tue Jun 28 2005 10:28:23 EDT
file stats: LOC: 90   Methods: 6
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
URLResource.java 75% 86.7% 83.3% 84%
coverage coverage
 1    // Copyright 2004, 2005 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    package org.apache.hivemind.util;
 15   
 16    import java.io.IOException;
 17    import java.io.InputStream;
 18    import java.net.MalformedURLException;
 19    import java.net.URL;
 20    import java.util.Locale;
 21   
 22    import org.apache.hivemind.ApplicationRuntimeException;
 23    import org.apache.hivemind.Resource;
 24   
 25    /**
 26    * An implementation of {@link org.apache.hivemind.Resource}
 27    * built around a string representation of a URL.
 28    *
 29    * @author Howard Lewis Ship
 30    */
 31    public class URLResource extends AbstractResource
 32    {
 33    private URL _url;
 34   
 35  276 public URLResource( URL url )
 36    {
 37  276 super( url.toString() );
 38  276 _url = url;
 39    }
 40   
 41  17 public URLResource( String path )
 42    {
 43  17 super( path );
 44    }
 45   
 46  67 public String toString()
 47    {
 48  67 return getPath();
 49    }
 50   
 51  17 protected Resource newResource( String path )
 52    {
 53  17 return new URLResource( path );
 54    }
 55   
 56  291 public URL getResourceURL()
 57    {
 58  291 if( _url == null )
 59    {
 60  17 try
 61    {
 62  17 URL test = new URL( getPath() );
 63  17 InputStream stream = test.openStream();
 64  7 if( stream != null )
 65    {
 66  7 stream.close();
 67  7 _url = test;
 68    }
 69    }
 70    catch( MalformedURLException ex )
 71    {
 72  0 throw new ApplicationRuntimeException( ex );
 73    }
 74    catch( IOException ex )
 75    {
 76    // If the resource can't be opened,
 77    // then return null.
 78    }
 79    }
 80  291 return _url;
 81    }
 82   
 83    /**
 84    * Always returns this location; no localization check occurs.
 85    */
 86  0 public Resource getLocalization( Locale locale )
 87    {
 88  0 return this;
 89    }
 90    }