package net.sf.jasperreports.engine;

import net.sf.jasperreports.engine.fill.JRBaseFiller;
import net.sf.jasperreports.engine.fill.JRFillChart;
import net.sf.jasperreports.engine.fill.JRFillChartDataset;

public abstract class JRAbstractChartCustomizer implements JRChartCustomizer {
  private JRBaseFiller filler;
  
  private JRFillChartDataset chartDataset;
  
  public void init(JRBaseFiller chartFiller, JRFillChart chart) {
    this.filler = chartFiller;
    this.chartDataset = (JRFillChartDataset)chart.getDataset();
  }
  
  protected final Object getParameterValue(String parameterName) {
    return getParameterValue(parameterName, false);
  }
  
  protected final Object getParameterValue(String parameterName, boolean fromInputDataset) {
    return (fromInputDataset ? this.chartDataset.getInputDataset() : this.filler.getMainDataset()).getParameterValue(parameterName);
  }
  
  protected final Object getVariableValue(String variableName) {
    return getVariableValue(variableName, false);
  }
  
  protected final Object getVariableValue(String variableName, boolean fromInputDataset) {
    return (fromInputDataset ? this.chartDataset.getInputDataset() : this.filler.getMainDataset()).getVariableValue(variableName);
  }
  
  protected final Object getFieldValue(String fieldName) {
    return getFieldValue(fieldName, false);
  }
  
  protected final Object getFieldValue(String fieldName, boolean fromInputDataset) {
    return (fromInputDataset ? this.chartDataset.getInputDataset() : this.filler.getMainDataset()).getFieldValue(fieldName);
  }
}
