Clover coverage report - Maven Clover report
Coverage timestamp: Mon Sep 3 2007 08:24:07 EEST
file stats: LOC: 171   Methods: 7
NCLOC: 122   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JPatternsPropsUtils.java 80% 92.7% 100% 89.7%
coverage coverage
 1    package com.sourceforge.jpatterns.utils;
 2   
 3    import com.sourceforge.jpatterns.core.JPConstants;
 4    import com.sourceforge.jpatterns.core.configuration.IPropertiesManager;
 5    import com.sourceforge.jpatterns.core.configuration.PropertiesManagerImpl;
 6    import com.zmicer.utils.LoggingUtils;
 7    import com.zmicer.utils.ReflexionUtils;
 8    import com.zmicer.utils.ResourceUtils;
 9    import com.zmicer.utils.ZmicerUtilsConstants;
 10    import org.apache.commons.lang.StringUtils;
 11    import org.apache.log4j.Logger;
 12   
 13    import java.util.ResourceBundle;
 14   
 15    /**
 16    * This class the common JPatterns based methods for working with property files.
 17    *
 18    * $Author:: zmicer $<br/>
 19    * $Rev:: 67 $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
 20    * @forversion 1.0.1
 21    */
 22    public class JPatternsPropsUtils
 23    {
 24    /**
 25    * Logger instance.
 26    */
 27    final public static Logger LOG = Logger.getLogger(ZmicerUtilsConstants.LoggingCategory.PROPERTIES_RELATED.toString());
 28   
 29    /**
 30    * The default bundle to be used.
 31    */
 32    public static ResourceBundle defaultBundle;
 33   
 34    /**
 35    * The custom bundle to be used.
 36    */
 37    public static ResourceBundle customBundle;
 38   
 39    /**
 40    * @return the name of the resource bundle file should be used for the default JPatterns properties configuration.
 41    * $Rev:: 67 $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
 42    */
 43  174 public static String getDefaultBundleName()
 44    {
 45  174 final String jvmDefautlt = System.getProperty(JPConstants.PropertiesConfigFilesConstants.DEFAULT_PROPERTIES_FILE_NAME_JVM_PARAM);
 46  174 if (null != jvmDefautlt && !"".equals(jvmDefautlt.trim()))
 47    {
 48  90 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "Please be noticed the JVM provided value for the default props is used [" +
 49    jvmDefautlt + "]");
 50  90 return jvmDefautlt;
 51    }
 52  84 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "The default (not JVM based) value is used [" +
 53    JPConstants.PropertiesConfigFilesConstants.DEFAULT_PROPERTIES_FILE_NAME + "]");
 54  84 return JPConstants.PropertiesConfigFilesConstants.DEFAULT_PROPERTIES_BASE_NAME;
 55    }
 56   
 57    /**
 58    * @return the name of the resource bundle file should be used for the custom JPatterns properties configuration.
 59    * $Rev:: 67 $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
 60    */
 61  174 public static String getCustomBundleName()
 62    {
 63  174 final String jvmCustom = System.getProperty(JPConstants.PropertiesConfigFilesConstants.CUSTOM_PROPERTIES_FILE_NAME_JVM_PARAM);
 64  174 if (null != jvmCustom && !"".equals(jvmCustom.trim()))
 65    {
 66  72 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "Please be noticed the JVM param value is used for custom props [" +
 67    jvmCustom + "]");
 68  72 return jvmCustom;
 69    }
 70  102 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "The default (not JVM based value is used for custom props file name [" +
 71    JPConstants.PropertiesConfigFilesConstants.CUSTOM_PROPERTIES_FILE_NAME + "]");
 72  102 return JPConstants.PropertiesConfigFilesConstants.CUSTOM_PROPERTIES_BASE_NAME;
 73    }
 74   
 75    /**
 76    * Return the implementation of the IPropertiesManager. For this we would obtain default/custom bundles. Pleaes be noticed they would
 77    * be stored to {@link m_defaultBundle} and {@link m_customBundle} to be able to use them later by the implementation of the
 78    * PropertiesManagerImpl without additional retrieving of the bundles.
 79    *
 80    * @return the implementation of the IPropertiesManager using the default/custom properties files. First of all the custom would be
 81    * checked, then the default one, and then if the implementation is not specified - default implementation would be obtained
 82    * (<code>PropertiesManagerImpl class</code>)
 83    * $Rev:: 67 $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
 84    */
 85  6 public static IPropertiesManager getPropertiesManagerImplementation()
 86    {
 87  6 final String defaultProps = JPatternsPropsUtils.getDefaultBundleName();
 88  6 final String customProps = JPatternsPropsUtils.getCustomBundleName();
 89  6 if (null == defaultProps)
 90    {
 91  0 throw new IllegalStateException("The name of default configuration can not be null.");
 92    }
 93  6 defaultBundle = ResourceUtils.getResourceBundle(defaultProps);
 94  6 customBundle = ResourceUtils.getResourceBundle(customProps);
 95  6 String className = null;
 96  6 if (null != customBundle)
 97    {
 98  3 try
 99    {
 100  3 className = customBundle.getString(ReflexionUtils.getBaseName(IPropertiesManager.class));
 101    }
 102    catch (Exception ex)
 103    {
 104    // just nothing
 105    }
 106  3 if (null != className)
 107    {
 108  2 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "The implementation of IPropertiesManager was found at the custom " +
 109    "properties file [" + customProps + "], implementation is [" + className + "]");
 110    }
 111    }
 112  6 if (StringUtils.isBlank(className) && null != defaultBundle)
 113    {
 114  4 try
 115    {
 116  4 className = defaultBundle.getString(ReflexionUtils.getBaseName(IPropertiesManager.class));
 117    }
 118    catch (Exception ex)
 119    {
 120    // just nothing
 121    }
 122  4 if (null != className)
 123    {
 124  3 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "The implementation of IPropertiesManager was found at the default " +
 125    "properties file [" + defaultProps + "]," + "implementation is [" + className + "]");
 126    }
 127    }
 128  6 if (StringUtils.isBlank(className))
 129    {
 130  1 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "The default PropertiesManagerImpl implementation of the " +
 131    "IPropertiesManager is used [" + ReflexionUtils.getBaseName(PropertiesManagerImpl.class) + "]");
 132  1 return new PropertiesManagerImpl();
 133    }
 134    else
 135    {
 136  5 final Object object = ReflexionUtils.reflectObject(className, true);
 137  4 if (null == object || !(object instanceof IPropertiesManager))
 138    {
 139  0 LoggingUtils.debug(LOG, JPatternsPropsUtils.class, "Can not instantiate the implementation of the IPropertiesManager " +
 140    "using class name [" + className + "]. The returned object type [" +
 141  0 ((null != object) ? object.getClass().getName() : "null was returned") + "]");
 142  0 return null;
 143    }
 144    else
 145    {
 146  4 return (IPropertiesManager) object;
 147    }
 148    }
 149    }
 150   
 151   
 152  7 public static ResourceBundle getDefaultBundle()
 153    {
 154  7 return defaultBundle;
 155    }
 156   
 157  2 public static void setDefaultBundle(ResourceBundle defaultBundle)
 158    {
 159  2 JPatternsPropsUtils.defaultBundle = defaultBundle;
 160    }
 161   
 162  2 public static ResourceBundle getCustomBundle()
 163    {
 164  2 return customBundle;
 165    }
 166   
 167  2 public static void setCustomBundle(ResourceBundle customBundle)
 168    {
 169  2 JPatternsPropsUtils.customBundle = customBundle;
 170    }
 171    }