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); }
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()); } } }
public static String getHomeAddressPrompt() { return factory.getString(BUNDLE_PATH, 15); }
public static String getEmailAddressPrompt() { return factory.getString(BUNDLE_PATH, 16); }
public static String getOrderWelcomeMessage() { return factory.getString(BUNDLE_PATH, 13); }
public static String getBookIdPrompt() { return factory.getString(BUNDLE_PATH, 14); }
public static String getAuthorNamePrompt() { return factory.getString(BUNDLE_PATH, 11); }
public static String getAddBooksMessagePrompt() { return factory.getString(BUNDLE_PATH, 12); }
public static String getBookTitlePrompt() { return factory.getString(BUNDLE_PATH, 10); }
public static String getMenuErrorMessage() { return factory.getString(BUNDLE_PATH, 9); }
public static String getGoodbyeMessage() { return factory.getString(BUNDLE_PATH, 8); }
public static String getMenuPromptMessage() { return factory.getString(BUNDLE_PATH, 7); }
public static String getMenuOptionQuit() { return factory.getString(BUNDLE_PATH, 6); }