Clover coverage report - Ledge Container - SNAPSHOT
Coverage timestamp: Fri Nov 17 2006 05:16:03 CET
file stats: LOC: 112   Methods: 5
NCLOC: 48   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CustomizedConfigurationProvider.java 25% 66.7% 100% 66.7%
coverage coverage
 1    //
 2    // Copyright (c) 2003,2004 , Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 3    // All rights reserved.
 4    //
 5    // Redistribution and use in source and binary forms, with or without modification,
 6    // are permitted provided that the following conditions are met:
 7    //
 8    // * Redistributions of source code must retain the above copyright notice,
 9    // this list of conditions and the following disclaimer.
 10    // * Redistributions in binary form must reproduce the above copyright notice,
 11    // this list of conditions and the following disclaimer in the documentation
 12    // and/or other materials provided with the distribution.
 13    // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 14    // nor the names of its contributors may be used to endorse or promote products
 15    // derived from this software without specific prior written permission.
 16    //
 17    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 18    // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19    // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 20    // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 21    // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 22    // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 23    // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 24    // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 25    // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 26    // POSSIBILITY OF SUCH DAMAGE.
 27    //
 28    package org.objectledge.configuration;
 29   
 30    import org.jcontainer.dna.Configuration;
 31    import org.objectledge.pico.customization.CustomizedComponentProvider;
 32    import org.objectledge.pico.customization.UnsupportedKeyTypeException;
 33    import org.picocontainer.PicoContainer;
 34    import org.picocontainer.PicoInitializationException;
 35    import org.picocontainer.PicoIntrospectionException;
 36    import org.picocontainer.PicoVerificationException;
 37   
 38    /**
 39    * Provides Configuration objects to the components being initialized using ConfigurationFactory.
 40    *
 41    * @author <a href="mailto:rafal@caltha.pl">Rafal Krzewski</a>
 42    * @version $Id: CustomizedConfigurationProvider.java,v 1.4 2005/02/04 02:28:03 rafal Exp $
 43    */
 44    public class CustomizedConfigurationProvider
 45    implements CustomizedComponentProvider
 46    {
 47    private ConfigurationFactory configurationFactory;
 48   
 49    /**
 50    * Creates new CustomizedConfigurationProvider instance.
 51    *
 52    * @param configurationFactory the configuration factory.
 53    */
 54  430 public CustomizedConfigurationProvider(ConfigurationFactory configurationFactory)
 55    {
 56  430 this.configurationFactory = configurationFactory;
 57    }
 58   
 59    /**
 60    * {@inheritDoc}
 61    */
 62  344 public Object getCustomizedComponentInstance(PicoContainer container, Object componentKey,
 63    Class componentImplementation)
 64    throws PicoInitializationException, PicoIntrospectionException
 65    {
 66  344 String componentName = getComponentName(componentKey);
 67  344 return configurationFactory.getConfig(componentName, componentImplementation);
 68    }
 69   
 70    /**
 71    * {@inheritDoc}
 72    */
 73  688 public Class getCustomizedComponentImplementation()
 74    {
 75  688 return Configuration.class;
 76    }
 77   
 78    /**
 79    * {@inheritDoc}
 80    */
 81  86 public void verify(PicoContainer container) throws PicoVerificationException
 82    {
 83    // no dependencies
 84    }
 85   
 86    //////////////////////////////////////////////////////////////////////////////////////////////
 87   
 88    /**
 89    * Returns human readable name of the component.
 90    *
 91    * @param componentKey the component key.
 92    * @return human readable name of the component.
 93    * @throws UnsupportedKeyTypeException if the component key is of unsupported type.
 94    */
 95  344 protected String getComponentName(Object componentKey)
 96    throws UnsupportedKeyTypeException
 97    {
 98  344 if(componentKey instanceof Class)
 99    {
 100  344 return ((Class)componentKey).getName();
 101    }
 102  0 else if(componentKey instanceof String)
 103    {
 104  0 return componentKey.toString();
 105    }
 106    else
 107    {
 108  0 throw new UnsupportedKeyTypeException("unsupported component key type "+
 109    componentKey.getClass().getName());
 110    }
 111    }
 112    }