All Downloads are FREE. Search and download functionalities are using the official Maven repository.

toxgene.core.genes.literals.LiteralGene Maven / Gradle / Ivy

The newest version!
/**
 * Defines an abstract class for genes that output literal values. Also,
 * implements the method for recursive generation, which is not relevant to
 * literal genes, by simply calling the non-recursive generate method.
 *
 * @author Denilson Barbosa
 * @version 0.1 */

package toxgene.core.genes.literals;


import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Vector;

import toxgene.core.genes.Gene;
import toxgene.core.genes.lists.ListGene;
import toxgene.core.genes.lists.ToxListElement;
import toxgene.core.genes.lists.ToxListElementException;

public abstract class LiteralGene implements Gene, ListGene{
  private ByteArrayOutputStream temp;
  private PrintStream stream;
  
  public LiteralGene(){
		temp = new ByteArrayOutputStream();
		stream = new PrintStream(temp);
  }

  /**
   * Returns the base type for this value gene
   */
  protected abstract String baseType();

  /**
   * This method is implemented by each concrete class.
   */
  public abstract void generate(PrintStream outStream);

  /**
   * Literal genes can generate leaf nodes in tox-lists easily.
   */
  public void generate(ToxListElement element){
		generate(stream);
		//we simply add a new String child to the element
		element.setContent(temp.toString());
		temp.reset();
  }

  public void reset(){
		//do nothing, overriden by the genes that do really care about this.
  }

  public String getType(){
		return baseType();
  }

  public Vector getChildrenByName(String name) throws ToxListElementException{
		return null;
  }

  public Vector getChildren(){
		return null;
  }
  
  public String name(){
		return "literal";
  }

	public int numIterators(){
		return 0;
	}

	public void destroy(){
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy