View Javadoc

1   package cz.cuni.amis.pogamut.udk.communication.translator.server.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.udk.communication.messages.gbinfomessages.Mutator;
8   import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Player;
9   import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Vehicle;
10  import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.VehicleListEnd;
11  import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.VehicleListStart;
12  import cz.cuni.amis.pogamut.udk.communication.translator.TranslatorContext;
13  import cz.cuni.amis.pogamut.udk.communication.translator.bot.support.BotListState;
14  import cz.cuni.amis.pogamut.udk.communication.translator.server.support.ServerListState;
15  import cz.cuni.amis.pogamut.udk.communication.translator.shared.events.MutatorListObtained;
16  import cz.cuni.amis.pogamut.udk.communication.translator.shared.events.PlayerListObtained;
17  import cz.cuni.amis.pogamut.udk.communication.translator.shared.events.VehicleListObtained;
18  
19  /**
20   * Takes care of the vehicle list. It stores them inside a List object and when END message comes it sends
21   * them to the world view via VehicleListObtained event.
22   * <p><p>
23   * Last state of the handshake - we switch from this state to the ConfigureMessageExpectedState. 
24   * 
25   * @author Radek 'Black_Hand' Pibil
26   */
27  @FSMState(map={@FSMTransition(
28  					state=ServerRunningState.class, 
29  					symbol={VehicleListEnd.class},
30  					transition={})}
31  )
32  public class VehicleListState extends ServerListState<Vehicle, TranslatorContext> {
33  
34  	public VehicleListState() {
35  		super(VehicleListStart.class, Vehicle.class, VehicleListEnd.class);
36  	}
37  	
38  	@Override
39  	public void stateLeaving(TranslatorContext context,
40  			IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
41  		super.stateLeaving(context, toState, symbol);
42  		context.getEventQueue().pushEvent(new VehicleListObtained(getList()));
43  		newList();
44  	}
45  	
46  	@Override
47  	public void innerStateSymbol(TranslatorContext context, InfoMessage symbol) {
48  		super.innerStateSymbol(context, symbol);
49  		if (symbol instanceof Vehicle) {
50  			context.getEventQueue().pushEvent((Vehicle)symbol);
51  		}
52  	}
53  }