package net.sf.jasperreports.charts.base;

import java.io.Serializable;
import net.sf.jasperreports.charts.JRDataRange;
import net.sf.jasperreports.engine.JRExpression;
import net.sf.jasperreports.engine.JRExpressionCollector;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.base.JRBaseObjectFactory;

public class JRBaseDataRange implements JRDataRange, Serializable {
  private static final long serialVersionUID = 10200L;
  
  protected JRExpression lowExpression = null;
  
  protected JRExpression highExpression = null;
  
  public JRBaseDataRange(JRDataRange dataRange) {
    if (dataRange != null) {
      this.lowExpression = dataRange.getLowExpression();
      this.highExpression = dataRange.getHighExpression();
    } 
  }
  
  public JRBaseDataRange(JRDataRange dataRange, JRBaseObjectFactory factory) {
    factory.put(dataRange, this);
    this.lowExpression = factory.getExpression(dataRange.getLowExpression());
    this.highExpression = factory.getExpression(dataRange.getHighExpression());
  }
  
  public JRExpression getLowExpression() {
    return this.lowExpression;
  }
  
  public JRExpression getHighExpression() {
    return this.highExpression;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public Object clone() {
    JRBaseDataRange clone = null;
    try {
      clone = (JRBaseDataRange)super.clone();
    } catch (CloneNotSupportedException e) {
      throw new JRRuntimeException(e);
    } 
    if (this.lowExpression != null)
      clone.lowExpression = (JRExpression)this.lowExpression.clone(); 
    if (this.highExpression != null)
      clone.highExpression = (JRExpression)this.highExpression.clone(); 
    return clone;
  }
}
