FileDocCategorySizeDatePackage
HeaderBookServiceServant.javaAPI DocExample4192Tue Dec 17 22:54:08 GMT 2002ora.jwsnut.chapter6.headerbookservice

HeaderBookServiceServant

public class HeaderBookServiceServant extends Object implements javax.xml.rpc.server.ServiceLifecycle, HeaderBookQuery
Implementation class for the small book web service.

Fields Summary
private javax.xml.rpc.server.ServletEndpointContext
endpointContext
private String
userName
private String
password
Constructors Summary
Methods Summary
private booleancheckAccess(ora.jwsnut.chapter6.headerbookservice.Authentication auth)
Check whether the calling user is authenticated.

        boolean allowed = false;
        if (userName != null && password != null && auth != null) {
            // Authentication is configured.
            return userName.equals(auth.getUserName()) &&
                    password.equals(auth.getPassword());
        }
        return allowed;            
    
public voiddestroy()

        // Nothing to do
    
public voidgetBookAuthor(java.lang.String title, javax.xml.rpc.holders.StringHolder author, ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)
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
HeaderBookServiceException if the book title is unknown

        calendarHolder.value = new GregorianCalendar();
        String authorName = HeaderBookServiceServantData.getBookAuthor(title);
        if (authorName == null || !checkAccess(auth)) {
            throw new HeaderBookServiceException("Unknown author: " + title);
        }
        author.value = authorName;
    
public intgetBookCount(ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)
Gets the number of books known to the service

return
the number of books known to the service.

        calendarHolder.value = new GregorianCalendar();
        String[] titles = HeaderBookServiceServantData.getBookTitles();
        return titles == null || !checkAccess(auth) ? 0 : titles.length;
    
public java.lang.StringgetBookTitle(int index, ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)
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 null if the index is not valid.

        calendarHolder.value = new GregorianCalendar();
        String[] bookTitles = HeaderBookServiceServantData.getBookTitles(); 
        if (bookTitles == null || index < 0 || index >= bookTitles.length || !checkAccess(auth)) {
            return null;
        }
        return bookTitles[index];
    
public voidinit(java.lang.Object context)

        endpointContext = (ServletEndpointContext)context;
        
        // Get the authorized user name and password from the init parameters
        ServletContext servletContext = endpointContext.getServletContext();
        userName = servletContext.getInitParameter("UserName");
        password = servletContext.getInitParameter("Password");
    
public voidlog(java.lang.String value, ora.jwsnut.chapter6.headerbookservice.Authentication auth, javax.xml.rpc.holders.CalendarHolder calendarHolder)
Makes a log entry.

param
value the value to be logged.

        calendarHolder.value = new GregorianCalendar();
        if (checkAccess(auth)) {
            endpointContext.getServletContext().log(new Date() + ": " + value);
        }