
toxgene.core.genes.trees.ToxRecursiveMixedContent Maven / Gradle / Ivy
/**
* Implements a gene for mixed recursive mixed content
* generation. Essentially, this object behaves identically to a
* ToxElement. except it does not output a tagname.
*
* @author Denilson Barbosa
* @version 0.1 */
package toxgene.core.genes.trees;
import java.io.PrintStream;
import java.util.Vector;
import toxgene.core.ToXgeneErrorException;
import toxgene.core.genes.ContainerGene;
import toxgene.core.genes.Gene;
import toxgene.core.genes.VarQttyGene;
import toxgene.core.genes.lists.ListGene;
import toxgene.core.genes.lists.ToxList;
import toxgene.core.genes.lists.ToxListElement;
import toxgene.core.genes.lists.ToxListElementException;
import toxgene.core.genes.literals.LiteralGene;
import toxgene.core.parser.ToxComplexType;
import toxgene.core.random.ToxRandom;
public class ToxRecursiveMixedContent extends ToxElement
implements TreeGene, ListGene {
/**
* Minimum and maximun numbers of occurrences for actual instances
*/
private int min_qtty, max_qtty;
/**
* determines whether this element has a predefined upper limit on its
* number of occurrences (i.e., max_qtty).
*/
private boolean get_max_qtty = false;
/**
* Pseudo-random number generator
*/
private ToxRandom randomGenerator;
/**
* Vector with all direct attributes of the element.
*/
private Vector attributes;
/**
* Vector for the genes that define the contents of the element,
* regardless of its content model.
*/
private Vector contents;
/**
* Vector with all container objects inside this element. Container
* objects contain attributes and other elements that might or might not
* be generated, depending on factors external to this element.
*/
private Vector containers;
/**
* Vector with all genes that have variable number of occurrences. These
* genes determine the actual number of occurrences of the current
* element. Each element in this vector is also in the contents vector
* (inserted in the correct order of appearence in the input template) and
* is generated like any other gene.
*/
private Vector varQttyContents;
/**
* Vector with all tox-scan elements that are direct children of this
* elment, used to reset them before generating any data. Each element in
* this vector is also in the varQttyContents (thus also in the contents)
* vector.
*/
private Vector scans;
/**
* Determines whether this element is a literal or a tree gene.
*/
private boolean isLiteral;
/**
* Determines whether this gene's contents have to be reset each time the
* gene is instantiated.
*/
private boolean resetGenes;
/**
* Number of times the gene will be instantiated.
*/
private int times;
/**
* Number of times the gene was already instantiaded.
*/
private int instance;
private boolean addNewLine;
public ToxRecursiveMixedContent(int min_qtty, int max_qtty,
ToxRandom randomGenerator, boolean isLiteral,
boolean resetGenes, boolean newLines){
this.min_qtty = min_qtty;
this.max_qtty = max_qtty;
this.times = 0;
this.instance = 0;
get_max_qtty = (max_qtty == -1);
contents = new Vector();
attributes = new Vector();
containers = new Vector();
varQttyContents = new Vector();
scans = new Vector();
this.randomGenerator = randomGenerator;
this.isLiteral = isLiteral;
this.resetGenes = resetGenes;
addNewLine = newLines;
}
public int getQtty(){
int times = min_qtty, max = max_qtty;
if (get_max_qtty){
int qtty = 0;
for (int k=0; k0){
throw new ToXgeneErrorException("recursive mixed content declarations cannot have "
+"attributes.");
}
attributes.addAll(holder.attributes());
contents.addAll(holder.contents());
containers.addAll(holder.containers());
varQttyContents.addAll(holder.varQttyContents());
scans.addAll(holder.scans());
}
/**
* Adds a new attribute container to this element.
*/
public void addContainer(ContainerGene gene){
get_max_qtty = true;
containers.add(gene);
}
/**
* Adds a new gene to the contents of the element. This gene has a
* variable number of occurrences, depending on the result of a
* query. This number of occurrences is used to compute the actual number
* of occurrences for this element. The child gene is also added to the
* content list for this element.
*/
public void addVarQttyContent(VarQttyGene gene){
varQttyContents.add(gene);
contents.add(gene);
}
/**
* Adds a new tox-scan/tox-sample gene to the list of scan genes in this
* element. This gene is also added to the contents vector so that it is
* processed in the correct order.
*/
public void addScan(ToxScan gene){
scans.add(gene);
addVarQttyContent(gene);
}
/**
* Outputs the tagName for the element. Used for a ToxFile element when
* printing the doctype information.
*/
public String tagName(){
return null;
}
public String name(){
return null;
}
public Vector children(){
return contents;
}
public Vector getChildren(){
Vector result = null;
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy