FileDocCategorySizeDatePackage
ContextBookServiceClient.javaAPI DocExample2920Sun Oct 20 14:15:52 BST 2002ora.jwsnut.chapter6.client

ContextBookServiceClient

public class ContextBookServiceClient extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        
        if (args.length < 1) {
            usage();
        }        
        
        try { 
            // Get the endpoint interface
            ContextBookService_Impl service = new ContextBookService_Impl();
            ContextBookQuery bookQuery = service.getContextBookQueryPort();
            Stub stub = (Stub)bookQuery;
            stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]);
            
            // Enable session maintenance so that the setUpperCase()
            // method works.
            stub._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
            
            // Set the user name and password for authentication purposes
            // provided that the values are available in the System properties
            String userName = System.getProperty("ContextBooks.user");
            String password = System.getProperty("ContextBooks.password");
            if (userName != null && password != null) {
                stub._setProperty(Stub.USERNAME_PROPERTY, userName);
                stub._setProperty(Stub.PASSWORD_PROPERTY, password);
            }
            
            // Enable upper case titles if requested
            boolean upperCase = args.length > 1 && args[1].equalsIgnoreCase("uppercase");
            bookQuery.setUpperCase(upperCase);
            System.out.println("Upper case? " + bookQuery.isUpperCase());
            
            // Get the number of books
            int bookCount = bookQuery.getBookCount();
            System.out.println("Number of books: " + bookCount);

            // Get Call objects for the getBookTitle() and getBookAuthor methods
            StringHolder holder = new StringHolder();
            for (int i = 0; i < bookCount; i++) {
                // Get the book title
                String title = bookQuery.getBookTitle(i);
                System.out.print("Book title is [" + title + "], ");

                // Get the book's author.
                bookQuery.getBookAuthor(title, holder);
                System.out.println("author is [" + holder.value + "]");
            }
            
            // Log successful completion
            bookQuery.log("Successful completion.");
        } catch (Exception ex) {
            System.out.println(ex);
            ex.printStackTrace(System.out);
        }
    
public static voidusage()

        System.err.println("Usage: java ContextBookServiceClient address [uppercase]");
        System.exit(1);