Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 167   Methods: 13
NCLOC: 95   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConfigHandler.java 0% 0% 0% 0%
coverage
 1    /*
 2    * ConfigHandler.java
 3    *
 4    * Created on 7. August 2002, 10:08
 5    */
 6    package org.jconfig.jmx;
 7   
 8    import java.io.File;
 9    import java.net.URL;
 10   
 11    import org.jconfig.Configuration;
 12    import org.jconfig.ConfigurationManager;
 13    import org.jconfig.handler.XMLFileHandler;
 14    /**
 15    *@author mecky
 16    *@created 7. August 2002
 17    */
 18    public class ConfigHandler implements ConfigHandlerMBean {
 19   
 20    private String resourceName;
 21    private String configName;
 22   
 23    /**
 24    * Constructor for the ConfigHandler object
 25    */
 26  0 public ConfigHandler() {
 27    }
 28   
 29   
 30    /**
 31    * Gets the configurationName attribute of the ConfigHandler object
 32    *
 33    *@return The configurationName value
 34    */
 35  0 public String getConfigurationName() {
 36  0 return configName;
 37    }
 38   
 39   
 40    /**
 41    * Gets the fileName attribute of the ConfigHandler object
 42    *
 43    *@return The fileName value
 44    */
 45  0 public String getResourceName() {
 46  0 return resourceName;
 47    }
 48   
 49    /**
 50    * Sets the configurationName attribute of the ConfigHandler object
 51    *
 52    *@param configName The new configurationName value
 53    */
 54  0 public void setConfigurationName(String configName) {
 55  0 if ( resourceName != null ) {
 56  0 load(resourceName,configName);
 57    }
 58  0 this.configName = configName;
 59    }
 60   
 61   
 62    /**
 63    * Sets the fileName attribute of the ConfigHandler object
 64    *
 65    *@param fileName The new fileName value
 66    */
 67  0 public void setResourceName(String resourceName) {
 68  0 if ( configName != null ) {
 69  0 load(resourceName,configName);
 70    }
 71  0 this.resourceName = resourceName;
 72    }
 73   
 74    /**
 75    * Description of the Method
 76    *
 77    *@return Description of the Return Value
 78    */
 79  0 public String toString() {
 80  0 StringBuffer buffer = new StringBuffer();
 81  0 buffer.append("ConfigHandler:\n");
 82  0 buffer.append("Resourcename:");
 83  0 buffer.append(resourceName);
 84  0 buffer.append("\nConfigname:");
 85  0 buffer.append(configName);
 86  0 return buffer.toString();
 87    }
 88   
 89   
 90    /**
 91    * Description of the Method
 92    */
 93  0 public void forceReload() {
 94  0 load(resourceName,configName);
 95    }
 96   
 97    /**
 98    * Gets the name attribute of the ConfigHandler object
 99    *
 100    *@return The name value
 101    */
 102  0 public String getName() {
 103  0 return "jConfig:" + configName;
 104    }
 105   
 106    // Changed so that it can also read from URLs.
 107    // Thanx to Guy Rouillier <guyr@masergy.com> for the pathc
 108  0 private void load(String resourceName,String configName) {
 109  0 try {
 110  0 if ( configName == null ) {
 111  0 configName = "default";
 112    }
 113  0 ConfigurationManager myConfig = ConfigurationManager.getInstance();
 114  0 URL url = null;
 115    // If the string has a protocol on it, we'll assume it's an absolute
 116    // URL. Otherwise, we'll assume it's a resource known to the
 117    // classloader.
 118  0 if (resourceName.indexOf("://") >= 0)
 119    {
 120  0 url = new URL(resourceName);
 121    } // end if
 122    else
 123    {
 124  0 ClassLoader cl = Thread.currentThread().getContextClassLoader();
 125  0 url = cl.getResource(resourceName);
 126    } // end else
 127   
 128  0 if (url != null) {
 129  0 File file = new File(url.getFile());
 130  0 XMLFileHandler handler = new XMLFileHandler(file.getAbsolutePath());
 131  0 myConfig.load(handler, configName);
 132    }
 133    }
 134    catch (Exception e) {
 135  0 e.printStackTrace();
 136    }
 137    }
 138   
 139  0 public String showConfiguration() {
 140  0 Configuration myConfig = ConfigurationManager.getConfiguration(configName);
 141  0 if ( myConfig != null ) {
 142  0 StringBuffer buffer = new StringBuffer();
 143  0 buffer.append("<pre>");
 144  0 buffer.append(myConfig.toString());
 145  0 buffer.append("</pre>");
 146  0 return buffer.toString();
 147    }
 148    else {
 149  0 return null;
 150    }
 151    }
 152   
 153  0 public void removeProperty(String name, String category) {
 154  0 Configuration config = ConfigurationManager.getConfiguration(configName);
 155  0 config.removeProperty(name, category);
 156    }
 157   
 158  0 public void saveConfiguration() throws Exception {
 159  0 ConfigurationManager.getInstance().save(configName);
 160    }
 161   
 162  0 public void setProperty(String name, String value, String category) {
 163  0 Configuration config = ConfigurationManager.getConfiguration(configName);
 164  0 config.setProperty(name, value, category);
 165    }
 166   
 167    }