IDL Constructed Types   «Prev  Next»

Corba Mapping Exception - Exercise

Course Project: Exception Handling

Objective: Use exceptions defined in IDL by implementing CORBA exception handling in Java.

Exercise scoring

You will receive 10 points for this exercise. This exercise is auto-scored; when you have completed the exercise, click the Submit button to receive full credit.

Background and Overview

Once again, you will be writing the BookStore service implementation. Exceptions have been added to the operations of all services. You are given two working servers that place object references into the Naming Service upon startup. You are also given the shell of another server program that acts as a client to the first two servers. You will need to modify the client program to access both servers. All initialization of the objects is done for you. The IDL for the exercise follows. Pay particular attention to the definitions of exceptions and their use in operation raises clauses.
module ECommerceModule {
 exception CreditDenialException {
  string reason;
 };
 struct CreditInfo { 
  string cardnumber;
  string expdate;
  float   creditLimit;
 };
};

module BookShopModule {
 struct Book { 
  string title;
  string author;
 };
 typedef sequence<book> BookList;
 struct Sale {
  Book   bk;
  float  discount;
 };
 typedef sequence<sale> SaleList;
 struct PriceInfo {
  Book   bk;
  float  discount;
  float  price;
 };
 typedef sequence<priceinfo> PriceInfoList;
 enum OrderStatus { BackOrdered ,Available ,Unavailable ,Unknown,
   Satisfied };
 struct BookOrder {
  Book bk;
  long numCopies;
  float price;
  OrderStatus status;
 };
 typedef sequence<bookorder> BookOrderList;
  exception BookDoesNotExistException {
  Book bookDesc;
 };
 exception InventoryException {
  Book bookDesc;
  string reason;
 };
 exception InvalidSaleException {
  string reason;
 };

  
 interface BookStoreInv {
  long getNumCopiesOfBook(in Book bk) raises (BookDoesNotExistException);
  boolean isBookInStock(in Book bk);
  Book getBook(in string title) raises (BookDoesNotExistException) ;
  BookList listAllBooks();
  void addBook(in Book bk,in float cost) raises (InventoryException);
  void addCopies(in Book morecopies,in long qty) raises
  (InventoryException, BookDoesNotExistException);
  void removeCopies(in Book bk,in long qty) raises  (InventoryException, 
  BookDoesNotExistException);
  OrderStatus getOrderStatus(in BookOrder order) raises
    (BookDoesNotExistException);
  void satisfyOrders(inout BookOrderList books) raises
    (BookDoesNotExistException,InventoryException);
 };
 interface Pricer {
  attribute float standardMarkUp;
  float priceBook(in Book bk) raises 
    (BookDoesNotExistException) ;
  void  priceOrders(inout BookOrderList order) raises
    (BookDoesNotExistException );
  void  addSale(in Sale sale) raises (BookDoesNotExistException,
  InvalidSaleException);
  void  removeSale(in Sale sale) raises 
    (BookDoesNotExistException, InvalidSaleException);
  boolean isBookOnSale(in Book bk,out float salePercentage) raises
    (BookDoesNotExistException) ;
  SaleList listAllSales();
 };
 
 exception ServiceException {
  string reason;
  string detail;
 };

 interface BookStore {
  readonly attribute string storeName;
  OrderStatus getBookStatus(in string title) raises (ServiceException) ;
  BookList listAllBooks(); 
  BookList listBooksForAuthor(in string author);
  PriceInfoList lookUpBookPrice(in BookList list) raises
(ServiceException) ;
  BookOrderList buyBooks(in BookList list,in ECommerceModule::CreditInfo info ) 
  raises (ServiceException,ECommerceModule::CreditDenialException);
 };
};

The meanings of the exceptions defined above are as follows:
  1. The exception BookDoesNotExistException is thrown whenever a book title specified is not in the inventory list of the BookStoreInv server or Pricer server.
  2. The exception CreditDenialException is thrown when there is not enough credit on the card, one of the credit information fields is missing, or the expiration date has passed.
  3. The InventoryException is thrown when a problem with the persistent store occurs, or when an operation would cause an invalid (less than zero copies) inventory entry to occur.
  4. The exception InvalidSaleException is thrown when a specified sale doesn’t exist or the discount on a sale is greater than 99% or less than 1% (the transaction must be a sale, and there are no give-aways; this is a business, after all).
  5. An exception ServiceException is thrown to the client when the BookStore service cannot fulfil a request. A reason and a detail message are provided in the exception.

Download files

First, download the Module4ExerciseB.zip file, and then unzip it into a work directory. It should create an exercise subdirectory and an exercise solution subdirectory. Edit the env.bat file to reflect your local work directory.

Instructions

Use your implementation from the previous course project exercise. For each method, you should test for bad input parameters and throw exceptions for each of the methods indicated in the BookStore interface. You should also catch exceptions from the other servers and decide to throw an exception or to go on processing a list.
Edit bookstoreserver.BookStoreImpl and fill in the following methods:
  1. lookUpBookPrice()
  2. buyBooks()

Remember that CreditInfo is in the EcommerceModule package, so you will need to add an import statement to the class before it will compile.
When using sequences, remember that they are simply creating arrays and filling the arrays. Also note that sequence elements should never be left null. Struct members should also never be left null.

Hints

  1. Remember to run the IDL compiler on exer6.idl.
  2. Remember to run the Java compiler on all the Java code, including the code generated by the IDL compiler.
  3. Look at the classes BookShopModule.BookStoreInv and BookShopModule.Pricer to see the method signatures for all the operations. These are the operations you will have to call in your own implementation.
  4. Remember that CreditInfo is in the EcommerceModule package, so you will need to add an import statement to the class before it will compile.
  5. When using sequences, remember that they are simply creating arrays and filling the arrays. Also note that sequence elements should never be left null.
  6. Struct elements should also never be left null.

Completing the exercise

When you have completed the exercise, click the Submit button.