00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030  
00031 package org.objectweb.proactive.benchmarks.timit.config;
00032 
00033 import java.util.HashMap;
00034 import java.util.Iterator;
00035 import java.util.List;
00036 
00037 import org.jdom.Document;
00038 import org.jdom.Element;
00039 import org.objectweb.proactive.benchmarks.timit.util.XMLHelper;
00040 
00046 public class ConfigReader {
00047     
00048     public static String PROJECT_PATH;
00049     
00050     static {
00051         String classesPath = ConfigReader.class.getResource(".").getPath();                
00052         ConfigReader.PROJECT_PATH = classesPath.substring(0, classesPath.indexOf("/classes"));        
00053     }
00054 
00055     private Document document;
00056 
00057     private Element eTimit;
00058 
00059     private HashMap<String, String> globalVariables; 
00060 
00061     private Serie[] series;        
00062 
00063     public ConfigReader(String filename) {
00064 
00065         
00066         this.document = XMLHelper.readFile(filename);
00067         this.eTimit = this.document.getRootElement();
00068 
00069         
00070         this.globalVariables = new HashMap<String, String>();
00071         
00072         
00073         this.globalVariables.put("PROJECT_PATH",PROJECT_PATH);
00074         
00075         Iterator it = this.eTimit.getChild("globalVariables").getChildren()
00076                 .iterator();
00077         while (it.hasNext()) {
00078             Element var = (Element) it.next();
00079             this.globalVariables.put(var.getAttributeValue("name"), var
00080                     .getAttributeValue("value"));
00081         }
00082 
00083         
00084         List serieList = this.eTimit.getChildren("serie");
00085         XMLHelper.replaceVariables(serieList, this.globalVariables);
00086         this.series = Serie.toArray(serieList);
00087     }
00088 
00093     public Serie[] getSeries() {
00094         return this.series.clone();
00095     }
00096 
00102     public HashMap<String, String> getGlobalVariables() {
00103         return this.globalVariables;
00104     }
00105 }