Clover coverage report - DNA Site - 1.1
Coverage timestamp: Sun May 2 2004 15:33:21 BST
file stats: LOC: 140   Methods: 5
NCLOC: 70   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
ContainerUtil.java 100% 100% 100% 100%
coverage
 1   
 /*
 2   
  * Copyright (C) The DNA Group. All rights reserved.
 3   
  *
 4   
  * This software is published under the terms of the DNA
 5   
  * Software License version 1.1, a copy of which has been included
 6   
  * with this distribution in the LICENSE.txt file.
 7   
  */
 8   
 package org.codehaus.dna.impl;
 9   
 
 10   
 import org.codehaus.dna.Active;
 11   
 import org.codehaus.dna.Composable;
 12   
 import org.codehaus.dna.Configurable;
 13   
 import org.codehaus.dna.Configuration;
 14   
 import org.codehaus.dna.ConfigurationException;
 15   
 import org.codehaus.dna.LogEnabled;
 16   
 import org.codehaus.dna.Logger;
 17   
 import org.codehaus.dna.MissingResourceException;
 18   
 import org.codehaus.dna.ResourceLocator;
 19   
 
 20   
 /**
 21   
  * Utility class to make it easier to process a object
 22   
  * through its lifecycle stages.
 23   
  *
 24   
  * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
 25   
  */
 26   
 public class ContainerUtil
 27   
 {
 28   
     /**
 29   
      * Supply specified object with Logger if it implements the
 30   
      * LogEnabled interface.
 31   
      *
 32   
      * @param object the object to process
 33   
      * @param logger the logger. If null then the specified object must
 34   
      *        not implement LogEnabled.
 35   
      * @throws IllegalArgumentException if the object is LogEnabled and
 36   
      *         Logger is null
 37   
      */
 38  12
     public static void enableLogging( final Object object,
 39   
                                       final Logger logger )
 40   
     {
 41  12
         if( object instanceof LogEnabled )
 42   
         {
 43  8
             if( null == logger )
 44   
             {
 45  4
                 final String message = "Null logger.";
 46  4
                 throw new IllegalArgumentException( message );
 47   
             }
 48  4
             ( (LogEnabled)object ).enableLogging( logger );
 49   
         }
 50   
     }
 51   
 
 52   
     /**
 53   
      * Supply specified object with ResourceLocator if it implements the
 54   
      * Composable interface.
 55   
      *
 56   
      * @param object the object to process
 57   
      * @param locator the ResourceLocator. If null then the specified
 58   
      *        object must not implement Composable.
 59   
      * @throws IllegalArgumentException if the object is Composable
 60   
      *         and locator is null
 61   
      * @throws MissingResourceException if processing lifecycle stage on
 62   
      *         object throws exception
 63   
      */
 64  12
     public static void compose( final Object object,
 65   
                                 final ResourceLocator locator )
 66   
         throws MissingResourceException
 67   
     {
 68  12
         if( object instanceof Composable )
 69   
         {
 70  8
             if( null == locator )
 71   
             {
 72  4
                 final String message = "Null locator.";
 73  4
                 throw new IllegalArgumentException( message );
 74   
             }
 75  4
             ( (Composable)object ).compose( locator );
 76   
         }
 77   
     }
 78   
 
 79   
     /**
 80   
      * Supply specified object with Configuration if it implements the
 81   
      * Configurable interface.
 82   
      *
 83   
      * @param object the object to process
 84   
      * @param configuration the Configuration. If null then the specified
 85   
      *        object must not implement Configurable.
 86   
      * @throws IllegalArgumentException if the object is Configurable
 87   
      *         and configuration is null
 88   
      * @throws ConfigurationException if processing lifecycle stage on
 89   
      *         object throws exception
 90   
      */
 91  12
     public static void configure( final Object object,
 92   
                                   final Configuration configuration )
 93   
         throws ConfigurationException
 94   
     {
 95  12
         if( object instanceof Configurable )
 96   
         {
 97  8
             if( null == configuration )
 98   
             {
 99  4
                 final String message = "Null configuration.";
 100  4
                 throw new IllegalArgumentException( message );
 101   
             }
 102  4
             ( (Configurable)object ).configure( configuration );
 103   
         }
 104   
     }
 105   
 
 106   
     /**
 107   
      * Initialize specified object if it implements the
 108   
      * Active interface.
 109   
      *
 110   
      * @param object the object to process
 111   
      * @throws Exception if processing lifecycle stage on
 112   
      *         object throws exception
 113   
      */
 114  8
     public static void initialize( final Object object )
 115   
         throws Exception
 116   
     {
 117  8
         if( object instanceof Active )
 118   
         {
 119  4
             ( (Active)object ).initialize();
 120   
         }
 121   
     }
 122   
 
 123   
     /**
 124   
      * Dispose specified object if it implements the
 125   
      * Active interface.
 126   
      *
 127   
      * @param object the object to process
 128   
      * @throws Exception if processing lifecycle stage on
 129   
      *         object throws exception
 130   
      */
 131  8
     public static void dispose( final Object object )
 132   
         throws Exception
 133   
     {
 134  8
         if( object instanceof Active )
 135   
         {
 136  4
             ( (Active)object ).dispose();
 137   
         }
 138   
     }
 139   
 }
 140