FileDocCategorySizeDatePackage
SBookServiceServant.javaAPI DocExample3138Tue Oct 29 13:51:46 GMT 2002ora.jwsnut.chapter6.serializerbookservice

SBookServiceServant

public class SBookServiceServant extends Object implements SBookQuery
Implementation class for the books web service.

Fields Summary
Constructors Summary
Methods Summary
private BookInfofindBook(java.lang.String name)
Looks for a book whose title matches a given string. The comparison is case-insensitive.

param
name the string to match against the book name
return
the BookInfo object for the first matching book, or null if no match exists.

        BookInfo[] books = SBookServiceServantData.getBookInfo();
        for (int i = 0; i < books.length; i++) {
            if (books[i].getTitle().equalsIgnoreCase(name)) {
                // Found a match
                return books[i];
            }
        }
        return null;        // No match
    
public java.lang.StringgetAuthor(java.lang.String name)
Get the author for a book with a given name.

param
name the name of the book.
return
the author of the book, or null if no matching book can be found.

        BookInfo book = findBook(name);
        return book == null ? null : book.getAuthor();
    
public intgetBookCount()
Gets the number of books known to the service

return
the number of books known to the service.

        return SBookServiceServantData.getBookInfo().length;
    
public BookInfo[]getBookInfo()
Gets information for all known books, in the form of an array.

return
an array of BookInfo objects with one entry for each book.

        return SBookServiceServantData.getBookInfo();
    
public java.util.HashMapgetBookMap()
Returns all of the books known to the book service in the form of a HashMap where the key to each entry is the book title in upper case and the value is a BookInfo object.

        return SBookServiceServantData.getBookInfoHashMap();
    
public java.lang.StringgetEditor(java.lang.String name)
Gets the name of the editor for a book.

param
name the name of the book.
return
the editor of the book, or null if no matching book can be found.

        BookInfo book = findBook(name);
        return book == null ? null : book.getEditor();
    
public doublegetPrice(java.lang.String name)
Gets the price of a book with a given name. If the given name does not match with a known book, a BookServiceException is thrown.

param
name the name of the book.
return
the price of the book.

        BookInfo book = findBook(name);
        if (book == null) {
            // No such book - throw an exception
            throw new BookServiceException("No matching book for '" + name + "'");
        }
        return book.getPrice();