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