Example #1
0
  private static Book createBook() throws Exception {
    String title = "";
    String author = "";
    while (title.compareTo("") == 0) {
      System.out.println("\n" + LocaleMessage.getBookTitlePrompt());
      title = getInput();
    }
    while (author.compareTo("") == 0) {
      System.out.println("\n" + LocaleMessage.getAuthorNamePrompt());
      author = getInput();
    }

    return new Book(generateBookId(), title, author);
  }
Example #2
0
  public static void main(String[] args) throws Exception {
    // This is just a simple non mule way to invoke a web service.
    // It will place an order so you can see the emailOrderService
    // in action.
    // For learning how to use CXF with an outbound router, please
    // see the mule-publisher-demo portion of the project.
    new BookstoreClient("bookstore.xml");
    int response = 0;

    System.out.println("\n" + LocaleMessage.getWelcomeMessage());

    while (response != 'q') {
      System.out.println("\n" + LocaleMessage.getMenuOption1());
      System.out.println("\n" + LocaleMessage.getMenuOption2());
      System.out.println("\n" + LocaleMessage.getMenuOption3());
      System.out.println("\n" + LocaleMessage.getMenuOption4());
      System.out.println("\n" + LocaleMessage.getMenuOptionQuit());
      System.out.println("\n" + LocaleMessage.getMenuPromptMessage());
      response = getSelection();

      if (response == '1') {
        Book book = createBook();
        bookstore.addBook(book);
        System.out.println("Added Book");
      } else if (response == '2') {
        Collection<Book> books = new ArrayList<Book>();
        boolean isAddAnotherBook = true;
        while (isAddAnotherBook) {
          Book book = createBook();
          books.add(book);
          System.out.println("\n" + LocaleMessage.getAddBooksMessagePrompt());
          int result = getSelection();
          if (result != 'y') {
            isAddAnotherBook = false;
            bookstore.addBooks(books);
            System.out.println("Added book list");
          }
        }
      } else if (response == '3') {
        Collection<Book> books = bookstore.getBooks();
        System.out.println("Request returned " + books.size() + " book/s");

        for (Iterator i = books.iterator(); i.hasNext(); ) {
          Book book = (Book) i.next();
          System.out.println("Title: " + book.getTitle());
          System.out.println("Author: " + book.getAuthor());
          System.out.println("Id: " + book.getId());
          System.out.println();
        }
      } else if (response == '4') {
        System.out.println("\n" + LocaleMessage.getOrderWelcomeMessage());
        System.out.println("\n" + LocaleMessage.getBookIdPrompt());
        long bookId = Long.parseLong(getInput());
        System.out.println("\n" + LocaleMessage.getHomeAddressPrompt());
        String homeAddress = getInput();
        System.out.println("\n" + LocaleMessage.getEmailAddressPrompt());
        String emailAddress = getInput();

        // order book
        bookstore.orderBook(bookId, homeAddress, emailAddress);

        System.out.println("Book was ordered");
      } else if (response == 'q') {
        System.out.println(LocaleMessage.getGoodbyeMessage());
        System.exit(0);
      } else {
        System.out.println(LocaleMessage.getMenuErrorMessage());
      }
    }
  }
Example #3
0
 public static String getHomeAddressPrompt() {
   return factory.getString(BUNDLE_PATH, 15);
 }
Example #4
0
 public static String getEmailAddressPrompt() {
   return factory.getString(BUNDLE_PATH, 16);
 }
Example #5
0
 public static String getOrderWelcomeMessage() {
   return factory.getString(BUNDLE_PATH, 13);
 }
Example #6
0
 public static String getBookIdPrompt() {
   return factory.getString(BUNDLE_PATH, 14);
 }
Example #7
0
 public static String getAuthorNamePrompt() {
   return factory.getString(BUNDLE_PATH, 11);
 }
Example #8
0
 public static String getAddBooksMessagePrompt() {
   return factory.getString(BUNDLE_PATH, 12);
 }
Example #9
0
 public static String getBookTitlePrompt() {
   return factory.getString(BUNDLE_PATH, 10);
 }
Example #10
0
 public static String getMenuErrorMessage() {
   return factory.getString(BUNDLE_PATH, 9);
 }
Example #11
0
 public static String getGoodbyeMessage() {
   return factory.getString(BUNDLE_PATH, 8);
 }
Example #12
0
 public static String getMenuPromptMessage() {
   return factory.getString(BUNDLE_PATH, 7);
 }
Example #13
0
 public static String getMenuOptionQuit() {
   return factory.getString(BUNDLE_PATH, 6);
 }