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.ArrayList;
00034 import java.util.Arrays;
00035 import java.util.Iterator;
00036 import java.util.List;
00037 import java.util.regex.Matcher;
00038 import java.util.regex.Pattern;
00039
00040 import org.jdom.Attribute;
00041 import org.jdom.Element;
00042 import org.objectweb.proactive.benchmarks.timit.util.XMLHelper;
00043
00044 public class Serie extends Tag {
00045
00046 private ConfigChart[] charts;
00047
00048 private Benchmark[] benchmarks;
00049
00050 public Serie(Element eSerie) {
00051 super(eSerie);
00052
00053
00054 if( eSerie.getChild("charts") != null ) {
00055 List chartList = eSerie.getChild("charts").getChildren();
00056 this.charts = new ConfigChart[chartList.size()];
00057 for (int i = 0; i < this.charts.length; i++) {
00058 this.charts[i] = new ConfigChart((Element) chartList.get(i));
00059 }
00060 }
00061
00062
00063 List benchList = eSerie.getChild("benchmarks").getChildren();
00064 this.benchmarks = Benchmark.toArray(benchList);
00065
00066 }
00067
00068 public String get(String name) {
00069 name = name.toLowerCase();
00070 String value = super.get(name);
00071
00072 if (value != null) {
00073 return value;
00074 }
00075
00076 if (name.equals("errorfile")) {
00077 return "error.log";
00078 }
00079
00080 throw new RuntimeException("Variable benchmark.'" + name
00081 + "' missing in configuration file");
00082 }
00083
00084 public Benchmark[] getBenchmarks() {
00085 return this.benchmarks.clone();
00086 }
00087
00088 public ConfigChart[] getCharts() {
00089 if( this.charts == null ) return null;
00090 return this.charts.clone();
00091 }
00092
00093 public String toString() {
00094 return super.toString() + Arrays.toString(this.charts) + " - "
00095 + Arrays.toString(this.benchmarks) + "\n";
00096 }
00097
00098 public static Serie[] oldtoArray(List serieList) {
00099 int quantity = serieList.size();
00100 Serie[] result = new Serie[quantity];
00101
00102 for (int i = 0; i < quantity; i++) {
00103 Element eSerie = (Element) serieList.get(i);
00104 result[i] = new Serie(eSerie);
00105 }
00106
00107 return result;
00108 }
00109 public static Serie[] toArray(List serieList) {
00110
00111 ArrayList<String> seqList;
00112 int quantity = serieList.size();
00113 ArrayList<Serie> result = new ArrayList<Serie>();
00114
00115 Pattern p = Pattern.compile("[^\\x23\\x7B\\x7D]*\\x23\\x7B" +
00116 "([^\\x7D]*)" +
00117 "\\x7D[^\\x7D\\x23\\x7B]*");
00118
00119 for (int i = 0; i < quantity; i++) {
00120 Element eSerie = (Element) serieList.get(i);
00121 seqList = new ArrayList<String>();
00122
00123
00124 Iterator itAttr = eSerie.getAttributes().iterator();
00125 while (itAttr.hasNext()) {
00126 Attribute attr = (Attribute) itAttr.next();
00127 Matcher m = p.matcher(attr.getValue());
00128 while (m.find()) {
00129 String sequence = m.group(1);
00130 if (!seqList.contains(sequence)) {
00131 seqList.add(sequence);
00132 }
00133 }
00134 }
00135
00136
00137 if (seqList.size() > 0) {
00138 expand(eSerie, seqList, 0, result);
00139 } else {
00140 result.add(new Serie(eSerie));
00141 }
00142 }
00143
00144 return result.toArray(new Serie[1]);
00145 }
00146
00147 private static void expand(Element eSerie, ArrayList<String> seqList,
00148 int index, ArrayList<Serie> out) {
00149
00150 String seq = seqList.get(index);
00151 String[] values = seq.split(",");
00152
00153 for (String value : values) {
00154 Element eSerieClone = (Element) eSerie.clone();
00155 XMLHelper.replaceAll(
00156 eSerieClone, "\\x23\\x7B" + seq + "\\x7D",
00157 value);
00158 Iterator itDesc = eSerieClone.getDescendants();
00159 while( itDesc.hasNext() ) {
00160 Object eDesc = itDesc.next();
00161 if( eDesc instanceof Element ) {
00162 XMLHelper.replaceAll(
00163 (Element) eDesc, "\\x23\\x7B" + seq + "\\x7D",
00164 value);
00165 }
00166 }
00167
00168 if (index + 1 < seqList.size()) {
00169 expand(eSerieClone, seqList, index + 1, out);
00170 } else {
00171 out.add(new Serie(eSerieClone));
00172 }
00173 }
00174 }
00175 }