View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.translator.shared.transition;
2   
3   import cz.cuni.amis.fsm.IFSMState;
4   import cz.cuni.amis.fsm.IFSMTransition;
5   import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage;
6   import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldChangeEvent;
7   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo;
8   import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorContext;
9   import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorMessages;
10  import cz.cuni.amis.pogamut.ut2004.communication.translator.UnexpectedMessageException;
11  
12  /**
13   * Transition that is used in GameInfoExpectedState and ReadyState when the GameInfo message is received
14   * to send the GameInfo event.
15   * @author Jimmy
16   */
17  public class GameInfoTransition implements IFSMTransition<InfoMessage, TranslatorContext> {
18  
19  	@Override
20  	public void init(TranslatorContext context) {
21  	}
22  
23  	@Override
24  	public void restart(TranslatorContext context) {
25  	}
26  
27  	@Override
28  	public void stepped(TranslatorContext context,
29  			IFSMState<InfoMessage, TranslatorContext> fromState,
30  			InfoMessage bySymbol,
31  			IFSMState<InfoMessage, TranslatorContext> toState) {
32  		if (!(bySymbol instanceof GameInfo)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, bySymbol, GameInfo.class), context.getLogger(), this);
33  		if (!(bySymbol instanceof IWorldChangeEvent)) throw new UnexpectedMessageException(TranslatorMessages.messageNotWorldEvent(this, bySymbol), context.getLogger(), this);
34  		context.getEventQueue().pushEvent((GameInfo)bySymbol);		
35  	}
36  	
37  	@Override
38  	public String toString() {
39  		return getClass().getSimpleName();
40  	}
41  
42  }