Application.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.framework;
00002 
00003 import java.io.File;
00004 import java.io.FileNotFoundException;
00005 import java.io.FileOutputStream;
00006 import java.io.IOException;
00007 import java.io.PrintStream;
00008 
00009 import edu.rice.cs.hpc.data.experiment.Experiment;
00010 import edu.rice.cs.hpc.data.experiment.xml.PrintFileXML;
00011 import edu.rice.cs.hpc.data.util.Constants;
00012 import edu.rice.cs.hpc.data.util.Util;
00013 
00014 /******************************************************************************************
00015  * Class to manage the execution of the light version of hpcviewer
00016  * This class will require an argument for a database or XML file, then
00017  *  output the result into XML file
00018  * Otherwise, output error message.
00019  * No user interaction is needed in this light version
00020  * @author laksonoadhianto
00021  *
00022  ******************************************************************************************/
00023 public class Application {
00024 
00025     
00026     /***---------------------------------------------------------------------**
00027      * Open a XML database file, and return true if everything is OK.
00028      * @param objFile: the XML experiment file
00029      * @return
00030      ***---------------------------------------------------------------------**/
00031     private boolean openExperiment(PrintStream objPrint, File objFile) {
00032         Experiment experiment;
00033 
00034         try {
00035             experiment = new Experiment();  // prepare the experiment
00036             experiment.open(objFile, null, false);                      // parse the database
00037             this.printFlatView(objPrint, experiment);
00038             return true;
00039         } catch (Exception e) {
00040             e.printStackTrace();
00041             return false;
00042         }
00043     }
00044     
00045     
00046     /***---------------------------------------------------------------------**
00047      * 
00048      * @param experiment
00049      ***---------------------------------------------------------------------**/
00050     private void printFlatView(PrintStream objPrint, Experiment experiment) {
00051         PrintFileXML objPrintXML = new PrintFileXML();
00052         objPrintXML.print(objPrint, experiment);
00053     }
00054     
00055     
00060     public static void main(String[] args) {
00061         Application objApp = new Application();
00062         PrintStream objPrint = System.out;
00063         String sFilename;
00064         boolean std_output = true;
00065         
00066         //------------------------------------------------------------------------------------
00067         // processing the command line argument
00068         //------------------------------------------------------------------------------------
00069         if ( (args == null) || (args.length==0)) {
00070             System.out.println("Usage: hpcdata.sh [-o output_file] experiment_database");
00071             return;
00072         } else  {
00073             sFilename = args[0];
00074             
00075             for (int i=0; i<args.length; i++) {
00076                 if (args[i].equals("-o") && (i<args.length-1)) {
00077                     String sOutput = args[i+1];
00078                     File f = new File(sOutput);
00079                     if (!f.exists())
00080                         try {
00081                             f.createNewFile();
00082                         } catch (IOException e1) {
00083                             e1.printStackTrace();
00084                             return;
00085                         }
00086                     try {
00087                         FileOutputStream file = new FileOutputStream(sOutput);
00088                         try {
00089                             objPrint = new PrintStream( file );
00090                             std_output = false;
00091                             i++;
00092                         } catch (Exception e) {
00093                             System.err.println("Error: cannot create file " + sOutput + ": " +e.getMessage());
00094                             return;
00095                         }
00096 
00097                     
00098                     } catch (FileNotFoundException e2) {
00099                         // TODO Auto-generated catch block
00100                         e2.printStackTrace();
00101                     }
00102                 } else {
00103                     sFilename = args[i];
00104                 }
00105             }
00106         }
00107         
00108         //------------------------------------------------------------------------------------
00109         // open the experiment if possible
00110         //------------------------------------------------------------------------------------
00111         PrintStream print_msg;
00112         if (std_output)
00113             print_msg = System.err;
00114         else
00115             print_msg = System.out;
00116         
00117         File objFile = new File(sFilename);
00118         boolean done = false;
00119 
00120         print_msg.println("Opening database " + sFilename);
00121         
00122         if (objFile.isDirectory()) {
00123             File files[] = Util.getListOfXMLFiles(sFilename);
00124             for (File file: files) 
00125             {
00126                 // only experiment*.xml will be considered as database file
00127                 if (file.getName().startsWith(Constants.DATABASE_FILENAME)) {
00128                     done = objApp.openExperiment(objPrint, file);
00129                     if (done)
00130                         break;
00131                 }
00132             }
00133         } else {
00134             done = objApp.openExperiment(objPrint, objFile);
00135             
00136         }
00137 
00138         if (done)
00139             print_msg.println("Flat view has been generated successfully");
00140     }
00141 
00142 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1