001 package videoautomat;
002 import sale.SaleProcess;
003 import sale.SalesPoint;
004 import users.ActionCapability;
005 import users.User;
006 import data.ooimpl.DataBasketImpl;
007 import data.ooimpl.StoringStockImpl;
008
009 /**
010 * This class implements the <code>User</code> of this application. It contains a <code>StoringStock</code> for
011 * storing the actually rented videos and holds the information which capabilities the user has.
012 */
013 public class AutomatUser extends User {
014 /**
015 * Key used to get the <code>ActionCapability</code> used to start a {@link SaleProcessAdmin}.
016 */
017 public static final String CAPABILITY_ADMIN = "admin";
018 /*
019 * The stock which holds the rented videos.
020 */
021 private StoringStockImpl ss_videos;
022 /**
023 * Constructs a new <code>AutomatUser</code>.
024 *
025 * @param user_ID
026 * the ID of the new user
027 * @param admin
028 * boolean to decide, whether this user has administrator privileges or not
029 */
030 public AutomatUser(String user_ID, char[] passWd, boolean admin) {
031 super(user_ID);
032 setPassWd(garblePassWD(passWd));
033 ss_videos = new StoringStockImpl(user_ID, VideoShop.getVideoCatalog());
034 ss_videos.addStockChangeListener(new StockChangeLogger(user_ID));
035 setCapability(new ActionCapability(
036 CAPABILITY_ADMIN,
037 VideoShop.MSG_ACCESS,
038 new sale.Action() {
039 public void doAction(SaleProcess p, SalesPoint sp) throws Throwable {
040 sp.runProcess(new SaleProcessAdmin(), new DataBasketImpl());
041 }
042 }, admin));
043 }
044 /**
045 * @return a <code>StoringStock</code> containing the rented {@link VideoCassette}s of this user
046 */
047 public StoringStockImpl getVideoStock() {
048 return ss_videos;
049 }
050 }
051