Clover coverage report - Maven Clover report
Coverage timestamp: Mon Sep 3 2007 08:24:07 EEST
file stats: LOC: 143   Methods: 7
NCLOC: 75   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PropertiesBasedFactory.java 100% 81% 100% 88.2%
coverage coverage
 1    package com.sourceforge.jpatterns.core.configuration;
 2   
 3    import com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException;
 4    import com.sourceforge.jpatterns.core.configuration.model.IJPatternsConfigBeansBuilder;
 5    import com.sourceforge.jpatterns.patterns.factory.IJPFactory;
 6    import com.sourceforge.jpatterns.utils.JPatternsPropsUtils;
 7    import com.zmicer.utils.LoggingUtils;
 8    import org.apache.log4j.Logger;
 9   
 10    /**
 11    * This factory uses the {@link PropertiesManagerImpl} to instantiate the instances of the particular classes are based on the
 12    * properties definitions. The properties based configuration is done only for the "core" initial components allows us to implement
 13    * the "factory" pattern. After it the JPatterns framework would use this implemented factory for instantiating all the stuff we
 14    * would use to imlement other patterns.
 15    * <br/>
 16    * This is singleton - there is no sense to have several instances of this class
 17    *
 18    * $Author:: zmicer $<br/>
 19    * $Rev:: 67 $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
 20    * $Date:: 2007-08-28 21:37:07 #$<br/>
 21    *
 22    * @version 1.0
 23    */
 24    public class PropertiesBasedFactory
 25    {
 26    /**
 27    * Logger instance.
 28    */
 29    final public static Logger LOG = Logger.getLogger(PropertiesBasedFactory.class);
 30   
 31    /**
 32    * The singleton instance of this class to be retreved by the <code>getInstance</code> method.
 33    */
 34    private static PropertiesBasedFactory FACTORY;
 35   
 36    /**
 37    * The implementation of the <code>IJPConfigurator</code> interface
 38    */
 39    private IJPConfigurator m_jpConfigurator = null;
 40   
 41    /**
 42    * Static instance of the properties manager.
 43    */
 44    private static IPropertiesManager propertiesManager;
 45   
 46   
 47    /**
 48    * The default private constructor.
 49    * <br/>
 50    * Please be carefull in adding some initialization functionality at this constructor - this is singleton, and the call of the
 51    * constructor is done at the static initialization level.
 52    */
 53  1 private PropertiesBasedFactory()
 54    {
 55  1 super();
 56    }
 57   
 58    /**
 59    * @return the singleton instance of the factory.
 60    */
 61  880 public synchronized static PropertiesBasedFactory getInstance()
 62    {
 63  880 if (null != FACTORY )
 64    {
 65  879 return FACTORY;
 66    }
 67  1 try
 68    {
 69  1 FACTORY = new PropertiesBasedFactory();
 70  1 return FACTORY;
 71    }
 72    catch (Throwable t)
 73    {
 74  0 LoggingUtils.logException(LOG, t, null, PropertiesBasedFactory.class);
 75  0 throw new JPInitializationException("Cannot retreive instance of PropertyBasedFactory class: " +t.getMessage());
 76    }
 77    }
 78   
 79    /**
 80    * @return the singleton instance of the <code>IPropertiesManager</code> implementation
 81    */
 82  689 public IPropertiesManager getPropertiesManager()
 83    {
 84  689 if (null != propertiesManager)
 85    {
 86  688 return propertiesManager;
 87    }
 88    else
 89    {
 90  1 try
 91    {
 92  1 propertiesManager = JPatternsPropsUtils.getPropertiesManagerImplementation();
 93  1 return propertiesManager;
 94    }
 95    catch (Throwable t)
 96    {
 97  0 LoggingUtils.logException(LOG, t, null, PropertiesBasedFactory.class);
 98  0 throw new JPInitializationException("Cannot instantiate IPropertiesManager implementation: " +t.getMessage());
 99    }
 100    }
 101    }
 102   
 103    /**
 104    * @return the instance of {@link IJPConfigurator} defined at the properties file.
 105    *
 106    * @throws com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException in the case <code>IJPConfigurator</code> instance can not be instantiated
 107    */
 108  37 public IJPConfigurator getJPConfigurator() throws JPInitializationException
 109    {
 110  37 if (null == m_jpConfigurator)
 111    {
 112  18 m_jpConfigurator = (IJPConfigurator) getPropertiesManager().getBundledObject(IJPConfigurator.class);
 113    }
 114  37 return m_jpConfigurator;
 115    }
 116   
 117    /**
 118    * @return the instance of {@link com.sourceforge.jpatterns.core.configuration.model.IJPatternsConfigBeansBuilder}
 119    * defined at the properties file.
 120    *
 121    * @throws com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException in the case <code>IJPatternsConfigBeansBuilder</code> instance can not be instantiated
 122    */
 123  191 public IJPatternsConfigBeansBuilder getJPatternsConfigBaseBeanBuilder() throws JPInitializationException
 124    {
 125  191 return (IJPatternsConfigBeansBuilder) getPropertiesManager().getBundledObject(IJPatternsConfigBeansBuilder.class);
 126    }
 127   
 128    /**
 129    * Set all the values of implementations to null.
 130    */
 131  166 public void cleanImplementations()
 132    {
 133  166 m_jpConfigurator = null;
 134    }
 135   
 136    /**
 137    * @return the new instance of the {@link com.sourceforge.jpatterns.patterns.factory.IJPFactory}
 138    */
 139  14 public IJPFactory instantiateFactory()
 140    {
 141  14 return (IJPFactory) getPropertiesManager().getBundledObject(IJPFactory.class);
 142    }
 143    }