Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 87   Methods: 3
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NestedConfigParser.java 70% 94,1% 100% 86%
coverage coverage
 1    package org.jconfig.parser;
 2   
 3    import org.jconfig.Configuration;
 4    import org.jconfig.NestedCategory;
 5    import org.jconfig.NestedConfiguration;
 6    import org.w3c.dom.Document;
 7    import org.w3c.dom.Element;
 8    import org.w3c.dom.NamedNodeMap;
 9    import org.w3c.dom.Node;
 10   
 11    /**
 12    *
 13    * @author Andreas Mecky andreas.mecky@xcom.de
 14    * @author Terry Dye terry.dye@xcom.de
 15    */
 16    public class NestedConfigParser extends AbstractConfigParser {
 17   
 18    private boolean doTrimValue = false;
 19   
 20  27 public NestedConfigParser() {
 21  27 String trimStr = System.getProperty("jconfig.trimValue");
 22  27 if (trimStr != null && trimStr.length() > 0) {
 23  0 if (trimStr.equalsIgnoreCase("yes")
 24    || trimStr.equalsIgnoreCase("true")) {
 25  0 doTrimValue = true;
 26    }
 27    }
 28    }
 29   
 30    /**
 31    * Description of the Method
 32    *
 33    * @param doc
 34    * Description of the Parameter
 35    */
 36  26 public Configuration parse(Document doc, String configName) {
 37  26 Configuration configuration = new NestedConfiguration(configName);
 38  26 String currentCategory;
 39  26 getVariables(doc, configuration);
 40  26 getIncludeProperties(doc, configuration);
 41  26 getBaseConfigName(doc, configuration);
 42  26 Element root = doc.getDocumentElement();
 43    // first we get all nodes where the element is category
 44  26 for (Node child = root.getFirstChild(); child != null; child = child
 45    .getNextSibling()) {
 46  338 if (child.getNodeName().equals("category")) {
 47  122 NamedNodeMap curAtt = child.getAttributes();
 48  122 Node curNode = curAtt.getNamedItem("name");
 49  122 currentCategory = curNode.getNodeValue();
 50  122 NestedCategory category = new NestedCategory(currentCategory);
 51  122 getCategory(child, category, configName);
 52  122 configuration.setCategory(category);
 53    }
 54    }
 55  26 return configuration;
 56    }
 57   
 58  159 private void getCategory(Node n, NestedCategory cat, String configName) {
 59    // now we process all children for this category
 60  159 for (Node child = n.getFirstChild(); child != null; child = child
 61    .getNextSibling()) {
 62    // we take the tag name as property name
 63  795 if (child.getNodeType() == 1) {
 64  318 String name = child.getNodeName();
 65  318 if (name.equals("category")) {
 66  37 NamedNodeMap curAtt = child.getAttributes();
 67  37 Node nNode = curAtt.getNamedItem("name");
 68  37 String categoryName = nNode.getNodeValue();
 69  37 NestedCategory category = new NestedCategory(categoryName);
 70  37 category.setConfigurationName(configName);
 71  37 cat.addCategory(category);
 72  37 getCategory(child, category, configName);
 73    } else {
 74  281 if (child.getFirstChild() != null) {
 75  281 String value = child.getFirstChild().getNodeValue();
 76  281 if (name != null && value != null) {
 77  281 cat.setProperty(name, (this.doTrimValue) ? value
 78    .trim() : value);
 79    }
 80    }
 81    }
 82   
 83    }
 84    }
 85    }
 86   
 87    }