Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 80   Methods: 2
NCLOC: 43   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CDataConfigParser.java 90% 100% 100% 97,1%
coverage coverage
 1    package org.jconfig.parser;
 2   
 3    import org.jconfig.Category;
 4    import org.jconfig.Configuration;
 5    import org.jconfig.DefaultCategory;
 6    import org.jconfig.ExtensibleConfiguration;
 7    import org.w3c.dom.Document;
 8    import org.w3c.dom.NamedNodeMap;
 9    import org.w3c.dom.Node;
 10    import org.w3c.dom.NodeList;
 11    /**
 12    * The CDataConfigParser supports the following XML structure:<br>
 13    * <category name="hello"><br>
 14    * <mytag>my value</mytag><br>
 15    * <nextone>more goes here</nextone><br>
 16    * <server_port>8080</server_port><br>
 17    * </category><br>
 18    * It also supports "inheritance" that means one category can
 19    * extend another category and will also have all properties.
 20    * Properties will be overwritten.<br>
 21    * Syntax:<br>
 22    * <category name="first"><br>
 23    * <hello>world/<hello><br>
 24    * </category><br>
 25    * <category name="second" extends="first"><br>
 26    * </category><br>
 27    * This means that category "second" now also has the property called "hello"
 28    *
 29    * @author Andreas Mecky andreas.mecky@xcom.de
 30    * @author Terry Dye terry.dye@xcom.de
 31    */
 32    public class CDataConfigParser extends AbstractConfigParser {
 33   
 34  2 public CDataConfigParser() {
 35    }
 36   
 37    /**
 38    * Description of the Method
 39    *
 40    *@param doc Description of the Parameter
 41    */
 42  1 public Configuration parse(Document doc,String configName) {
 43  1 ExtensibleConfiguration configuration = new ExtensibleConfiguration(configName);
 44  1 String currentCategory;
 45  1 getVariables(doc,configuration);
 46  1 getIncludeProperties(doc, configuration);
 47  1 getBaseConfigName(doc, configuration);
 48    // first we get all nodes where the element is category
 49  1 NodeList nl = doc.getElementsByTagName("category");
 50  1 for (int i = 0; i < nl.getLength(); i++) {
 51    // now we get every node from the list
 52  2 Node n = nl.item(i);
 53    // and get the name attribute for this category
 54  2 NamedNodeMap curAtt = n.getAttributes();
 55  2 Node curNode = curAtt.getNamedItem("name");
 56  2 currentCategory = curNode.getNodeValue();
 57  2 Category ec = new DefaultCategory(currentCategory);
 58  2 configuration.setCategory(ec);
 59  2 curNode = curAtt.getNamedItem("extends");
 60  2 if ( curNode != null ) {
 61  1 ec.setExtendsCategory(curNode.getNodeValue());
 62    }
 63    // now we process all children for this category
 64  2 for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
 65    // we take the tag name as property name
 66  12 if ( child.getNodeType() == 1 && child.getFirstChild() != null ) {
 67  5 String name = child.getNodeName();
 68  5 String value = child.getFirstChild().getNodeValue();
 69  5 if (name != null && value != null) {
 70    // the key is always category/name
 71    // e.g. general/congig_file
 72  5 configuration.setProperty(name,value,currentCategory);
 73    }
 74    }
 75    }
 76    }
 77  1 return configuration;
 78    }
 79   
 80    }