public Campaign readFile(String fileName) throws Exception {
        Campaign result = new Campaign();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(fileName);
        doc.getDocumentElement().normalize();

        Element el = doc.getDocumentElement();
        if (!el.getNodeName().equals("campaign")) {
            throw new Exception(fileName + " is not a valid xml campain file");
        }

        result.name = el.getAttributeNode("name").getValue();

        NodeList nodeLst = doc.getElementsByTagName("run");
        for (int s = 0; s < nodeLst.getLength(); s++) {
            Node node = nodeLst.item(s);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                CampaignRun run = new CampaignRun();
                run.testbed = element.getAttribute("testbed");
                result.runs.add(run);
                NodeList nodeList = element.getElementsByTagName("testsuite");

                for (int t = 0; t < nodeList.getLength(); t++) {
                    TestSuiteParams params = new TestSuiteParams();

                    run.testsuites.add(params);
                    params.setDirectory(nodeList.item(t).getAttributes().getNamedItem("directory").getNodeValue());

                    NodeList childList = nodeList.item(t).getChildNodes();
                    for (int c = 0; c < childList.getLength(); c++) {
                        Node childNode = childList.item(c);
                        if (childNode.getNodeName().equals("testdata")) {
                            String selectorStr = childNode.getAttributes().getNamedItem("selector").getNodeValue();
                            String[] selectedRowsStr = selectorStr.split(",");
                            TreeSet<Integer> selectedRows = new TreeSet<>();
                            for (String selectedRowStr : selectedRowsStr) {
                                selectedRows.add(Integer.parseInt(selectedRowStr));
                            }
                            params.setDataRows(selectedRows);
                        }
                        if (childList.item(c).getNodeName().equals("loopInHours")) {
                            params.setLoopInHours(true);
                        }

                        if (childList.item(c).getNodeName().equals("count")) {
                            try {
                                params.setCount(Integer.parseInt(childList.item(c).getTextContent()));
                            } catch (NumberFormatException e) {
                                logger.error("count field in " + fileName + " file should be numeric");
                            }
                        }
                    }
                }
            }
        }
        return result;
    }
public Campaign readFile ( String fileName ) throws Exception { Campaign result = new Campaign ( ) ; DocumentBuilderFactory dbf = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder db = dbf . newDocumentBuilder ( ) ; Document doc = db . parse ( fileName ) ; doc . getDocumentElement ( ) . normalize ( ) ; Element el = doc . getDocumentElement ( ) ; if ( ! el . getNodeName ( ) . equals ( "campaign" ) ) { throw new Exception ( fileName + " is not a valid xml campain file" ) ; } result . name = el . getAttributeNode ( "name" ) . getValue ( ) ; NodeList nodeLst = doc . getElementsByTagName ( "run" ) ; for ( int s = 0 ; s < nodeLst . getLength ( ) ; s ++ ) { Node node = nodeLst . item ( s ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { Element element = ( Element ) node ; CampaignRun run = new CampaignRun ( ) ; run . testbed = element . getAttribute ( "testbed" ) ; result . runs . add ( run ) ; NodeList nodeList = element . getElementsByTagName ( "testsuite" ) ; for ( int t = 0 ; t < nodeList . getLength ( ) ; t ++ ) { TestSuiteParams params = new TestSuiteParams ( ) ; run . testsuites . add ( params ) ; params . setDirectory ( nodeList . item ( t ) . getAttributes ( ) . getNamedItem ( "directory" ) . getNodeValue ( ) ) ; NodeList childList = nodeList . item ( t ) . getChildNodes ( ) ; for ( int c = 0 ; c < childList . getLength ( ) ; c ++ ) { Node childNode = childList . item ( c ) ; if ( childNode . getNodeName ( ) . equals ( "testdata" ) ) { String selectorStr = childNode . getAttributes ( ) . getNamedItem ( "selector" ) . getNodeValue ( ) ; String [ ] selectedRowsStr = selectorStr . split ( "," ) ; TreeSet < Integer > selectedRows = new TreeSet < > ( ) ; for ( String selectedRowStr : selectedRowsStr ) { selectedRows . add ( Integer . parseInt ( selectedRowStr ) ) ; } params . setDataRows ( selectedRows ) ; } if ( childList . item ( c ) . getNodeName ( ) . equals ( "loopInHours" ) ) { params . setLoopInHours ( true ) ; } if ( childList . item ( c ) . getNodeName ( ) . equals ( "count" ) ) { try { params . setCount ( Integer . parseInt ( childList . item ( c ) . getTextContent ( ) ) ) ; } catch ( NumberFormatException e ) { logger . error ( "count field in " + fileName + " file should be numeric" ) ; } } } } } } return result ; }
Read the xml campaign file

@param fileName the xml campaign file
@return an object describing the campaign
@throws java.lang.Exception