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        /**
022             * ID for Serialization.
023             */
024            private static final long serialVersionUID = 6520554025625844846L;
025            private LogOnForm lof;
026        
027        /**
028         * Constructor for referencing the <code>LogOnForm</code>
029         * @param lof
030         */
031        public LogOnTransition(LogOnForm lof)
032        {
033            this.lof = lof;
034        }
035        
036        /**
037         * Proves the user and its password. If successful registeres user, puts user to
038         * <code>ProcessContext</code> and redirects to {@link SaleProcessLogOn#getMainGate()}.
039         * Otherwise returns to {@link SaleProcessLogOn#getFaultGate()}.
040         * @param sp - the current <code>SaleProcess</code>
041         * @param user - the current <code>User</code>
042         */
043        public Gate perform(SaleProcess sp, User user) {
044            
045            SaleProcessLogOn processLogOn = (SaleProcessLogOn) sp;
046            lof.ok();
047            User user_current = lof.getResult();
048            
049            if(user_current != null)
050            {
051                ((SalesPoint) processLogOn.getContext()).attach(user_current);
052                return processLogOn.getMainGate();
053            }
054            
055            return processLogOn.getFaultGate();
056        }
057    
058    }