/*
 * BICalcQueryAdapter.java
 *
 * Copyright © 1994-2004, Oracle. All rights reserved. Oracle grants
 * you ("Licensee") a non-exclusive, royalty-free, worldwide license to use,
 * modify and redistribute this software in source and binary code form, provided
 * that (i) this copyright notice and license appear on all copies of the
 * software; (ii) Licensee does not utilize the software in a manner disparaging
 * to Oracle; and (iii) Licensee does not utilize the software in a manner that
 * violates the terms of any Licensee agreement with Oracle.
 */
package samples.javaclient;

import oracle.dss.dataSource.common.Query;
import oracle.dss.dataSource.common.QueryAdapter;
import oracle.dss.util.DataAccess;
import oracle.dss.util.DataAvailableEvent;
import oracle.dss.util.DataChangedEvent;
import oracle.dss.util.DataDirector;
import oracle.dss.util.DataDirectorListener;
import oracle.dss.util.WaitDataAvailableEvent;

/**
 * This class shows how to create a query listener that stores data access objects
 */

public class BICalcQueryAdapter extends QueryAdapter
  implements DataDirectorListener {
  // Data Access object
  protected DataAccess m_dataAccess = null;

  // Data Director object
  protected DataDirector m_dataDirector = null;

  // Data source object
  protected Query m_query = null;

  /**
   * Constructor
   *
   * @param ds The query that this listener will be associated with.
   */
  public BICalcQueryAdapter(Query ds) {
    super();
    m_query = ds;
    setDataDirector(m_query.createCubeDataDirector());
    getDataDirector().addDataDirectorListener(this);
  }

  /**
   * Notifies when a lazy data fetch has been completed.
   *
   * @param e Information about the fetch.
   */
  public void waitDataAvailable(WaitDataAvailableEvent e) {
  }

  /**
   * Informs the view of changes to the actual data or metadata.
   *
   * @param e Information about the change in the data.
   */
  public void viewDataChanged(DataChangedEvent e) {
    viewDataAvailable(new DataAvailableEvent(e.getSource(),
      DataAvailableEvent.DATA_AVAILABLE, e.getDataAccess()));
  }

  /**
   * Informs the view that data is ready or revoked.
   *
   * @param e Information about the data provider.
   */
  public void viewDataAvailable(DataAvailableEvent e) {
    setDataAccess(e.getDataAccess());
  }

  /**
   * Set the internal DataAccess.
   *
   * @param da The DataAccess
   */
  public void setDataAccess(DataAccess da) {
    m_dataAccess = da;
  }

  /**
   * Get the DataAccess.
   *
   * @return The DataAccess
   */
  public DataAccess getDataAccess() {
    return m_dataAccess;
  }

  /**
   * Set the internal DataDirector object
   *
   * @param dd The DataDirector
   */
  public void setDataDirector(DataDirector dd) {
    m_dataDirector = dd;
  }

  /**
   * Get the DataDirector
   *
   * @return The DataDirector
   */
  public DataDirector getDataDirector() {
    return m_dataDirector;
  }
}