ExperimentFileXML.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015 package edu.rice.cs.hpc.data.experiment.xml;
00016
00017
00018 import edu.rice.cs.hpc.data.experiment.*;
00019 import edu.rice.cs.hpc.data.util.Constants;
00020 import edu.rice.cs.hpc.data.util.Grep;
00021 import edu.rice.cs.hpc.data.util.IUserData;
00022
00023 import java.io.File;
00024 import java.io.FileInputStream;
00025 import java.io.IOException;
00026 import java.io.InputStream;
00027
00028
00029
00030
00032
00034
00042 public class ExperimentFileXML extends ExperimentFile
00043 {
00044
00045 private File file;
00046
00047 public File getFile()
00048 {
00049 return file;
00050 }
00051
00052 public void setFile(File file)
00053 {
00054 this.file = file;
00055 }
00056
00057
00059
00061
00086 public void parse(InputStream stream, String name,
00087 BaseExperiment experiment, boolean need_metrics, IUserData<String, String> userData)
00088 throws Exception {
00089 final Builder builder;
00090 if (need_metrics) {
00091 builder = new ExperimentBuilder2(experiment, name, userData);
00092 } else {
00093 builder = new BaseExperimentBuilder(experiment, name, userData);
00094 }
00095
00096
00097 Parser parser = new Parser(name, stream, builder);
00098 parser.parse();
00099
00100 if (builder.getParseOK() == Builder.PARSER_OK) {
00101
00102 setFile(new File(name));
00103
00104 } else
00105 throw new InvalExperimentException(
00106 "Parse error in Experiment XML at line " +
00107 builder.getParseErrorLineNumber());
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 public void parse(File file, BaseExperiment experiment, boolean need_metrics, IUserData<String, String> userData)
00121 throws Exception
00122 {
00123
00124 InputStream stream;
00125 String name = file.toString();
00126
00127
00128 String directory, xmlFilePath;
00129 if (file.isDirectory()) {
00130 directory = file.getAbsolutePath();
00131 xmlFilePath = directory + File.separatorChar + Constants.DATABASE_FILENAME;
00132 } else {
00133 directory = file.getParent();
00134 xmlFilePath = file.getAbsolutePath();
00135 }
00136
00137 File XMLfile = new File(xmlFilePath);
00138
00139 if (!XMLfile.canRead()) {
00140 throw new IOException("File does not exist or not readable: " + XMLfile.getAbsolutePath());
00141 }
00142
00143 setFile(XMLfile);
00144
00145
00146 final Builder builder;
00147 if (need_metrics)
00148 {
00149 stream = new FileInputStream(XMLfile);
00150 builder = new ExperimentBuilder2(experiment, name, userData);
00151 }
00152 else
00153 {
00154
00155
00156
00157
00158
00159
00160
00161 String callpathLoc = directory + File.separatorChar + "callpath.xml";
00162 File callpathFile = new File(callpathLoc);
00163 if (!callpathFile.exists())
00164 {
00165 Grep.grep(xmlFilePath, callpathLoc, "<M ", false);
00166 callpathFile = new File(callpathLoc);
00167 }
00168 stream = new FileInputStream(callpathFile);
00169 builder = new BaseExperimentBuilder(experiment, name, userData);
00170 }
00171
00172 Parser parser = new Parser(name, stream, builder);
00173 parser.parse();
00174
00175 if( builder.getParseOK() == Builder.PARSER_OK ) {
00176
00177 } else
00178 throw new InvalExperimentException(builder.getParseErrorLineNumber());
00179 }
00180
00181
00182 }