Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 138   Methods: 3
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RegisteredFactories.java 50% 41.7% 100% 48.3%
coverage coverage
 1    /**
 2    * JTRunner is free software; you can redistribute it and/or modify it under the
 3    * terms of the GNU General Public License as published by the Free Software
 4    * Foundation; either version 2, or (at your option) any later version.
 5    */
 6   
 7    package jtr.config;
 8   
 9    import jtr.assigner.IFactory;
 10   
 11    import java.util.*;
 12    import org.apache.log4j.Logger;
 13   
 14    /**
 15    * This class is in charge of registering into the JTR runtime configuration all
 16    * those JTR pluggable component factories.
 17    *
 18    * @author Francesco Russo (frusso@dev.java.net)
 19    * @version 4.0
 20    * @since 1.0
 21    */
 22    public class RegisteredFactories {
 23    /**
 24    * Registers a new factory identified by the provided key and represented by
 25    * the provided FQN.<br>
 26    * The key has to be one of the recognized values represented by the
 27    * constant <code>Strings</code> defined by this class.
 28    *
 29    * @param key
 30    * String
 31    * @param fqn
 32    * String
 33    * @throws RegistrationFailedException
 34    */
 35  12 public synchronized static void registerFactory(String key, String fqn) throws RegistrationFailedException {
 36  12 try {
 37  12 logger.debug("Trying to register a new IFactory: [" + "key=" + key + ", fqn= " + fqn + "]");
 38  12 Class clazz = Class.forName(fqn, true, Thread.currentThread().getContextClassLoader());
 39  12 logger.debug("Class " + fqn + " loaded");
 40  12 try {
 41  12 registerFactory(key, (IFactory) clazz.newInstance());
 42  12 logger.debug("Class " + fqn + " instantiated & registered!");
 43    } catch (IllegalAccessException e) {
 44  0 String msg = "Unable to initialize the specified class: " + fqn + ". Please, check security constraints";
 45  0 RegistrationFailedException rfe = new RegistrationFailedException(msg, e);
 46  0 logger.fatal(msg, rfe);
 47  0 throw rfe;
 48    } catch (InstantiationException e) {
 49  0 String msg = "Unable to initialize the specified class: " + fqn + ". Please, check security constraints";
 50  0 RegistrationFailedException rfe = new RegistrationFailedException(msg, e);
 51  0 logger.fatal(msg, rfe);
 52  0 throw rfe;
 53    }
 54    } catch (ClassNotFoundException e) {
 55  0 String msg = "Unable to find the specified class: " + fqn + ". Please, check classpath settings or the specified fqn";
 56  0 RegistrationFailedException rfe = new RegistrationFailedException(msg, e);
 57  0 logger.fatal(msg, rfe);
 58  0 throw rfe;
 59    }
 60    }
 61   
 62    /**
 63    * This method allow to register a new factory providing its instance rather
 64    * than its FQN.
 65    *
 66    * @param key
 67    * String
 68    * @param instace
 69    * IFactory
 70    */
 71  12 public synchronized static void registerFactory(String key, IFactory instace) {
 72  12 factories.put(key, instace);
 73    }
 74   
 75    /**
 76    * Returns the factory identified by the given key or <code>null</code>
 77    * should the factory be unregistered.
 78    *
 79    * @param key
 80    * String
 81    * @return IFactory
 82    */
 83  148 public synchronized static IFactory getFactory(String key) {
 84  148 if (factories.containsKey(key)) {
 85  148 return (IFactory) factories.get(key);
 86    } else {
 87  0 String msg = "Unable to locate concrete factory for service "+key+".\n"+
 88    "Please, check your factories section in your jtr.xml file.";
 89  0 throw new MissingFactoryException(msg);
 90    }
 91    }
 92   
 93    /**
 94    * Key necessary to set/obtain the factory in charge of instantiating
 95    * <code>IAssignmentPolicy</code> concrete implementations.
 96    */
 97    public static final String IASSIGNMENT_POLICY_FACTORY = "IAssignmentPolicyFactory";
 98   
 99    /**
 100    * Key necessary to set/obtain the factory in charge of instantiating
 101    * <code>IOutcomeFactory</code> concrete implementations.
 102    */
 103    public static final String IOUTCOME_FACTORY = "IOutcomeFactory";
 104   
 105    /**
 106    * Key necessary to set/obtain the factory in charge of instantiating
 107    * <code>IWsHelperFactory</code> concrete implementations.
 108    */
 109    public static final String IWSHELPER_FACTORY = "IWsHelperFactory";
 110   
 111    /**
 112    * Key necessary to set/obtain the factory in charge of instantiating
 113    * <code>ITestResultCollectorFactory</code> concrete implementations.
 114    */
 115    public static final String ITEST_RESULT_DISPLAYER = "ITestResultDisplayer";
 116   
 117    /**
 118    * Key necessary to set/obtain the factory in charge of instantiating
 119    * <code>ITestCompletionListenerFactory</code> concrete implementations.
 120    */
 121    public static final String ITEST_COMPLETION_LISTENER = "ITestCompletionListener";
 122   
 123    /**
 124    * Key necessary to set/obtain the factory in charge of instantiating
 125    * <code>ITestSnapshotFactory</code> concrete implementations.
 126    */
 127    public static final String ITEST_SNAPSHOT_FACTORY = "ITestSnapshotFactory";
 128   
 129    /**
 130    * Key necessary to set/obtain the factory in charge of instantiating
 131    * <code>ITestResultsExporterFactory</code> concrete implementations.
 132    */
 133    public static final String ITEST_RESULTS_EXPORTER = "ITestResultsExporter";
 134   
 135    private static HashMap<String,IFactory> factories = new HashMap<String,IFactory>();
 136   
 137    private static final Logger logger = Logger.getLogger(RegisteredFactories.class);
 138    }