001 package videoautomat.transition; 002 003 import sale.Gate; 004 import sale.SaleProcess; 005 import sale.SalesPoint; 006 import sale.Transition; 007 import users.User; 008 import users.stdforms.LogOnForm; 009 import videoautomat.SaleProcessLogOn; 010 011 /** 012 * a <code>Transition</code> that proves the selected name and password and with success leads to the 013 * {@link SaleProcessLogOn#getMainGate()}, otherwise it returns the 014 * {@link SaleProcessLogOn#getFaultGate()}. 015 * 016 * @author Alexander Herrmann 017 * 018 */ 019 public class LogOnTransition implements Transition { 020 021 private LogOnForm lof; 022 023 /** 024 * Constructor for referencing the <code>LogOnForm</code> 025 * @param lof 026 */ 027 public LogOnTransition(LogOnForm lof) 028 { 029 this.lof = lof; 030 } 031 032 /** 033 * Proves the user and its password. If successful registeres user, puts user to 034 * <code>ProcessContext</code> and redirects to {@link SaleProcessLogOn#getMainGate()}. 035 * Otherwise returns to {@link SaleProcessLogOn#getFaultGate()}. 036 * @param sp - the current <code>SaleProcess</code> 037 * @param user - the current <code>User</code> 038 */ 039 public Gate perform(SaleProcess sp, User user) { 040 041 SaleProcessLogOn processLogOn = (SaleProcessLogOn) sp; 042 lof.ok(); 043 User user_current = lof.getResult(); 044 045 if(user_current != null) 046 { 047 ((SalesPoint) processLogOn.getContext()).attach(user_current); 048 return processLogOn.getMainGate(); 049 } 050 051 return processLogOn.getFaultGate(); 052 } 053 054 }