Clover coverage report - Maven Clover report
Coverage timestamp: Mon Sep 3 2007 08:24:07 EEST
file stats: LOC: 142   Methods: 6
NCLOC: 80   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JPEngineFactory.java 60% 71% 83.3% 70.2%
coverage coverage
 1    package com.sourceforge.jpatterns.core;
 2   
 3    import com.sourceforge.jpatterns.core.configuration.IPropertiesManager;
 4    import com.sourceforge.jpatterns.core.configuration.PropertiesBasedFactory;
 5    import com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException;
 6    import com.zmicer.utils.InputArgumentUtils;
 7    import com.zmicer.utils.LoggingUtils;
 8    import org.apache.log4j.Logger;
 9   
 10    import java.io.Serializable;
 11    import java.util.HashMap;
 12    import java.util.Map;
 13   
 14    /**
 15    * Singleton-factory for the accesing the entry points of all the JPatterns operations. Currently it is only <code>IJPEngine</code>,
 16    * still there could be another entry points may occurr here in the future.
 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    public final class JPEngineFactory implements Serializable
 23    {
 24   
 25    /**
 26    * Logger instance.
 27    */
 28    final public static Logger LOG = Logger.getLogger(JPEngineFactory.class);
 29   
 30    /**
 31    * Singleton instance.
 32    */
 33    private static JPEngineFactory INSTANCE = null;
 34   
 35    /**
 36    * The <code>IJPEngine</code> to be used.
 37    * Stores the engines per the categories. Be noticed the format of this storage may be changed in the future as the set of the possible categories
 38    * could be made dynamical.
 39    */
 40    private Map<JPConstants.EngineConfigCaregory, IJPEngine> m_engines = new HashMap<JPConstants.EngineConfigCaregory, IJPEngine>();
 41   
 42    /**
 43    * Default private constructor - the part of implementation of singleton pattern
 44    * <br/>
 45    * Please be carefull in adding some initialization functionality at this constructor - this is singleton, and the call of the
 46    * constructor is done at the static initialization level.
 47    */
 48  1 private JPEngineFactory()
 49    {
 50  1 super();
 51    // todo [zmicer]: think if it is necessary here!
 52  1 init(); //This is method should be called here to avoid uninitialized using of IJPEngine.
 53    }
 54   
 55    /**
 56    * Init method.
 57    */
 58  2 public void init()
 59    {
 60  2 final IJPEngine engine1 = instantiateEngine();
 61  2 engine1.init(JPConstants.EngineConfigCaregory.CONSUMER);
 62  2 m_engines.put(JPConstants.EngineConfigCaregory.CONSUMER, engine1);
 63   
 64  2 final IJPEngine engine2 = instantiateEngine();
 65  2 engine2.init(JPConstants.EngineConfigCaregory.FRAMEWORK);
 66  2 m_engines.put(JPConstants.EngineConfigCaregory.FRAMEWORK, engine2);
 67    }
 68   
 69    /**
 70    * @return the new IJPEngine instance.
 71    */
 72  4 protected IJPEngine instantiateEngine()
 73    {
 74  4 final IPropertiesManager propsManager = PropertiesBasedFactory.getInstance().getPropertiesManager();
 75  4 if (null == propsManager)
 76    {
 77  0 throw new JPInitializationException("IPropertiesManager can not be null.");
 78    }
 79  4 final Object objectEngine = propsManager.getBundledObject(IJPEngine.class);
 80  4 if (null == objectEngine)
 81    {
 82  0 throw new JPInitializationException("Can not instantiate the IJPEngine implementation.");
 83    }
 84  4 if (!(objectEngine instanceof IJPEngine))
 85    {
 86  0 throw new JPInitializationException("Incorrect implemetation of the IJPEngine interface is set at the framework properties.");
 87    }
 88  4 return (IJPEngine) objectEngine;
 89    }
 90   
 91    /**
 92    * @return the singleton instance of the <code>JPEngineFactory</code>
 93    */
 94  23 public synchronized static JPEngineFactory getInstance()
 95    {
 96  23 if (null != INSTANCE)
 97    {
 98  22 return INSTANCE;
 99    }
 100  1 try
 101    {
 102  1 INSTANCE = new JPEngineFactory();
 103  1 return INSTANCE;
 104    }
 105    catch (Throwable ex)
 106    {
 107  0 LoggingUtils.logException(LOG, ex, null, JPEngineFactory.class);
 108  0 throw new JPInitializationException("Cannot instantiate JPEngineFactory: " +ex.getMessage());
 109    }
 110    }
 111   
 112    /**
 113    * Get the IJPEngine of the necessary category.
 114    *
 115    * @param category the category to be used, Can not be null (otherwise <code>IllegalArgumentException</code> would appear).
 116    *
 117    * @return the JPatterns engine singleton instance
 118    */
 119  11 public static IJPEngine getJPEngine(JPConstants.EngineConfigCaregory category)
 120    {
 121  11 InputArgumentUtils.checkObjects(category);
 122  11 if (null == getInstance().m_engines.get(category))
 123    {
 124  0 logAndThrow("Can not obtain the IJPEngine of the category [" + category.toString() + "]");
 125    }
 126  11 return getInstance().m_engines.get(category);
 127    }
 128   
 129    /**
 130    * Log the message and then throw it.
 131    *
 132    * @param message the not emopty message to be thrown and logged
 133    *
 134    * @throws com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException always, using message
 135    */
 136  0 protected static void logAndThrow(final String message) throws JPInitializationException
 137    {
 138  0 InputArgumentUtils.checkStrings(true, message);
 139  0 LoggingUtils.error(LOG, JPEngineFactory.class, message);
 140  0 throw new JPInitializationException(message);
 141    }
 142    }