View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.translator.bot.state;
2   
3   import cz.cuni.amis.fsm.FSMState;
4   import cz.cuni.amis.fsm.FSMTransition;
5   import cz.cuni.amis.fsm.IFSMState;
6   import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage;
7   import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldChangeEvent;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PasswdOk;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PasswdWrong;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Password;
11  import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorContext;
12  import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorMessages;
13  import cz.cuni.amis.pogamut.ut2004.communication.translator.UnexpectedMessageException;
14  import cz.cuni.amis.pogamut.ut2004.communication.translator.bot.support.AbstractBotFSMState;
15  
16  /**
17   * Entered by the Password message that is sent to the world view, the state then wait for PasswdOk or PasswdWrong
18   * message to came.
19   * 
20   * @author Jimmy
21   */
22  @FSMState(map={@FSMTransition(
23                  state=ReadyState.class, 
24                  symbol={PasswdOk.class}, 
25                  transition={}),
26                 @FSMTransition(
27                  state=CommunicationTerminatedState.class, 
28                  symbol={PasswdWrong.class},
29                  transition={})
30                 }
31  )
32  public class PasswordState extends AbstractBotFSMState<InfoMessage, TranslatorContext> {
33  	
34  	@Override
35  	public void init(TranslatorContext context) {
36  	}
37  
38  	@Override
39  	public void restart(TranslatorContext context) {
40  	}
41  
42  	@Override
43  	public void stateEntering(TranslatorContext context,
44  			IFSMState<InfoMessage, TranslatorContext> fromState,
45  			InfoMessage symbol) {
46  		if (!(symbol instanceof Password)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol, Password.class), context.getLogger(), this);
47  		if (!(symbol instanceof IWorldChangeEvent)) throw new UnexpectedMessageException(TranslatorMessages.messageNotWorldEvent(this, symbol), context.getLogger(), this);
48  		context.getEventQueue().pushEvent((IWorldChangeEvent)symbol);
49  	}
50  
51  	@Override
52  	public void stateLeaving(TranslatorContext context,
53  			IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
54  	}
55  
56  	@Override
57  	public void stateSymbol(TranslatorContext context, InfoMessage symbol) {
58  		if (!(symbol instanceof Password)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol), context.getLogger(), this);
59  	}
60  	
61  }