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