edu.uci.ics.inf111.dvdvendor.devices
Class DVDDispenser

java.lang.Object
  extended by edu.uci.ics.inf111.dvdvendor.devices.DVDDispenser

public class DVDDispenser
extends java.lang.Object

The DVDDispenser class represents a wrapper for a hardware driver of the device to receive and dispense the DVDs. Because we are not really using such a device, our class provides methods to simulate the device is receiving or dispensing DVDs.

The DVDDispenser uses an Observer (or Listener) design pattern. Objects which implement the DVDDispenserListener interface may use the attach() method to register with the DVDDispenser. When a receive or dispense event occurs, the DVDDispenser reports the event to its observers using their notify methods. In this example, we do not support detaching from the DVDDispenser.


Field Summary
private  java.lang.String barCode
          bar code records the current bar code of the DVD being sensed in the DVDDispenser.
private  java.util.Vector<DVDDispenserListener> observers
          observers is a Vector of DVDDispenserListeners which will be notified of receiving and dispensing events.
 
Constructor Summary
DVDDispenser()
          This simple constructor initializes a blank bar code and an empty set of observers.
 
Method Summary
 void attach(DVDDispenserListener ddl)
          The attach() method registers a DVDDispenserListener to receive all future DVDDispenserEvents.
 void blankCode()
          The blankCode() method reset the bar code of the DVDDispenser
 void dispense(java.lang.String barCode)
          dispense() is the method we use to simulate the DVD dispenser is dispensing a product.
 java.lang.String getBarCode()
          Returns the current bar code being registered by the DVD Dispenser reader.
private  void notifyObserver(DVDDispenserEvent event)
          notifyObserver() passes the information of the event along to the observer objects as a DVDDispenserEvent, which includes the current bar code in the the DVD dispenser.
 void receive(java.lang.String barCode)
          receive() is the method we use to simulate the DVD dispenser is receiving a product.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

barCode

private java.lang.String barCode
bar code records the current bar code of the DVD being sensed in the DVDDispenser.


observers

private java.util.Vector<DVDDispenserListener> observers
observers is a Vector of DVDDispenserListeners which will be notified of receiving and dispensing events.

Constructor Detail

DVDDispenser

public DVDDispenser()
This simple constructor initializes a blank bar code and an empty set of observers.

Method Detail

getBarCode

public java.lang.String getBarCode()
Returns the current bar code being registered by the DVD Dispenser reader.


receive

public void receive(java.lang.String barCode)
receive() is the method we use to simulate the DVD dispenser is receiving a product. This is a gross simplification, but will suffice for our system.

Parameters:
barCode - The bar code read in this event.

dispense

public void dispense(java.lang.String barCode)
dispense() is the method we use to simulate the DVD dispenser is dispensing a product. This is a gross simplification, but will suffice for our system.

Parameters:
barCode - The bar code read in this event.

blankCode

public void blankCode()
The blankCode() method reset the bar code of the DVDDispenser


notifyObserver

private void notifyObserver(DVDDispenserEvent event)
notifyObserver() passes the information of the event along to the observer objects as a DVDDispenserEvent, which includes the current bar code in the the DVD dispenser. The information is passed by calling the notifyDVDDispenserEvent() method on the Listener.

Parameters:
event - An event containing the event type and the current bar code in the dispenser.

attach

public void attach(DVDDispenserListener ddl)
The attach() method registers a DVDDispenserListener to receive all future DVDDispenserEvents.

Parameters:
ddl - The Listener (often the calling object) to be attached.