import java.util.*;
import java.rmi.*;

public class InventoryClient {

  public InventoryClient(String inHost) {

    try {
      Inventory inventory = (Inventory)Naming.lookup("rmi://" +
        inHost + ":2001/Inventory");

      Vector catalogItems = inventory.getCatalogItems();
      CatalogItem item = null;
      for(int i=0, len=catalogItems.size(); i<len; i++) {
        item = (CatalogItem)catalogItems.elementAt(i);
        System.out.println("CatalogItem = " + item);
      }

      CD lookupCD = new CD("Crash", "Dave Matthews Band", -1, -1);
      System.out.println("Looking for cd Title=" + 
        lookupCD.getTitle() + ", Artist=" + lookupCD.getArtist() +
        " in Inventory");
      int qty = inventory.getQuantityInInventory(lookupCD);
      if(qty > 0) {
        System.out.println("Found CD .");
        System.out.println("\t quantity in Inventory = " + qty);
      }
 
    } catch (Exception ex) {
      System.out.println("Caught exception = " + ex);
      ex.printStackTrace();
    }
  }

  public static void main(String args[]) {
    String host = "localhost";
    if(args.length >= 1) {
      host = args[0];
    }
    InventoryClient client = new InventoryClient(host);
  }
}
