Coverage Report - org.codehaus.plexus.DefaultContainerConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultContainerConfiguration
73 %
70/95
62 %
5/8
1,129
 
 1  
 package org.codehaus.plexus;
 2  
 
 3  
 import java.net.URL;
 4  
 import java.util.ArrayList;
 5  
 import java.util.List;
 6  
 import java.util.Map;
 7  
 
 8  
 import org.codehaus.plexus.classworlds.ClassWorld;
 9  
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 10  
 import org.codehaus.plexus.component.discovery.ComponentDiscoverer;
 11  
 import org.codehaus.plexus.component.discovery.ComponentDiscovererManager;
 12  
 import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
 13  
 import org.codehaus.plexus.component.discovery.DefaultComponentDiscoverer;
 14  
 import org.codehaus.plexus.component.discovery.DefaultComponentDiscovererManager;
 15  
 import org.codehaus.plexus.component.discovery.PlexusXmlComponentDiscoverer;
 16  
 import org.codehaus.plexus.component.factory.ComponentFactoryManager;
 17  
 import org.codehaus.plexus.component.factory.DefaultComponentFactoryManager;
 18  
 import org.codehaus.plexus.component.repository.ComponentRepository;
 19  
 import org.codehaus.plexus.component.repository.DefaultComponentRepository;
 20  
 import org.codehaus.plexus.configuration.source.ConfigurationSource;
 21  
 import org.codehaus.plexus.container.initialization.ContainerInitializationPhase;
 22  
 import org.codehaus.plexus.container.initialization.InitializeComponentDiscovererManagerPhase;
 23  
 import org.codehaus.plexus.container.initialization.InitializeComponentFactoryManagerPhase;
 24  
 import org.codehaus.plexus.container.initialization.InitializeComponentRegistryPhase;
 25  
 import org.codehaus.plexus.container.initialization.InitializeContainerConfigurationSourcePhase;
 26  
 import org.codehaus.plexus.container.initialization.InitializeLoggerManagerPhase;
 27  
 import org.codehaus.plexus.container.initialization.InitializeSystemPropertiesPhase;
 28  
 import org.codehaus.plexus.container.initialization.InitializeUserConfigurationSourcePhase;
 29  
 import org.codehaus.plexus.lifecycle.BasicLifecycleHandler;
 30  
 import org.codehaus.plexus.lifecycle.DefaultLifecycleHandlerManager;
 31  
 import org.codehaus.plexus.lifecycle.LifecycleHandler;
 32  
 import org.codehaus.plexus.lifecycle.LifecycleHandlerManager;
 33  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.ConfigurablePhase;
 34  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.ContextualizePhase;
 35  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.DisposePhase;
 36  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializePhase;
 37  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.LogDisablePhase;
 38  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.LogEnablePhase;
 39  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartPhase;
 40  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StopPhase;
 41  
 
 42  
 /** @author Jason van Zyl */
 43  61
 public class DefaultContainerConfiguration
 44  
     implements ContainerConfiguration
 45  
 {
 46  
     private String name;
 47  
 
 48  
     private Map<Object, Object> context;
 49  
 
 50  
     private ClassWorld classWorld;
 51  
 
 52  
     private ClassRealm realm;
 53  
 
 54  
     private String containerConfiguration;
 55  
 
 56  
     private URL containerConfigurationURL;
 57  
 
 58  
     private ConfigurationSource configurationSource;
 59  
     
 60  61
     private List<Class> componentDiscoverers = new ArrayList<Class>();
 61  
     
 62  61
     private List<Class> componentDiscoveryListeners = new ArrayList<Class>();
 63  
     
 64  
     public ContainerConfiguration setName( String name )
 65  
     {
 66  56
         this.name = name;
 67  
 
 68  56
         return this;
 69  
     }
 70  
 
 71  
     public ContainerConfiguration setContext( Map<Object, Object> context )
 72  
     {
 73  55
         this.context = context;
 74  
 
 75  55
         return this;
 76  
     }
 77  
 
 78  
     public ContainerConfiguration setClassWorld( ClassWorld classWorld )
 79  
     {
 80  3
         this.classWorld = classWorld;
 81  
 
 82  3
         return this;
 83  
     }
 84  
 
 85  
     public ContainerConfiguration setRealm( ClassRealm realm )
 86  
     {
 87  0
         this.realm = realm;
 88  
 
 89  0
         return this;
 90  
     }
 91  
 
 92  
     public ContainerConfiguration setContainerConfiguration( String containerConfiguration )
 93  
     {
 94  56
         this.containerConfiguration = containerConfiguration;
 95  
 
 96  56
         return this;
 97  
     }
 98  
 
 99  
     public String getContainerConfiguration()
 100  
     {
 101  117
         return containerConfiguration;
 102  
     }
 103  
 
 104  
     public ContainerConfiguration setContainerConfigurationURL( URL containerConfiguration )
 105  
     {
 106  0
         this.containerConfigurationURL = containerConfiguration;
 107  
 
 108  0
         return this;
 109  
     }
 110  
 
 111  
     public URL getContainerConfigurationURL()
 112  
     {
 113  61
         return containerConfigurationURL;
 114  
     }
 115  
 
 116  
     public String getName()
 117  
     {
 118  0
         return name;
 119  
     }
 120  
 
 121  
     public Map<Object, Object> getContext()
 122  
     {
 123  116
         return context;
 124  
     }
 125  
 
 126  
     public ClassWorld getClassWorld()
 127  
     {
 128  61
         return classWorld;
 129  
     }
 130  
 
 131  
     public ClassRealm getRealm()
 132  
     {
 133  61
         return realm;
 134  
     }
 135  
 
 136  
     // Programmatic Container Initialization and Setup
 137  
 
 138  
     public ContainerConfiguration setInitializationPhases( ContainerInitializationPhase[] initializationPhases )
 139  
     {
 140  0
         this.initializationPhases = initializationPhases;
 141  
 
 142  0
         return this;
 143  
     }
 144  
 
 145  
     public ContainerInitializationPhase[] getInitializationPhases()
 146  
     {
 147  61
         return initializationPhases;
 148  
     }
 149  
 
 150  61
     private ContainerInitializationPhase[] initializationPhases =
 151  
         {
 152  
             new InitializeComponentRegistryPhase(),
 153  
             new InitializeComponentFactoryManagerPhase(),
 154  
             new InitializeContainerConfigurationSourcePhase(),
 155  
             new InitializeLoggerManagerPhase(),
 156  
             new InitializeSystemPropertiesPhase(),
 157  
             new InitializeComponentDiscovererManagerPhase(),
 158  
             new InitializeUserConfigurationSourcePhase()
 159  
 
 160  
         };
 161  
 
 162  
     // Component discoverer
 163  
 
 164  
     private ComponentDiscovererManager componentDiscovererManager;
 165  
 
 166  
     public ContainerConfiguration addComponentDiscoveryListener( ComponentDiscoveryListener componentDiscoveryListener )
 167  
     {
 168  0
         getComponentDiscovererManager().registerComponentDiscoveryListener( componentDiscoveryListener );
 169  
 
 170  0
         return this;
 171  
     }
 172  
 
 173  
     public ContainerConfiguration addComponentDiscoverer( ComponentDiscoverer componentDiscoverer )
 174  
     {
 175  0
         ((DefaultComponentDiscovererManager)getComponentDiscovererManager()).addComponentDiscoverer( componentDiscoverer );
 176  
 
 177  0
         return this;
 178  
     }
 179  
 
 180  
     public ContainerConfiguration addComponentDiscoverer( Class<?> clazz )
 181  
     {
 182  0
         componentDiscoverers.add( clazz );
 183  0
         return this;
 184  
     }
 185  
 
 186  
     public ContainerConfiguration addComponentDiscoveryListener( Class<?> clazz )
 187  
     {
 188  0
         componentDiscoveryListeners.add( clazz );
 189  0
         return this;
 190  
     }
 191  
 
 192  
     public List<Class> getComponentDiscoverers()
 193  
     {
 194  61
         return componentDiscoverers;
 195  
     }
 196  
 
 197  
     public List<Class> getComponentDiscoveryListeners()
 198  
     {
 199  61
         return componentDiscoveryListeners;
 200  
     }    
 201  
     
 202  
     public ContainerConfiguration setComponentDiscovererManager( ComponentDiscovererManager componentDiscovererManager )
 203  
     {
 204  0
         this.componentDiscovererManager = componentDiscovererManager;
 205  
 
 206  0
         return this;
 207  
     }
 208  
 
 209  
     public ComponentDiscovererManager getComponentDiscovererManager()
 210  
     {
 211  61
         if ( componentDiscovererManager == null )
 212  
         {
 213  61
             componentDiscovererManager = new DefaultComponentDiscovererManager();
 214  
 
 215  61
             ((DefaultComponentDiscovererManager)componentDiscovererManager).addComponentDiscoverer( new DefaultComponentDiscoverer() );
 216  
 
 217  61
             ((DefaultComponentDiscovererManager)componentDiscovererManager).addComponentDiscoverer( new PlexusXmlComponentDiscoverer() );
 218  
         }
 219  
 
 220  61
         return componentDiscovererManager;
 221  
     }
 222  
 
 223  
 
 224  
     private ComponentFactoryManager componentFactoryManager;
 225  
 
 226  
     public ComponentFactoryManager getComponentFactoryManager()
 227  
     {
 228  61
         if ( componentFactoryManager == null )
 229  
         {
 230  61
             componentFactoryManager = new DefaultComponentFactoryManager();                        
 231  
         }
 232  
 
 233  61
         return componentFactoryManager;
 234  
     }
 235  
 
 236  
     public ContainerConfiguration setComponentFactoryManager( ComponentFactoryManager componentFactoryManager )
 237  
     {
 238  0
         this.componentFactoryManager = componentFactoryManager;
 239  
 
 240  0
         return this;
 241  
     }
 242  
 
 243  
     private ComponentRepository componentRepository;
 244  
 
 245  
     public ContainerConfiguration setComponentRepository( ComponentRepository componentRepository )
 246  
     {
 247  0
         this.componentRepository = componentRepository;
 248  
 
 249  0
         return this;
 250  
     }
 251  
 
 252  
     public ComponentRepository getComponentRepository()
 253  
     {
 254  61
         if ( componentRepository == null )
 255  
         {
 256  61
             componentRepository = new DefaultComponentRepository();
 257  
         }
 258  
 
 259  61
         return componentRepository;
 260  
     }
 261  
 
 262  
     // Lifecycle handler manager
 263  
 
 264  
     private LifecycleHandlerManager lifecycleHandlerManager;
 265  
 
 266  
     public ContainerConfiguration addLifecycleHandler( LifecycleHandler lifecycleHandler )
 267  
     {
 268  28
         getLifecycleHandlerManager().addLifecycleHandler( lifecycleHandler );
 269  
 
 270  28
         return this;
 271  
     }
 272  
 
 273  
     public ContainerConfiguration setLifecycleHandlerManager( LifecycleHandlerManager lifecycleHandlerManager )
 274  
     {
 275  0
         this.lifecycleHandlerManager = lifecycleHandlerManager;
 276  
 
 277  0
         return this;
 278  
     }
 279  
 
 280  
     public LifecycleHandlerManager getLifecycleHandlerManager()
 281  
     {
 282  89
         if ( lifecycleHandlerManager == null )
 283  
         {
 284  61
             lifecycleHandlerManager = new DefaultLifecycleHandlerManager();
 285  
 
 286  
             // Plexus
 287  61
             LifecycleHandler plexus = new BasicLifecycleHandler( "plexus" );
 288  
             // Begin
 289  61
             plexus.addBeginSegment( new LogEnablePhase() );
 290  61
             plexus.addBeginSegment( new ContextualizePhase() );
 291  
 //            plexus.addBeginSegment( new AutoConfigurePhase() );
 292  61
             plexus.addBeginSegment( new InitializePhase() );
 293  61
             plexus.addBeginSegment( new StartPhase() );
 294  
             // End
 295  61
             plexus.addEndSegment( new StopPhase() );
 296  61
             plexus.addEndSegment( new DisposePhase() );
 297  61
             plexus.addEndSegment( new LogDisablePhase() );
 298  61
             lifecycleHandlerManager.addLifecycleHandler( plexus );
 299  
 
 300  
             // Basic
 301  61
             LifecycleHandler basic = new BasicLifecycleHandler( "basic" );
 302  
             // Begin
 303  61
             basic.addBeginSegment( new LogEnablePhase() );
 304  61
             basic.addBeginSegment( new ContextualizePhase() );
 305  
 //            basic.addBeginSegment( new AutoConfigurePhase() );
 306  61
             basic.addBeginSegment( new InitializePhase() );
 307  61
             basic.addBeginSegment( new StartPhase() );
 308  
             // End
 309  61
             basic.addEndSegment( new StopPhase() );
 310  61
             basic.addEndSegment( new DisposePhase() );
 311  61
             basic.addEndSegment( new LogDisablePhase() );
 312  61
             lifecycleHandlerManager.addLifecycleHandler( basic );
 313  
 
 314  
             // Plexus configurable
 315  61
             LifecycleHandler plexusConfigurable = new BasicLifecycleHandler( "plexus-configurable" );
 316  
             // Begin
 317  61
             plexusConfigurable.addBeginSegment( new LogEnablePhase() );
 318  61
             plexusConfigurable.addBeginSegment( new ContextualizePhase() );
 319  61
             plexusConfigurable.addBeginSegment( new ConfigurablePhase() );
 320  61
             plexusConfigurable.addBeginSegment( new InitializePhase() );
 321  61
             plexusConfigurable.addBeginSegment( new StartPhase() );
 322  
             // End
 323  61
             plexusConfigurable.addEndSegment( new StopPhase() );
 324  61
             plexusConfigurable.addEndSegment( new DisposePhase() );
 325  61
             plexusConfigurable.addEndSegment( new LogDisablePhase() );
 326  61
             lifecycleHandlerManager.addLifecycleHandler( plexusConfigurable );
 327  
 
 328  
             // Passive
 329  61
             LifecycleHandler passive = new BasicLifecycleHandler( "passive" );
 330  61
             lifecycleHandlerManager.addLifecycleHandler( passive );
 331  
 
 332  
             // Bootstrap
 333  61
             LifecycleHandler bootstrap = new BasicLifecycleHandler( "bootstrap" );
 334  61
             bootstrap.addBeginSegment( new ContextualizePhase() );
 335  61
             lifecycleHandlerManager.addLifecycleHandler( bootstrap );
 336  
         }
 337  
 
 338  89
         return lifecycleHandlerManager;
 339  
     }
 340  
 
 341  
     // Configuration Sources
 342  
 
 343  
     public ContainerConfiguration setConfigurationSource( ConfigurationSource configurationSource )
 344  
     {
 345  0
         this.configurationSource = configurationSource;
 346  
 
 347  0
         return this;
 348  
     }
 349  
 
 350  
     public ConfigurationSource getConfigurationSource()
 351  
     {
 352  61
         return configurationSource;
 353  
     }
 354  
 }