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.ItemCategory;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ItemCategoryEnd;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ItemCategoryStart;
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  import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.ItemDescriptor;
16  import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.ItemDescriptorObtained;
17  
18  /**
19   * Takes care of the ITC messages creating new categories inside the ItemTranslator class. Every ITC message that
20   * comes is sent to the ItemTranslator object from the TranslatorContext.
21   * @author Jimmy
22   */
23  @FSMState(map={
24  			@FSMTransition(
25  					state=HandshakeControllerState.class, 
26  					symbol={ItemCategoryEnd.class}, 
27  					transition={})
28  		}
29  )
30  public class ItemCategoryState extends AbstractBotFSMState<InfoMessage, TranslatorContext>{
31  
32  	@Override
33  	public void init(TranslatorContext context) {
34  	}
35  
36  	@Override
37  	public void restart(TranslatorContext context) {
38  	}
39  
40  	@Override
41  	public void stateEntering(TranslatorContext context,
42  							  IFSMState<InfoMessage, TranslatorContext> fromState,
43  			                  InfoMessage symbol) {
44  		if (!(symbol instanceof ItemCategoryStart)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol, ItemCategoryStart.class), context.getLogger(), this);
45  	}
46  
47  	@Override
48  	public void stateLeaving(TranslatorContext context,
49  			IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
50  		if (!(symbol instanceof ItemCategoryEnd)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol, ItemCategoryEnd.class), context.getLogger(), this);
51  	}
52  
53  	@Override
54  	public void stateSymbol(TranslatorContext context, InfoMessage symbol) {
55  		if (!(symbol instanceof ItemCategory)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol, ItemCategory.class), context.getLogger(), this);
56  		ItemDescriptor desc = context.getItemTranslator().createDescriptor((ItemCategory)symbol);
57  		if (desc == null) {
58  			context.getLogger().warning("ItemCategory was not translated into ItemDescriptor: " + symbol);
59  			return;
60  		}
61  		long simTime = (symbol instanceof IWorldChangeEvent ? ((IWorldChangeEvent)symbol).getSimTime() : 0);
62  		context.getEventQueue().pushEvent(new ItemDescriptorObtained(desc, simTime));
63  	}
64  
65  }