Coverage Report - org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassRealmConverter
35 %
7/20
16 %
2/12
1,833
 
 1  
 package org.codehaus.plexus.component.configurator.converters.special;
 2  
 
 3  
 import org.codehaus.classworlds.ClassRealmAdapter;
 4  
 import org.codehaus.classworlds.ClassRealmReverseAdapter;
 5  
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 6  
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
 7  
 import org.codehaus.plexus.component.configurator.ConfigurationListener;
 8  
 import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
 9  
 import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
 10  
 import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
 11  
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
 12  
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 13  
 
 14  
 /**
 15  
  * ConfigurationConverter to set up ClassRealm component fields.
 16  
  *
 17  
  * @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
 18  
  */
 19  
 public class ClassRealmConverter
 20  
     extends AbstractConfigurationConverter
 21  
 {
 22  1
     public static final String ROLE = ConfigurationConverter.class.getName();
 23  
 
 24  
     private ClassRealm classRealm;
 25  
 
 26  
     /**
 27  
      * Constructs this ClassRealmConverter with the given ClassRealm.
 28  
      * If there's a way to automatically configure this component
 29  
      * using the current classrealm, this method can go away.
 30  
      *
 31  
      * @param classRealm
 32  
      */
 33  
     public ClassRealmConverter( ClassRealm classRealm )
 34  66
     {
 35  66
         setClassRealm( classRealm );
 36  66
     }
 37  
 
 38  
     @Deprecated
 39  
     public ClassRealmConverter( final org.codehaus.classworlds.ClassRealm classRealm )
 40  0
     {
 41  0
         setClassRealm( classRealm );
 42  0
     }
 43  
 
 44  
     public void setClassRealm( final ClassRealm classRealm )
 45  
     {
 46  66
         this.classRealm = classRealm;
 47  66
     }
 48  
 
 49  
     @Deprecated
 50  
     public void setClassRealm( final org.codehaus.classworlds.ClassRealm classRealm )
 51  
     {
 52  0
         if ( classRealm.getClassLoader() instanceof ClassRealm )
 53  
         {
 54  0
             setClassRealm( (ClassRealm) classRealm.getClassLoader() );
 55  
         }
 56  
         else
 57  
         {
 58  0
             setClassRealm( ClassRealmReverseAdapter.getInstance( classRealm ) );
 59  
         }
 60  0
     }
 61  
 
 62  
     public boolean canConvert( Class type )
 63  
     {
 64  
         // backwards compatibility for old ClassWorld fields
 65  132
         return org.codehaus.classworlds.ClassRealm.class.isAssignableFrom( type )
 66  
             || ClassRealm.class.isAssignableFrom( type );
 67  
     }
 68  
 
 69  
     public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
 70  
                                      Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
 71  
                                      ConfigurationListener listener )
 72  
         throws ComponentConfigurationException
 73  
     {
 74  0
         Object retValue = fromExpression( configuration, expressionEvaluator, type );
 75  
 
 76  0
         if ( retValue == null )
 77  
         {
 78  0
             retValue = classRealm;
 79  
         }
 80  
 
 81  
         // backwards compatibility for old ClassWorld fields
 82  0
         if ( retValue instanceof ClassRealm && org.codehaus.classworlds.ClassRealm.class.isAssignableFrom( type ) )
 83  
         {
 84  0
             retValue = ClassRealmAdapter.getInstance( (ClassRealm) retValue );
 85  
         }
 86  
 
 87  0
         return retValue;
 88  
     }
 89  
 
 90  
 }