Coverage Report - com.sourceforge.jpatterns.core.configuration.PropertiesBasedFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertiesBasedFactory
76% 
100% 
2,571
 
 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  5
     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  5
     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  
     private PropertiesBasedFactory()
 54  
     {
 55  5
         super();
 56  5
     }
 57  
 
 58  
     /**
 59  
      * @return the singleton instance of the factory.
 60  
      */
 61  
     public synchronized static PropertiesBasedFactory getInstance()
 62  
     {
 63  4262
         if (null != FACTORY )
 64  
         {
 65  4257
             return FACTORY;
 66  
         }
 67  
             try
 68  
             {
 69  5
                 FACTORY = new PropertiesBasedFactory();
 70  5
                 return FACTORY;
 71  
             }
 72  0
             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  
     public IPropertiesManager getPropertiesManager()
 83  
     {
 84  3331
         if (null != propertiesManager)
 85  
         {
 86  3326
             return propertiesManager;
 87  
         }
 88  
         else
 89  
         {
 90  
             try
 91  
             {
 92  5
                 propertiesManager = JPatternsPropsUtils.getPropertiesManagerImplementation();
 93  5
                 return propertiesManager;
 94  
             }
 95  0
             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  
     public IJPConfigurator getJPConfigurator() throws JPInitializationException
 109  
     {
 110  169
         if (null == m_jpConfigurator)
 111  
         {
 112  82
             m_jpConfigurator = (IJPConfigurator) getPropertiesManager().getBundledObject(IJPConfigurator.class);
 113  
         }
 114  169
         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  
     public IJPatternsConfigBeansBuilder getJPatternsConfigBaseBeanBuilder() throws JPInitializationException
 124  
     {
 125  915
         return (IJPatternsConfigBeansBuilder) getPropertiesManager().getBundledObject(IJPatternsConfigBeansBuilder.class);
 126  
     }
 127  
 
 128  
     /**
 129  
      * Set all the values of implementations to null.
 130  
      */
 131  
     public void cleanImplementations()
 132  
     {
 133  814
         m_jpConfigurator = null;
 134  814
     }
 135  
 
 136  
     /**
 137  
      * @return the new instance of the {@link com.sourceforge.jpatterns.patterns.factory.IJPFactory}
 138  
      */
 139  
     public IJPFactory instantiateFactory()
 140  
     {
 141  68
         return (IJPFactory) getPropertiesManager().getBundledObject(IJPFactory.class);
 142  
     }
 143  
 }