001    package sale;
002    
003    import users.User;
004    
005    /**
006     * Convenience implementation of a Transition that simply changes to another gate. Additionally, some other
007     * useful Transitions are provided.
008     *
009     * @see Transition
010     * @see Gate
011     *
012     * @author Steffen Zschaler
013     * @version 2.0 17/08/1999
014     * @since v2.0
015     */
016    public class GateChangeTransition extends Object implements Transition {
017    
018        /**
019         * The target gate.
020         *
021         * @serial
022         */
023        protected Gate m_gTarget;
024    
025        /**
026         * Create a new GateChangeTransition.
027         *
028         * @param gTarget the Gate to change to.
029         */
030        public GateChangeTransition(Gate gTarget) {
031            super();
032    
033            m_gTarget = gTarget;
034        }
035    
036        /**
037         * Perform the Transition. I.e. go to the gate indicated on creation.
038         *
039         * @override Never
040         */
041        public final Gate perform(SaleProcess p, User u) {
042            return m_gTarget;
043        }
044    
045        // some convenience constants
046        /**
047         * Transition that will go to the calling process' {@link SaleProcess#getRollbackGate rollback gate}.
048         */
049        public static final Transition CHANGE_TO_ROLLBACK_GATE = new Transition() {
050            public Gate perform(SaleProcess p, User u) {
051                return p.getRollbackGate();
052            }
053        };
054    
055        /**
056         * Transition that will go to the calling process' {@link SaleProcess#getCommitGate commit gate}.
057         */
058        public static final Transition CHANGE_TO_COMMIT_GATE = new Transition() {
059            public Gate perform(SaleProcess p, User u) {
060                return p.getCommitGate();
061            }
062        };
063    
064        /**
065         * Transition that will go to the calling process' {@link SaleProcess#getQuitGate quit gate}.
066         */
067        public static final Transition CHANGE_TO_QUIT_GATE = new Transition() {
068            public Gate perform(SaleProcess p, User u) {
069                return p.getQuitGate();
070            }
071        };
072    
073        /**
074         * Transition that will go to the calling process' {@link SaleProcess#getStopGate stop gate}.
075         */
076        public static final Transition CHANGE_TO_STOP_GATE = new Transition() {
077            public Gate perform(SaleProcess p, User u) {
078                return p.getStopGate();
079            }
080        };
081    
082        /**
083         * Transition that will go to the calling process' {@link SaleProcess#getLogGate log gate}.
084         */
085        public static final Transition CHANGE_TO_LOG_GATE = new Transition() {
086            public Gate perform(SaleProcess p, User u) {
087                return p.getLogGate();
088            }
089        };
090    }