FileDocCategorySizeDatePackage
SmallBookServiceServant.javaAPI DocExample1907Fri Oct 11 11:54:08 BST 2002ora.jwsnut.chapter6.smallbookservice

SmallBookServiceServant.java

package ora.jwsnut.chapter6.smallbookservice;

import java.util.Date;
import javax.xml.rpc.holders.StringHolder;

/**
 * Implementation class for the small book web service.
 */
public class SmallBookServiceServant implements SmallBookQuery {
    
    /**
     * Gets the number of books known to the service
     * @return the number of books known to the service.
     */
    public int getBookCount() {
        String[] titles = SmallBookServiceServantData.getBookTitles();
        return titles == null ? 0 : titles.length;
    }

    /**
     * Gets the title of a given book.
     * @param index the index of the book whose title is required
     * @return the title of the given book, or <code>null</code> if
     * the index is not valid.
     */
    public String getBookTitle(int index) {
        String[] bookTitles = SmallBookServiceServantData.getBookTitles();        
        return bookTitles == null || index < 0 || index >= bookTitles.length 
                                                ? null : bookTitles[index];
    }
    
    /**
     * Gets the author for a books with a given title
     * @param title the titles of the book
     * @param author an output parameter that will be set to the author of the given book
     * @throws SmallBookServiceException if the book title is unknown
     */
    public void getBookAuthor(String title, StringHolder author) throws SmallBookServiceException {
        String authorName = SmallBookServiceServantData.getBookAuthor(title);
        if (authorName == null) {
            throw new SmallBookServiceException("Unknown author: " + title);
        }
        author.value = authorName;
    }  
    
    /**
     * Makes a log entry.
     * @param value the value to be logged.
     */
    public void log(String value) {
        System.out.println(new Date() + ": " + value);
    }
}