CatalogBeanpublic class CatalogBean extends Object implements SerializableThis class represents a product catalog. It holds a list of
products available for sale.
This is just a demo so the product list is hardcoded, created
at instantiation. A real version would get the information from
an external data source. |
Fields Summary |
---|
private Map | catalog |
Constructors Summary |
---|
public CatalogBean()Constructor. Creates all ProductBean objects and adds them
to the catalog.
ProductBean prod = new ProductBean();
prod.setId("1000");
prod.setName("JavaServer Pages");
prod.setDescr("Learn how to develop a JSP based web application.");
prod.setPrice(32.95f);
catalog.put("1000", prod);
prod = new ProductBean();
prod.setId("2000");
prod.setName("Java Servlet Programming");
prod.setDescr("Learn how to develop a servlet based web application.");
prod.setPrice(32.95f);
catalog.put("2000", prod);
prod = new ProductBean();
prod.setId("3000");
prod.setName("Java In a Nutshell");
prod.setDescr("Learn the Java programming language.");
prod.setPrice(32.95f);
catalog.put("3000", prod);
|
Methods Summary |
---|
public ProductBean[] | getProductList()Returns all products as an Iterator, suitable for looping.
ProductBean[] products = new ProductBean[catalog.size()];
catalog.values().toArray(products);
return products;
| public java.util.Map | getProductsById()Returns a Map with all ProductBean instances, keyed by ID.
return catalog;
|
|