Coverage Report - org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
SelfFirstStrategy
100 %
20/20
90 %
9/10
2,5
 
 1  
 package org.codehaus.plexus.classworlds.strategy;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 Codehaus Foundation.
 5  
  * 
 6  
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 7  
  * in compliance with the License. You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software distributed under the License
 12  
  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 13  
  * or implied. See the License for the specific language governing permissions and limitations under
 14  
  * the License.
 15  
  */
 16  
 
 17  
 import java.io.IOException;
 18  
 import java.net.URL;
 19  
 import java.util.Enumeration;
 20  
 
 21  
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 22  
 
 23  
 /**
 24  
  * @author Jason van Zyl
 25  
  */
 26  
 public class SelfFirstStrategy
 27  
     extends AbstractStrategy
 28  
 {
 29  
 
 30  
     public SelfFirstStrategy( ClassRealm realm )
 31  
     {
 32  303
         super( realm );
 33  303
     }
 34  
 
 35  
     public Class<?> loadClass( String name )
 36  
         throws ClassNotFoundException
 37  
     {
 38  451
         Class<?> clazz = realm.loadClassFromImport( name );
 39  
 
 40  451
         if ( clazz == null )
 41  
         {
 42  444
             clazz = realm.loadClassFromSelf( name );
 43  
 
 44  444
             if ( clazz == null )
 45  
             {
 46  22
                 clazz = realm.loadClassFromParent( name );
 47  
 
 48  22
                 if ( clazz == null )
 49  
                 {
 50  12
                     throw new ClassNotFoundException( name );
 51  
                 }
 52  
             }
 53  
         }
 54  
 
 55  439
         return clazz;
 56  
     }
 57  
 
 58  
     public URL getResource( String name )
 59  
     {
 60  3
         URL resource = realm.loadResourceFromImport( name );
 61  
 
 62  3
         if ( resource == null )
 63  
         {
 64  3
             resource = realm.loadResourceFromSelf( name );
 65  
 
 66  3
             if ( resource == null )
 67  
             {
 68  2
                 resource = realm.loadResourceFromParent( name );
 69  
             }
 70  
         }
 71  
 
 72  3
         return resource;
 73  
     }
 74  
 
 75  
     public Enumeration<URL> getResources( String name )
 76  
         throws IOException
 77  
     {
 78  13
         Enumeration<URL> imports = realm.loadResourcesFromImport( name );
 79  13
         Enumeration<URL> self = realm.loadResourcesFromSelf( name );
 80  13
         Enumeration<URL> parent = realm.loadResourcesFromParent( name );
 81  
 
 82  13
         return combineResources( imports, self, parent );
 83  
     }
 84  
 
 85  
 }