
toxgene.core.genes.trees.ToxCollection Maven / Gradle / Ivy
/**
* Provides an interface to an actual XML document to be generated.
*
* @author Denilson Barbosa
* @version 0.1
*/
package toxgene.core.genes.trees;
import toxgene.core.ToXgeneErrorException;
import toxgene.core.genes.lists.ToxList;
import toxgene.interfaces.ToXgeneDocumentCollection;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.Vector;
public class ToxCollection implements TreeGene, ToXgeneDocumentCollection{
private PrintStream outStream;
private String name, doctype, tgVersion;
private int copies, start;
private boolean hasDTD = false;
private int currentDocument;
/**
* Vector containing references to all lists that are used in the
* generation of this document/collection. Used for garbage collection
* purposes.
*/
private Vector uses;
/**
* Root element of the file. The data generation starts with this element
*/
private ToxElement root;
/**
* Determines whether to pad leading 0 to the names of the files in
* collections.
*/
private boolean pad;
/*************************************************************************
*
* THESE CONSTRUCTORS ARE FOR "SINGLE DOCUMENT" COLLECTIONS
*
************************************************************************/
public ToxCollection(String name, ToxElement root, String version){
this.name = name;
this.root = root;
tgVersion = version;
copies = 1; start=1; pad=false;
}
public ToxCollection(String name, String doctype, ToxElement root,
String version){
this.name = name;
this.root = root;
this.doctype = doctype;
hasDTD = true;
tgVersion = version;
copies = 1; start=1; pad=false;
}
/*************************************************************************
*
* THESE CONSTRUCTORS ARE FOR "MULTI DOCUMENT" COLLECTIONS
*
************************************************************************/
public ToxCollection (String name, int copies, int start, ToxElement root,
boolean pad, String version){
currentDocument = 0;
this.copies = copies;
this.start = start;
this.name = name;
this.root = root;
this.pad = pad;
tgVersion = version;
}
public ToxCollection (String name, int copies, int start, String doctype,
ToxElement root, boolean pad, String version){
currentDocument = 0;
this.copies = copies;
this.start = start;
this.name = name;
this.root = root;
this.doctype = doctype;
this.pad = pad;
hasDTD = true;
tgVersion = version;
}
public void references(Vector refs){
uses = refs;
for (int i=0; i");
outStream.println("");
if (hasDTD){
//if we find the given file here we stick it into the output,
//otherwise we write just a reference to an external DTD
try{
BufferedReader in = new BufferedReader(new FileReader(doctype));
outStream.println("");
}
catch(FileNotFoundException e){
outStream.println("");
}
catch(IOException e1){
throw new ToXgeneErrorException("IO exception while attempting "
+"to read "+doctype);
}
}
outStream.println();
//Starts the generation process.
root.generate(outStream);
if (currentDocument == copies)
destroy();
}
/**
* For compatibility reasons only. This method will never be called.
*/
public void generate(){
}
/**
* For compatibility reasons only. This method will never be called.
*/
public void reset(){
throw new ToXgeneErrorException("DIED A HORRIBLE DEATH!");
}
/**
* For compatibility reasons only. This method will never be called.
*/
public void generate(PrintStream outStream){
throw new ToXgeneErrorException("DIED A HORRIBLE DEATH!");
}
/**
* For compatibility reasons only. This method will never be called.
*/
public Vector getChildren(){
throw new ToXgeneErrorException("DIED A HORRIBLE DEATH!");
}
/**
* For compatibility reasons only. This method will never be called.
*/
public Vector children(){
throw new ToXgeneErrorException("DIED A HORRIBLE DEATH!");
}
// rwj
public void resetRandomGen() {
// nothing to do
}
public int numIterators(){
return root.numIterators();
}
public void destroy(){
if (uses != null){
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy