/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.security;

import java.util.*;
import com.silverwrist.dynamo.db.NamespaceCache;
import com.silverwrist.dynamo.db.UserProxyManagement;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;

class ReadAuditRecordSet implements AuditRecordSet
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private AuditReadOps m_ops;
  private NamespaceCache m_ns_cache;
  private UserProxyManagement m_proxy;
  private List m_record_ids;

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  ReadAuditRecordSet(AuditReadOps ops, NamespaceCache ns_cache, UserProxyManagement proxy, List record_ids)
  {
    m_ops = ops;
    m_ns_cache = ns_cache;
    m_proxy = proxy;
    m_record_ids = record_ids;

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Implementations from interface AuditRecordSet
   *--------------------------------------------------------------------------------
   */

  public int getRecordCount()
  {
    return m_record_ids.size();

  } // end getRecordCount

  public AuditRecord getRecord(int index) throws DatabaseException
  {
    if ((index<0) || (index>=m_record_ids.size()))
      throw new IndexOutOfBoundsException("record index out of bounds");

    // Get the basic record data.
    long rec_id = ((Long)(m_record_ids.get(index))).longValue();
    Map record_data = m_ops.getAuditRecordData(rec_id);

    // Get some extra information.
    record_data.put(AuditReadOps.HMKEY_NAMESPACE,
        m_ns_cache.namespaceIdToName(((Integer)(record_data.get(AuditReadOps.HMKEY_NSID))).intValue()));
    record_data.put(AuditReadOps.HMKEY_USER,
		    m_proxy.getUserProxy(((Integer)(record_data.get(AuditReadOps.HMKEY_UID))).intValue()));
    return new ReadAuditRecord(rec_id,record_data);

  } // end getRecord

} // end class ReadAuditRecordSet
