01: package com.mockrunner.example.struts;
02:
03: import javax.servlet.ServletContext;
04:
05: /**
06: * The <code>OrderManager</code> used in {@link OrderAction}.
07: * This example implementation does nothing.
08: */
09: public class OrderManager {
10: protected OrderManager() {
11:
12: }
13:
14: public static synchronized OrderManager instance(
15: ServletContext context) {
16: OrderManager manager = (OrderManager) context
17: .getAttribute(OrderManager.class.getName());
18: if (null == manager) {
19: manager = new OrderManager();
20: context.setAttribute(OrderManager.class.getName(), manager);
21: }
22: return manager;
23: }
24:
25: public int getStock(String id) {
26: //get stock
27: return 0;
28: }
29:
30: public void order(String id, int amount) {
31: //do order
32: }
33: }
|