Clover coverage report - PicoContainer - 1.0-beta-1
Coverage timestamp: Thu Aug 14 2003 23:16:27 BST
file stats: LOC: 110   Methods: 9
NCLOC: 82   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
DefaultLifecyclePicoAdaptor.java 100% 100% 100% 100%
coverage
 1   
 /*****************************************************************************
 2   
  * Copyright (C) PicoContainer Organization. All rights reserved.            *
 3   
  * ------------------------------------------------------------------------- *
 4   
  * The software in this package is published under the terms of the BSD      *
 5   
  * style license a copy of which has been included with this distribution in *
 6   
  * the license.html file.                                                    *
 7   
  *                                                                           *
 8   
  * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
 9   
  *****************************************************************************/
 10   
 
 11   
 package org.picocontainer.extras;
 12   
 
 13   
 import org.picocontainer.PicoContainer;
 14   
 import org.picocontainer.lifecycle.LifecyclePicoAdaptor;
 15   
 import org.picocontainer.lifecycle.Startable;
 16   
 import org.picocontainer.lifecycle.Stoppable;
 17   
 import org.picocontainer.lifecycle.Disposable;
 18   
 
 19   
 public class DefaultLifecyclePicoAdaptor implements LifecyclePicoAdaptor {
 20   
 
 21   
     private Startable startableAggregatedComponent;
 22   
     private Stoppable stoppableAggregatedComponent;
 23   
     private Disposable disposableAggregatedComponent;
 24   
     private boolean started;
 25   
     private boolean disposed;
 26   
     private final PicoContainer picoContainer;
 27   
 
 28  7
     public DefaultLifecyclePicoAdaptor(PicoContainer picoContainer) {
 29  7
         this.picoContainer = picoContainer;
 30   
     }
 31   
 
 32  6
     public boolean isStarted() {
 33  6
         return started;
 34   
     }
 35   
 
 36  7
     public boolean isStopped() {
 37  7
         return !started;
 38   
     }
 39   
 
 40  3
     public boolean isDisposed() {
 41  3
         return disposed;
 42   
     }
 43   
 
 44  19
     private void initializeIfNotInitialized() {
 45  19
         if (startableAggregatedComponent == null) {
 46  14
             try {
 47  14
                 startableAggregatedComponent = (Startable) picoContainer.getComponentMulticaster(true, false);
 48   
             } catch (ClassCastException e) {
 49   
             }
 50   
         }
 51  19
         if (stoppableAggregatedComponent == null) {
 52  14
             try {
 53   
 
 54  14
                 stoppableAggregatedComponent = (Stoppable) picoContainer.getComponentMulticaster(false, false);
 55   
             } catch (ClassCastException e) {
 56   
             }
 57   
         }
 58  19
         if (disposableAggregatedComponent == null) {
 59  17
             try {
 60   
                 //TODO-Aslak broken ?
 61  17
                 Object o = picoContainer.getComponentMulticaster(false, false);
 62  17
                 disposableAggregatedComponent = (Disposable) o;
 63   
             } catch (ClassCastException e) {
 64   
             }
 65   
         }
 66   
 
 67   
     }
 68   
 
 69  9
     public void start() throws Exception {
 70  9
         checkDisposed();
 71  9
         initializeIfNotInitialized();
 72  9
         if (started) {
 73  1
             throw new IllegalStateException("Already started.");
 74   
         }
 75  8
         started = true;
 76  8
         if (startableAggregatedComponent != null) {
 77  3
             startableAggregatedComponent.start();
 78   
         }
 79   
     }
 80   
 
 81  7
     public void stop() throws Exception {
 82  7
         checkDisposed();
 83  7
         initializeIfNotInitialized();
 84  7
         if (started == false) {
 85  1
             throw new IllegalStateException("Already stopped.");
 86   
         }
 87  6
         started = false;
 88  6
         if (stoppableAggregatedComponent != null) {
 89  3
             stoppableAggregatedComponent.stop();
 90   
         }
 91   
     }
 92   
 
 93  5
     public void dispose() throws Exception {
 94  5
         checkDisposed();
 95  3
         initializeIfNotInitialized();
 96  3
         disposed = true;
 97  3
         if (disposableAggregatedComponent != null) {
 98  1
             disposableAggregatedComponent.dispose();
 99   
         }
 100   
     }
 101   
 
 102  21
     private void checkDisposed() {
 103  21
         if (disposed) {
 104  2
             throw new IllegalStateException("Components Disposed Of");
 105   
         }
 106   
     }
 107   
 
 108   
 }
 109   
 
 110