toxgene.ToXgene Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ToxGene Show documentation
Show all versions of ToxGene Show documentation
Modified ToXGene for the iBench project.
The newest version!
/*
* ToXgene.java implements the front-end to the Tox Generator
*
* @author Denilson Barbosa
*
* @version 0.1
*/
package toxgene;
import java.util.Vector;
import java.text.DecimalFormat;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.PrintStream;
import toxgene.core.Engine;
import toxgene.core.ToXgeneErrorException;
import toxgene.interfaces.ToXgeneDocumentCollection;
import toxgene.interfaces.ToXgeneSession;
import toxgene.util.ToXgeneReporterImpl;
public class ToXgene{
private static Engine tgEngine;
private static boolean verbose = false;
public final static String version = "2.3";
private static boolean addNewLine = false;
private static boolean showWarnings = true;
private static boolean showTime = false;
/**
* these concern the use of an persistent object manager
*/
private static boolean usePOM = false;
private static long totalMemory;
private static float memFracBuffer;
private static int numBuffers;
private static int bufferSize;
private static String bufferPath;
private static String inputPath;
private static String outputPath = "./";
private static String jarPath = null;
private static boolean useJar = false;
private static long initialSeed;
private static ToXgeneReporterImpl tgReporter;
/**
* program entry point
*/
public static void main (String argv []){
long t_start = 0, t_parse = 0, t_lists = 0, t_done = 0;
int argc = argv.length;
boolean generate = true;
String cpr = "ToXgene "+version+" - "+
"(c) 2001 by University of Toronto and IBM Corporation\n\n";
String msg = "Usage: ToXgene \n"+
"where possible options include ([default value]):\n"+
" -l load data files from toxgene.jar instead of using system classloader\n" +
" -j \tSpecify path of toxgene.jar to load from\n" +
" -c\t\tCheck template only; do not generate files [false]\n"+
" -h\t\tPrint this message\n"+
" -v\t\tVerbose mode [false]\n"+
" -w\t\tOmit warning messages [false]\n"+
" -n\t\tAdd a new line after each element close tag [false]\n"+
" -t\t\tShow elapsed time [false]\n"+
" -s \tSpecify an initial master random seed\n"+
" -i \tSpecify a path where the input XML files for populating\n"+
" \t\tthe tox-lists are located [\".\"]\n"+
" -d \tSpecify a path where ToXgene should write the documents\n"+
" \tgenerated in the current session [\".\"]\n"+
" -o [p[f][[s]]] Use a persistent object manager [false]:\n"+
"\t\t \"p\" is the path where to store temporary files\n"+
"\t\t \"f\" is the fraction of the memory used for buffering\n"+
"\t\t \"s\" is the size (in kilobytes) of the memory buffers\n"+
"\t\t the default values are: p=\".\", f=0.5 and s=8KB";
if (argc == 0){
System.err.println(cpr+msg);
System.exit (1);
}
char option[];
int noptions = 0;
for (int i=0; i totalMemory){
error("invalid \"-o\" option: specified buffer size ("
+bufferSize+") is higher than available memory ("
+totalMemory+")!");
}
if (memFracBuffer <= 0 || memFracBuffer > 1){
error("invalid \"-o\" option: \"f\" must be between 0 and 1.");
}
if (bufferSize <= 0){
error("invalid \"-o\" option: \"s\" must be greater than 0.");
}
break;
}
default:{
System.out.println("Ignoring unrecognized option: "+option[1]);
break;
}
}
}
}
t_start = System.currentTimeMillis();
if (noptions < argc){
String template = argv[argc-1];
System.out.print(cpr);
try{
tgEngine = new Engine();
tgEngine.setJarPath(jarPath);
tgEngine.setUseJarLoading(true);
tgReporter = new ToXgeneReporterImpl(verbose, showWarnings);
ToXgeneSession session = new ToXgeneSession();
session.reporter = tgReporter;
session.initialSeed = initialSeed;
session.addNewLines = addNewLine;
session.inputPath = inputPath;
session.usePOM = usePOM;
session.pomBufferPath = bufferPath;
session.pomMemFracBuffer = memFracBuffer;
session.pomBufferSize = bufferSize;
tgEngine.startSession(session);
tgReporter.progress("***** Parsing template: ");
tgEngine.parseTemplate(new FileInputStream(template));
tgReporter.progress("Done !\n");
t_parse = System.currentTimeMillis();
if (generate){
tgEngine.generateLists();
t_lists = System.currentTimeMillis();
generateCollections();
t_done = System.currentTimeMillis();
}
}
catch (ToXgeneErrorException e1){
error(e1.getMessage());
}
catch (FileNotFoundException e){
tgEngine.endSession();
error("cannot open template file \""+template+"\"");
}
catch (Exception e){
e.printStackTrace();
}
tgEngine.endSession();
int nWarnings = tgReporter.warnings();
if ( nWarnings > 0){
System.out.println("There were "+nWarnings+" warning(s)");
}
tgReporter.printAllWarnings();
/**
* done everything.
*/
if (showTime){
System.out.println("Total elapsed time: "+(t_done-t_start)+"ms.");
System.out.println("Parsing time: "+(t_parse-t_start)+"ms.");
System.out.println("List processing time: "+(t_lists-t_parse)+"ms.");
}
System.exit(0);
}
else{
System.err.println(cpr+msg);
System.exit (1);
}
System.exit(1);
}
private static void generateCollections(){
Vector collections = tgEngine.getToXgeneDocumentCollections();
int cols = collections.size();
if (cols == 0){
tgReporter.warning("no document genes found");
}
else{
tgReporter.progress("\n ***** Generating XML documents *****\n");
for (int i=0; i1){
//this means we have a Collection and not a single file.
int start = tgColl.getStartingNumber();
int copies = tgColl.getSize();
int step = (copies > 19) ? copies/19 : 19;
String pattern="0;0";
if (tgColl.pad()){
pattern=";0";
int magnitude=copies;
while (magnitude > 0){
pattern+="0";
magnitude = magnitude/10;
}
}
DecimalFormat nf = new DecimalFormat(pattern);
tgReporter.progress("Generating collection: "+tgColl.getName()
+" ");
String current;
if ((step*19) < copies){
step++;
}
int count = 0, sum=0;
for (int j=start; j= step){
sum+=5;
tgReporter.progress("\b\b\b"+sum+"%");
count = 0;
}
}
tgReporter.progress("\b\b\bDone!\n");
}
else{
tgReporter.progress("Generating document: "
+tgColl.getName()+" ");
String current = outputPath+tgColl.getName()+".xml";
try{
PrintStream outStream =
new PrintStream(new FileOutputStream(current));
tgEngine.materialize(tgColl, outStream);
}
catch(Exception e){
tgEngine.endSession();
throw new ToXgeneErrorException("Couldn't create "+ current);
}
tgReporter.progress("Done!\n");
}
}
}
}
public static void error(String msg){
tgReporter.printAllWarnings();
System.out.println("\n***** ERROR: "+msg);
System.exit(1);
}
}