String fileName = fileIt.next();
count++;
try{
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File(fileName));
System.out.println("Gethering metric info from from xml file: "+fileName);
// normalize text representation
if(!CSV){
//print the name of the xml file as the name of the benchmark
if(fileName.endsWith(".xml"))
bench.print(fileName.substring(0,fileName.length()-4));
else
bench.print(fileName);
}
HashMap<String, Number> aggregatedValues = new HashMap<String, Number>();
//TODO Should compute all metrics always
//only print out the one we want
Iterator<String> tempIt = allMetrics.iterator();
while(tempIt.hasNext()){
aggregatedValues.put(tempIt.next(),new Integer(0));
}
int numClasses = aggregateXMLFileMetrics(doc,aggregatedValues);
//at this point the hashmap contains aggregatedValue of all metrics
//get the metrics we might need to divide
Object myTemp = aggregatedValues.get("Total-Conditionals");
if(myTemp == null){
System.out.println("Total-Conditionals not found in aggregatedValues");
System.exit(1);
}
double total_if_ifelse = ((Integer)myTemp).doubleValue();
myTemp = aggregatedValues.get("Total Loops");
if(myTemp == null){
System.out.println("Total Loops not found in aggregatedValues");
System.exit(1);
}
double totalLoops = ((Integer)myTemp).doubleValue();
double totalConditional = total_if_ifelse+totalLoops;
myTemp = aggregatedValues.get("AST-Node-Count");
if(myTemp == null){
System.out.println("AST-Node-Count not found in aggregatedValues");
System.exit(1);
}
double astCount = ((Integer)myTemp).doubleValue();
myTemp = aggregatedValues.get("NameCount");
if(myTemp == null){
System.out.println("NameCount not found in aggregatedValues");
System.exit(1);
}
double nameCount = ((Double)myTemp).doubleValue();
myTemp = aggregatedValues.get("Expr-Count");
if(myTemp == null){
System.out.println("ExprCount not found in aggregatedValues");
System.exit(1);
}
double exprCount = ((Double)myTemp).doubleValue();
tempIt = columns.iterator();
while(tempIt.hasNext()){
String nexttempit = tempIt.next();
Object temp = aggregatedValues.get(nexttempit);
//System.out.println("NEXT TEMP IT ISSSSSSSSSSSSSSSSSSSSSS"+nexttempit);
if(temp instanceof Integer){
int val = ((Integer)temp).intValue();
if(CSV){
switch(count){
case 0://original
bench.print(fileName.substring(0,fileName.indexOf('-')));
case 1:
case 2:
case 3:
case 4:
if(nexttempit.equals("Total-Abrupt")){
//no averaging
bench.print(","+val);
}
else if(nexttempit.equals("Total-Cond-Complexity")){
if(totalConditional !=0 ){
//average by dividing total-cond-complexity for sum of if+ifelse+loops
System.out.println("conditional complexit is"+val);
System.out.println("totalConditionals are"+totalConditional);
bench.print(","+val/totalConditional);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but toalconds are 0...not good
System.out.println("Val not 0 but totalConditionals are zero!!!");
System.exit(1);
}
}
else if(nexttempit.equals("D-W-Complexity")){
if(astCount !=0 ){
//average by dividing D-W-Complexity by node count
bench.print(","+val/astCount);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but astcount is 0...not good
System.out.println("Val not 0 but astcount is zero!!!");
System.exit(1);
}
}
else if(nexttempit.equals("Expr-Complexity")){
if(exprCount !=0 ){
//average by dividing expr-complexity for exprCount
bench.print(","+val/exprCount);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but expr-count are 0...not good
System.out.println("Val not 0 but exprcount is zero!!!");
System.exit(1);
}
}
else if(nexttempit.equals("Name-Complexity")){
if(nameCount !=0 ){
//average by dividing name-complexity for nameCount
bench.print(","+val/nameCount);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but name-count are 0...not good
System.out.println("Val not 0 but name-count is zero!!!");
System.exit(1);
}
}
else{
//labeled blocks, locals, if-ifelse, ASTNodeCount
bench.print(","+val);
}
break;
default:
System.out.println("unhandled count value");
System.exit(1);
}
}
else{
//not CSV
bench.print("&"+val);
}
}
else if(temp instanceof Double){
double val = ((Double)temp).doubleValue();
if(CSV){
switch(count){
case 0://original
bench.print(fileName.substring(0,fileName.indexOf('-')));
case 1:
case 2:
case 3:
case 4:
if(nexttempit.equals("Total-Abrupt")){
//no averaging
bench.print(","+val);
}
else if(nexttempit.equals("Total-Cond-Complexity")){
if(totalConditional !=0 ){
//average by dividing total-cond-complexity for sum of if+ifelse+loops
System.out.println("conditional complexit is"+val);
System.out.println("totalConditionals are"+totalConditional);
bench.print(","+val/totalConditional);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but toalconds are 0...not good
System.out.println("Val not 0 but totalConditionals are zero!!!");
System.exit(1);
}
}
else if(nexttempit.equals("D-W-Complexity")){
if(astCount !=0 ){
//average by dividing D-W-Complexity by node count
bench.print(","+val/astCount);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but astcount is 0...not good
System.out.println("Val not 0 but astcount is zero!!!");
System.exit(1);
}
}
else if(nexttempit.equals("Expr-Complexity")){
if(exprCount !=0 ){
//average by dividing expr-complexity for exprCount
bench.print(","+val/exprCount);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but expr-count are 0...not good
System.out.println("Val not 0 but exprcount is zero!!!");
System.exit(1);
}
}
else if(nexttempit.equals("Name-Complexity")){
if(nameCount !=0 ){
//average by dividing name-complexity for nameCount
bench.print(","+val/nameCount);
}
else if (val ==0)
bench.print(","+val);
else{
//val not 0 but name-count are 0...not good
System.out.println("Val not 0 but name-count is zero!!!");
System.exit(1);
}
}
else{
//labeled blocks, locals, if-ifelse, ASTNodeCount
bench.print(","+val);
}
break;
default:
System.out.println("unhandled count value");
System.exit(1);
}
}
else
bench.print("&"+val);
}
else
throw new RuntimeException("Unknown type of object stored!!!");
if(CSV){
if(tempIt.hasNext()){
System.out.println("Only allowed one metric for CSV");
System.exit(1);
}
}
else{
if(tempIt.hasNext())
bench.print(" ");
else
bench.println("\\\\");
}
}
}catch (SAXParseException err) {
System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
System.out.println(" " + err.getMessage ());
}
catch (SAXException e) {
Exception x = e.getException ();
((x == null) ? e : x).printStackTrace ();
}
catch (Throwable t) {
t.printStackTrace ();
}
}//done with all files for this benchmark
//print closing for the table for this benchmark
if(CSV)
bench.println("");
else
printTexTableFooter(bench,"");
}//done with all benchmarks
closeWriteFile(bench,newClassName);
}
else{
Iterator<String> it = xmlFileList.iterator();
while(it.hasNext()){
String fileName = it.next();
try{
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File(fileName));
System.out.println("Gethering metric info from from xml file: "+fileName);
// normalize text representation
doc.getDocumentElement ().normalize ();