1 package cz.cuni.amis.pogamut.ut2004.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.ut2004.communication.messages.gbinfomessages.ItemCategory;
8 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ItemCategoryEnd;
9 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ItemCategoryStart;
10 import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorContext;
11 import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorMessages;
12 import cz.cuni.amis.pogamut.ut2004.communication.translator.UnexpectedMessageException;
13 import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.ItemDescriptor;
14 import cz.cuni.amis.pogamut.ut2004.communication.translator.server.support.AbstractServerFSMState;
15 import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.ItemDescriptorObtained;
16
17
18
19
20
21
22 @FSMState(map={
23 @FSMTransition(
24 state=ServerRunningState.class,
25 symbol={ItemCategoryEnd.class},
26 transition={})
27 }
28 )
29 public class ItemCategoryState extends AbstractServerFSMState<InfoMessage, TranslatorContext>{
30
31 @Override
32 public void init(TranslatorContext context) {
33 }
34
35 @Override
36 public void restart(TranslatorContext context) {
37 }
38
39 @Override
40 public void stateEntering(TranslatorContext context,
41 IFSMState<InfoMessage, TranslatorContext> fromState,
42 InfoMessage symbol) {
43 if (!(symbol instanceof ItemCategoryStart)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol, ItemCategoryStart.class), context.getLogger(), this);
44 }
45
46 @Override
47 public void stateLeaving(TranslatorContext context,
48 IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
49 if (!(symbol instanceof ItemCategoryEnd)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol, ItemCategoryEnd.class), context.getLogger(), this);
50 }
51
52 @Override
53 protected void innerStateSymbol(TranslatorContext context, InfoMessage symbol) {
54 if (!(symbol instanceof ItemCategory)) throw new UnexpectedMessageException(TranslatorMessages.unexpectedMessage(this, symbol, ItemCategory.class), context.getLogger(), this);
55 long simTime = ((ItemCategory)symbol).getSimTime();
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 context.getEventQueue().pushEvent(new ItemDescriptorObtained(desc, simTime));
62 }
63
64 }