View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   
6   package cz.cuni.amis.pogamut.ut2004.communication.translator.bot.state;
7   
8   import cz.cuni.amis.fsm.FSMState;
9   import cz.cuni.amis.fsm.FSMTransition;
10  import cz.cuni.amis.fsm.IFSMState;
11  import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage;
12  import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldChangeEvent;
13  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PathList;
14  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PathListEnd;
15  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PathListStart;
16  import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorContext;
17  import cz.cuni.amis.pogamut.ut2004.communication.translator.bot.support.BotListState;
18  import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.Path;
19  
20  /**
21   * Takes care of the path list. It stores them inside a List object and when END message comes it sends
22   * them to the world view via Path event.
23   * @author Jimmy
24   */
25  @FSMState(map = {
26  					@FSMTransition(
27  							state = BotAliveState.class,
28  							symbol = {PathListEnd.class },
29  							transition = {}
30  					)
31  				}
32  )
33  public class PathAcceptState extends BotListState<PathList, TranslatorContext> {
34  
35      private String pathId = null;
36  
37  	public PathAcceptState() {
38  		super(PathListStart.class, PathList.class, PathListEnd.class);
39  	}
40  
41      @Override
42  	public void stateEntering(TranslatorContext context, IFSMState<InfoMessage, TranslatorContext> fromState, InfoMessage symbol) {
43          super.stateEntering(context, fromState, symbol);
44          pathId = ((PathListStart)symbol).getMessageId();
45      }
46  
47  	@Override
48  	public void stateLeaving(TranslatorContext context, IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
49  		super.stateLeaving(context, toState, symbol);
50  		long simTime = 
51  			(symbol instanceof IWorldChangeEvent ? ((IWorldChangeEvent)symbol).getSimTime() : 0);
52  		context.getEventQueue().pushEvent(new Path(pathId, getList(), simTime));
53  		getList().clear();
54  	}
55  }