Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 85   Methods: 3
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AdvancedConfigParser.java 0% 0% 0% 0%
coverage
 1    package org.jconfig.parser;
 2   
 3    import org.jconfig.Configuration;
 4    import org.jconfig.DefaultConfiguration;
 5    import org.w3c.dom.Document;
 6    import org.w3c.dom.NamedNodeMap;
 7    import org.w3c.dom.Node;
 8    import org.w3c.dom.NodeList;
 9    /**
 10    *
 11    * @author Andreas Mecky andreas.mecky@xcom.de
 12    * @author Terry Dye terry.dye@xcom.de
 13    */
 14    public class AdvancedConfigParser implements ConfigurationParser {
 15   
 16  0 public AdvancedConfigParser() {
 17    }
 18   
 19    /**
 20    * Gets the variables attribute of the ConfigurationManager object
 21    *
 22    *@param doc Description of the Parameter
 23    *@return The variables value
 24    */
 25  0 private static void getVariables(Document doc,Configuration config) {
 26  0 NodeList nl = doc.getElementsByTagName("variables");
 27  0 for (int i = 0; i < nl.getLength(); i++) {
 28  0 Node n = nl.item(i);
 29  0 for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
 30    // get all vraibles
 31  0 if (child.getNodeName().equals("variable")) {
 32  0 NamedNodeMap myAtt = child.getAttributes();
 33  0 Node myNode = myAtt.getNamedItem("name");
 34  0 String name = myNode.getNodeValue();
 35  0 myNode = myAtt.getNamedItem("value");
 36  0 String value = myNode.getNodeValue();
 37  0 if (name != null && value != null) {
 38    // we store the name as ${name} so we have
 39    // it directly the way it is used
 40    //String rname = "${" + name + "}";
 41    //config.setVariable(rname, value);
 42  0 config.setVariable(name, value);
 43    }
 44    }
 45    }
 46    }
 47    }
 48   
 49    /**
 50    * Description of the Method
 51    *
 52    *@param doc Description of the Parameter
 53    */
 54  0 public Configuration parse(Document doc,String configName) {
 55  0 Configuration configuration = new DefaultConfiguration(configName);
 56  0 String currentCategory;
 57  0 getVariables(doc,configuration);
 58    // first we get all nodes where the element is category
 59  0 NodeList nl = doc.getElementsByTagName("category");
 60  0 for (int i = 0; i < nl.getLength(); i++) {
 61    // now we get every node from the list
 62  0 Node n = nl.item(i);
 63    // and get the name attribute for this category
 64  0 NamedNodeMap curAtt = n.getAttributes();
 65  0 Node curNode = curAtt.getNamedItem("name");
 66  0 currentCategory = curNode.getNodeValue();
 67  0 configuration.setCategory(currentCategory);
 68    // now we process all children for this category
 69  0 for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
 70    // we take the tag name as property name
 71  0 if ( child.getNodeType() == 1 && child.getFirstChild() != null ) {
 72  0 String name = child.getNodeName();
 73  0 String value = child.getFirstChild().getNodeValue();
 74  0 if (name != null && value != null) {
 75    // the key is always category/name
 76    // e.g. general/congig_file
 77  0 configuration.setProperty(name,value,currentCategory);
 78    }
 79    }
 80    }
 81    }
 82  0 return configuration;
 83    }
 84   
 85    }