View Javadoc

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