package net.sf.jasperreports.charts.base;

import net.sf.jasperreports.charts.JRCategoryDataset;
import net.sf.jasperreports.charts.JRCategorySeries;
import net.sf.jasperreports.engine.JRChartDataset;
import net.sf.jasperreports.engine.JRExpressionCollector;
import net.sf.jasperreports.engine.base.JRBaseChartDataset;
import net.sf.jasperreports.engine.base.JRBaseObjectFactory;
import net.sf.jasperreports.engine.design.JRVerifier;

public class JRBaseCategoryDataset extends JRBaseChartDataset implements JRCategoryDataset {
  private static final long serialVersionUID = 10200L;
  
  protected JRCategorySeries[] categorySeries = null;
  
  public JRBaseCategoryDataset(JRChartDataset dataset) {
    super(dataset);
  }
  
  public JRBaseCategoryDataset(JRCategoryDataset dataset, JRBaseObjectFactory factory) {
    super((JRChartDataset)dataset, factory);
    JRCategorySeries[] srcCategorySeries = dataset.getSeries();
    if (srcCategorySeries != null && srcCategorySeries.length > 0) {
      this.categorySeries = new JRCategorySeries[srcCategorySeries.length];
      for (int i = 0; i < this.categorySeries.length; i++)
        this.categorySeries[i] = factory.getCategorySeries(srcCategorySeries[i]); 
    } 
  }
  
  public JRCategorySeries[] getSeries() {
    return this.categorySeries;
  }
  
  public byte getDatasetType() {
    return 2;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public void validate(JRVerifier verifier) {
    verifier.verify(this);
  }
  
  public Object clone() {
    JRBaseCategoryDataset clone = (JRBaseCategoryDataset)super.clone();
    if (this.categorySeries != null) {
      clone.categorySeries = new JRCategorySeries[this.categorySeries.length];
      for (int i = 0; i < this.categorySeries.length; i++)
        this.categorySeries[i] = (JRCategorySeries)this.categorySeries[i].clone(); 
    } 
    return clone;
  }
}
