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

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

/**
 * Invokes a lookup in a list, according to a given path expression
 *
 * @author Denilson Barbosa
 * @version 0.1
 */

package toxgene.core.genes.literals;


import java.io.PrintStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Vector;

import toxgene.core.Engine;
import toxgene.core.ToXgeneErrorException;
import toxgene.core.genes.VarQttyGene;
import toxgene.core.genes.lists.ListGene;
import toxgene.core.genes.lists.ToxListElement;
import toxgene.core.genes.trees.Expression;
import toxgene.core.genes.trees.Query;
import toxgene.util.Date;

public class ToxGet extends LiteralGene implements ListGene, VarQttyGene{
  /**
   * Expresion that defines the content of this query.
   */
  private Expression expression;
  /**
   * Resulting datatype for the expression defining the query.
   */
  private int type;
  /**
   * Minimum quantity of elements, as specified in the template.
   */
  private int min_qtty;
  /**
   * Maximum quantity of elements, as specified in the tmeplate.
   */
  private int max_qtty;
  /**
   * Actual quantity of elements, depending on the capacity of the list, and
   * the values for min and max.
   */
  private int qtty;
  /**
   * Index of the current element in the vector of possible values.
   */
  private int current;
  /**
   * Vector with all values for this element;
   */
  private Vector values;
  /**
   * Determines whether the output values are unique.
   */
  private boolean unique;
  /**
   * Vector containing the values output between two refresh from the
   * tox-lookup. Used for ensuring uniqueness in the template.
   */
  private Vector output;

  private boolean format;

  private DecimalFormat decimalFormat;
  private SimpleDateFormat dateFormat;

	private Engine tgEngine;

  public ToxGet(Expression expression, int min, int max, String pattern,
								Engine engine){
	min_qtty = min;
	max_qtty = max;
	this.expression = expression;
	this.type = expression.expressionType();
	tgEngine = engine;
	
	if (pattern.length() != 0){
	  format = true;
	  if (type == Expression.INTEGER || type == Expression.REAL){
		decimalFormat = new DecimalFormat(pattern);
	  }
	  else{
		if (type == Expression.DATE){
		  dateFormat = new SimpleDateFormat(pattern);
		}
	  }
	}
	else{
	  format = false;
	}
  }
  
  public void generate(PrintStream outputStream){
 	if (type == Expression.COMPLEX){
 	  //this has got to be a Query :)
 	  Vector values = ((Query)expression).evaluateSCAN();
 	  int size = values == null? 0: values.size();
 	  for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy