Source : Disk.java

CS22120 Group Project - project source listings

Questions and comments on this file can be directed to this classes author: Paul Smith

View Test Results.


package cs221.groupk.common;

import java.util.*;
import java.io.*;
import cs221.groupk.exceptions.database.*;

/**
 * Disk is the Serializable class the gets written to and read from at system
 * startup and shutdown. This class represents all the data that is passed
 * between the systems, so <B>ALL</B> information must be passed through this
 * class if it is requried.<BR>This class is part of the Database, so will
 * take care of data normalisation and compression before writing to file, as
 * well as writing a backup to the local hard disk, using the date to create
 * a unique filename.<BR>Also note, this class has many methods that are of an
 * admin only type, while these are present, internal checking prevents
 * unauthorised users from using these methods.
 *
 * <P><I>Code spell-checked - Chris Milner - 5th December 2000.</I><P>
 *
 * @author <A HREF="mailto:[email protected]">Paul Smith</A>
 */
public class Disk implements StdDisk, Serializable, Constants
{
  /**users is the internal store of saleItems*/
  protected UserSet userSet = null;
  /**saleItems is the internal store of saleItems*/
  protected SaleItemList saleItems = null;
  /**boughtItems is the internal store of saleItems*/
  protected BoughtItemList boughtItems = null;
  /**
   * location is the id specifying which station the disk is for.
   * @see Constants#UNDEFINED
   * @see Constants#TOP_STATION
   * @see Constants#BOTTOM_STATION
   */
  protected int location = UNDEFINED;
  /**backupEngine is only used if location is a station, then backups are kept*/
  protected StationBackupEngine backupEngine;
  /**usersloggedIn maintains a list of users that log in to the system*/
  protected User[] usersloggedIn;
  /**
   * usersLoggedInAt maintains a list of when users logged in. This matches
   * the usersloggedIn.usersloggedIn
   * @see Disk
   */
  protected Date[] usersLoggedInAt;


  /**
   * Default Constructor of Disk.
   */
  /* This has been included as it is required for manual class Serialization
   * DO NOT REMOVE - Paul.
   */
  public Disk()
  {
    //conditional create backupEngine
  }

  /**
   * writeToDisk writes the contents of <B>this</B> disk object to the disk,
   * replacing the disks contents in drive A. <B>Note</B> there are check ect
   * performed before the data is written, and this is where todays data is
   * copied to the local filestore for long term local back-up storage.
   * @return int error code.
   * @see Constants
   * @exception InsufficientAccessPrivilegeException is thrown when a user attempts
   * to call this method without first calling the Validate method.
   */
  public int writeToDisk() throws InsufficientAccessPrivilegeException
  {
    return -1;
  }

  /**
   * Initialises the internal values of this class with those present on the
   * copy of this class on the disk in drive A.
   * @return Disk - from the file on the transfer diskette.
   */
  public static Disk readFromDisk()
  {
    return null;
  }

  /**
   * registerSale adds the BoughtItem (boughtItem) to the local file, ready to
   * be written to the transfere diskette later. At this stage there is to
   * have been <B>no</B> processing on the data. All processing including
   * normalisation will take place within this class, prior to writing to
   * diskette or when being added to the main database.
   * @param BoughtItem boughtItem is the Item has been perchased and confirmed.
   * @exception InsufficientAccessPrivilegeException is thrown when a user attempts
   * to call this method without first calling the Validate method.
   */
  public void registerSale(BoughtItem boughtItem) throws InsufficientAccessPrivilegeException
  {
    //make a call to the backupEngine & the local store!
  }

  /**
   * getSaleItems returns a complete list of the available sale items from the
   * Disk.
   * @see SaleItem
   * @return SaleItemList list class containing the saleItem Objects for this
   * disk.
   * @exception InsufficientAccessPrivilegeException is thrown when a user attempts
   * to call this method without first calling the Validate method.
   */
  public SaleItemList getSaleItems() throws InsufficientAccessPrivilegeException
  {
    return null;
  }

  /**
   * validateUser is a transparent call to the method validateUser inside the
   * UserSet class.
   * @return int error code, or access level.
   * @param String user username to validate.
   * @param String pswd password for supplied username.
   * @see UserSet#validateUser(String, String)
   * @see Constants#VALIDATION_SUCCESFULL_ALL
   * @see Constants#VALIDATION_SUCCESFULL_STATIONS
   * @see Constants#VALIDATION_SUCCESFULL_BOTTOM_STATION
   * @see Constants#VALIDATION_SUCCESFULL_TOP_STATION
   * @see Constants#VALIDATION_FAIL_NOT_AUTHORISED
   * @see Constants#VALIDATION_FAIL_NO_SUCH_USER
   * @see Constants#VALIDATION_FAIL_INVALID_PASSWORD
   */
  public int validateUser(String user, String pswd)
  {
    //add usersloggedIn & usersloggedInAt values.
    return -1;
  }

  /**
   * Sets the system to ACCESS_LEVEL_NOT_VALIDATED, thus disabling the entire
   * system. Once this method is called no further sales can be logged or can
   * any methods be called from the Disk class without first calling
   * validateUser(String, String).
   * @return boolean returns true if sucessfully logged off.
   */
  public boolean logOffSystem()
  {
    return userSet.logOffSystem();
  }

  /**
   * getUserSet returns the user set from the diskette. This method is called
   * by any module that requires any administration of the user database.
   * If this method is called and the calling user does not have sufficient
   * access privilages then the an exception is thrown.
   * @exception InsufficientAccessPrivilegeException is thrown when a user attempts
   * to call this method without first calling the Validate method.
   */
  public UserSet getUserSet() throws InsufficientAccessPrivilegeException
  {
    return null;
  }

  /**
   * getBoughtItems returns an array of Bought Items, exactly as they were
   * entered (using register sale).
   */
  public BoughtItem[] getBoughtItems()
  {
    return null;
  }

  /**
   * setUserSet sets this Disks UserSet to the the parameter userSet. <I>This
   * method can only be run under the admin machine.</I>
   * @param UserSet userSet to replace the disks current user set with.
   * @exception InsufficientAccessPrivilegeException is thrown when a user attempts
   * to call this method without first calling the Validate method.
   */
  public void setUserSet(UserSet userSet) throws InsufficientAccessPrivilegeException
  {
    this.userSet = userSet;
  }

  /**
   * This method is not normally required for Object Serialization, however
   * it has been deemed necessary that it may be required to compress the
   * output from this class, the best way of doing so is as the data is being
   * written to disk.
   */
  private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException
  {
    //if valid
    //out.reset();//deletes previous class.
  }

  private void readObject(ObjectInputStream in) throws IOException
  {

  }
}


Up one level.

Page automatically generated on: 26/01/01 at: 10:48:15.