Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 126   Methods: 3
NCLOC: 77   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ExtensibleConfiguration.java 20% 15,1% 66,7% 18,4%
coverage coverage
 1    /*
 2    * Configuration.java
 3    *
 4    * Created on 19. November 2002, 22:27
 5    */
 6   
 7    package org.jconfig;
 8   
 9    import java.io.Serializable;
 10    import java.util.Iterator;
 11    import java.util.SortedMap;
 12   
 13    /**
 14    * This class is the configuration itself. The Configuration is
 15    * useful if one wants to manage multiple configurations. A single
 16    * instance of the Configuration may contain, for example, information
 17    * for one application or user.
 18    *
 19    * @author Andreas Mecky andreas.mecky@xcom.de
 20    * @author Terry Dye terry.dye@xcom.de
 21    */
 22    public class ExtensibleConfiguration extends DefaultConfiguration implements Serializable {
 23   
 24    /**
 25    * The constructor that creates a new configuration
 26    * with one empty category called "general". This
 27    * category is also the default category.
 28    *
 29    * @param configName the name of the configuration
 30    */
 31  2 public ExtensibleConfiguration(String configName) {
 32  2 super(configName);
 33    }
 34   
 35   
 36  9 public String getProperty(String key,String defaultValue,String categoryName) {
 37  9 if (key == null) {
 38  0 return defaultValue;
 39    }
 40  9 Category category = (Category)getCategory(categoryName);
 41  9 String tmp = category.getProperty(key);
 42  9 if ( tmp == null && category.getExtendsCategory() != null ) {
 43  2 return getProperty(key,defaultValue,category.getExtendsCategory());
 44    }
 45    // property not found so look in mainCategory
 46    // if it is not already the mainCategory
 47    // currently not supported
 48    /*
 49    if ( tmp == null && !isMainCat) {
 50    category = getCategory(mainCategory);
 51    tmp = category.getProperty(key);
 52    }
 53    */
 54  7 if ( tmp == null ) {
 55  0 if ( baseConfigName != null ) {
 56  0 Configuration cfg = ConfigurationManager.getConfiguration(baseConfigName);
 57  0 tmp = cfg.getProperty(key,defaultValue,categoryName);
 58    }
 59    else {
 60  0 tmp = defaultValue;
 61    }
 62    }
 63  7 return tmp;
 64    }
 65   
 66    /**
 67    * This method converts the Configuration into a String
 68    * which looks like XML.
 69    *
 70    * @return the Configuration as String in XML format
 71    */
 72  0 public String getXMLAsString() {
 73  0 StringBuffer buffer = new StringBuffer();
 74    // first we will write out the variable block
 75    // if we have some
 76  0 buffer.append("<?xml version=\"1.0\"");
 77  0 if ( getEncoding() != null ) {
 78  0 buffer.append(" encoding=\""+getEncoding()+"\"");
 79    }
 80  0 buffer.append(" ?>\n");
 81  0 buffer.append("<properties");
 82  0 if ( baseConfigName != null ) {
 83  0 buffer.append(" extends=\"");
 84  0 buffer.append(baseConfigName);
 85  0 buffer.append("\"");
 86    }
 87  0 buffer.append(">\n");
 88  0 addIncludeBlock(buffer);
 89  0 addVariableBlock(buffer);
 90    // now we are writing out all categories with
 91    // their properties
 92  0 String[] cats = getCategoryNames(false);
 93  0 for (int i = 0; i < cats.length; i++) {
 94  0 Category ec = (Category)getCategory(cats[i]);
 95  0 buffer.append(" <category name=\"");
 96  0 buffer.append(escapeForXML(ec.getCategoryName()));
 97  0 buffer.append("\"");
 98  0 if ( ec.getExtendsCategory() != null ) {
 99  0 buffer.append(" extends=\"");
 100  0 buffer.append(escapeForXML(ec.getExtendsCategory()));
 101  0 buffer.append("\"");
 102    }
 103  0 buffer.append(">\n");
 104  0 SortedMap sm = getSortedProperties(ec.getCategoryName(),false);
 105  0 if (sm != null) {
 106  0 Iterator nit = sm.keySet().iterator();
 107  0 while (nit.hasNext()) {
 108  0 String name = (String) nit.next();
 109  0 String value = (String)sm.get(name);
 110  0 buffer.append(" <");
 111  0 buffer.append(escapeForXML(name));
 112  0 buffer.append(">");
 113    // do not convert the value
 114  0 buffer.append(escapeForXML(value));
 115  0 buffer.append("</");
 116  0 buffer.append(escapeForXML(name));
 117  0 buffer.append(">\n");
 118    }
 119  0 buffer.append(" </category>\n");
 120    }
 121    }
 122  0 buffer.append("</properties>\n");
 123  0 return buffer.toString();
 124    }
 125   
 126    }