1 package cz.cuni.amis.pogamut.udk.communication.translator.server.state; 2 3 import java.util.HashMap; 4 import java.util.List; 5 import java.util.Map; 6 7 import cz.cuni.amis.fsm.FSMState; 8 import cz.cuni.amis.fsm.FSMTransition; 9 import cz.cuni.amis.fsm.IFSMState; 10 import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage; 11 import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldChangeEvent; 12 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId; 13 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Item; 14 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.ItemListEnd; 15 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.ItemListStart; 16 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.NavPoint; 17 import cz.cuni.amis.pogamut.udk.communication.translator.TranslatorContext; 18 import cz.cuni.amis.pogamut.udk.communication.translator.server.support.ServerListState; 19 import cz.cuni.amis.pogamut.udk.communication.translator.shared.events.MapPointListObtained; 20 21 import java.util.logging.Level; 22 23 @FSMState( 24 map={ 25 @FSMTransition( 26 state=ServerRunningState.class, 27 symbol={ItemListEnd.class}, 28 transition={} 29 ) 30 } 31 ) 32 public class ItemListState extends ServerListState<Item, TranslatorContext> { 33 34 public ItemListState() { 35 super(ItemListStart.class, Item.class, ItemListEnd.class); 36 } 37 38 @Override 39 public void stateLeaving(TranslatorContext translatorContext, 40 IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) { 41 processItems(translatorContext.getNavPoints(), getList(), translatorContext); 42 newList(); 43 } 44 45 private void processItems(Map<UnrealId, NavPoint> origNavPoints, List<Item> list, TranslatorContext context) { 46 Map<UnrealId, Item> items = new HashMap<UnrealId, Item>(); 47 48 for (Item item : list) { 49 items.put(item.getId(), item); 50 } 51 52 context.setItems(items); 53 54 if (context.getNavPoints() != null && context.getNavPoints().size() != 0) { 55 context.processNavPointsAndItems(); 56 if (context.getLogger().isLoggable(Level.FINE)) context.getLogger().fine("Pushing NavPoint events."); 57 context.getEventQueue().pushEvent(context.getNavPoints().values().toArray(new IWorldChangeEvent[0])); 58 if (context.getLogger().isLoggable(Level.FINE)) context.getLogger().fine("Pushing Item events."); 59 context.getEventQueue().pushEvent(context.getItems().values().toArray(new IWorldChangeEvent[0])); 60 context.getEventQueue().pushEvent(new MapPointListObtained(context.getNavPoints(), context.getItems())); 61 } else { 62 if (context.getLogger().isLoggable(Level.FINE)) context.getLogger().fine("Pushing Item events."); 63 context.getEventQueue().pushEvent(context.getItems().values().toArray(new IWorldChangeEvent[0])); 64 } 65 66 } 67 68 }