FileDocCategorySizeDatePackage
DocBookServiceServant.javaAPI DocExample3407Tue Dec 17 19:57:50 GMT 2002ora.jwsnut.chapter6.docbookservice

DocBookServiceServant

public class DocBookServiceServant extends Object implements DocBookQuery
Implementation class for the books web service.

Fields Summary
private SOAPFactory
factory
SOAPFactory used to create SOAPElements
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 = DocBookServiceServantData.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.StringgetBookAuthor(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 DocBookServiceServantData.getBookInfo().length;
    
public BookInfogetBookInfo(java.lang.String title)
Gets all details for a book with a given title.

param
title the title of the book.
return
the BookInfo for the book, or null if no matching book can be found.

        return findBook(title);
    
public java.lang.StringgetBookTitle(int index)
Gets the title for a book with a given index.

param
index the index of the book for which the title is required.
return
the book title, or null if the index is invalid

        int count = getBookCount();
        String title = null;
        if (index >= 0 || index < count) {
            title = DocBookServiceServantData.getBookInfo()[index].getTitle();
        }
        return title;
    
public javax.xml.soap.SOAPElementgetStockInfo(java.lang.String title)
Gets the stock level for a book with a given title.

param
title the title of the book.
return
the current stock level of the book.

        BookInfo book = findBook(title);
        SOAPElement element = null;
        if (book != null) {
            try {
                if (factory == null) {
                    factory = SOAPFactory.newInstance();
                }
                element = factory.createElement("stock");
                element.addTextNode(String.valueOf(book.getStock())); 
            } catch (SOAPException ex) {
                // Just return null in this case
                element = null;
            }
        }
        return element;