Coverage Report - org.codehaus.plexus.classworlds.strategy.OsgiBundleStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
OsgiBundleStrategy
0 %
0/20
0 %
0/10
2,5
 
 1  
 package org.codehaus.plexus.classworlds.strategy;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2010 Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.net.URL;
 21  
 import java.util.Enumeration;
 22  
 
 23  
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 24  
 
 25  
 public class OsgiBundleStrategy
 26  
     extends AbstractStrategy
 27  
 {
 28  
 
 29  
     // java.* from parent
 30  
     // imported packages [Import-Package header with explicit constraints on the exporter]
 31  
     // requires bundle [Required-Bundle]
 32  
     // self [Bundle-Classpath header]
 33  
     // attached fragments
 34  
     //
 35  
     // We need to trya and be OSGi r4 compliant in the loading of all the bundles so that we can try to
 36  
     // load eclipse without requiring equinox. Or any other OSGi container for that matter.
 37  
     public OsgiBundleStrategy( ClassRealm realm )
 38  
     {
 39  0
         super( realm );
 40  0
     }
 41  
 
 42  
     public Class<?> loadClass( String name )
 43  
         throws ClassNotFoundException
 44  
     {
 45  0
         Class<?> clazz = realm.loadClassFromImport( name );
 46  
 
 47  0
         if ( clazz == null )
 48  
         {
 49  0
             clazz = realm.loadClassFromSelf( name );
 50  
 
 51  0
             if ( clazz == null )
 52  
             {
 53  0
                 clazz = realm.loadClassFromParent( name );
 54  
 
 55  0
                 if ( clazz == null )
 56  
                 {
 57  0
                     throw new ClassNotFoundException( name );
 58  
                 }
 59  
             }
 60  
         }
 61  
 
 62  0
         return clazz;
 63  
     }
 64  
 
 65  
     public URL getResource( String name )
 66  
     {
 67  0
         URL resource = realm.loadResourceFromImport( name );
 68  
 
 69  0
         if ( resource == null )
 70  
         {
 71  0
             resource = realm.loadResourceFromSelf( name );
 72  
 
 73  0
             if ( resource == null )
 74  
             {
 75  0
                 resource = realm.loadResourceFromParent( name );
 76  
             }
 77  
         }
 78  
 
 79  0
         return resource;
 80  
     }
 81  
 
 82  
     public Enumeration<URL> getResources( String name )
 83  
         throws IOException
 84  
     {
 85  0
         Enumeration<URL> imports = realm.loadResourcesFromImport( name );
 86  0
         Enumeration<URL> self = realm.loadResourcesFromSelf( name );
 87  0
         Enumeration<URL> parent = realm.loadResourcesFromParent( name );
 88  
 
 89  0
         return combineResources( imports, self, parent );
 90  
     }
 91  
 
 92  
 }