final String viewClassName = ShoppingCart.class.getName();
/* Lookup the remote interface of the shopping cart */
String lookupName = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName
+ "?stateful";
final ShoppingCart cart = (ShoppingCart) context.lookup(lookupName);
System.out.println("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
System.out.println("Obtained the remote interface to the shopping cart");
/* invoke on the remote interface */
System.out.println("Buying a \"" + EAP + "\"");
cart.buy(EAP, 1);
System.out.println("Buying another \"" + EAP + "\"");
cart.buy(EAP, 1);
System.out.println("Buying a \"" + SOAP + "\"");
cart.buy(SOAP, 1);
System.out.println("\nPrint cart:");
HashMap<String, Integer> cartContents = cart.getCartContents();
for (String product : cartContents.keySet()) {
System.out.println(cartContents.get(product) + " " + product);
}
System.out.println("\nCheckout");
cart.checkout();
/* Try to access the cart after checkout */
try {
cart.getCartContents();
System.err.println("ERROR: The cart should not be available after Checkout!");
} catch (NoSuchEJBException e) {
System.out.println("Cart was correctly removed, as expected, after Checkout and is no longer available!");
}
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");