View Javadoc

1   package nl.tudelft.goal.unreal.translators;
2   
3   import java.net.URI;
4   import java.util.Map.Entry;
5   import java.util.logging.Level;
6   
7   import nl.tudelft.goal.unreal.messages.BotParametersList;
8   import nl.tudelft.goal.unreal.messages.Configuration;
9   import nl.tudelft.goal.unreal.messages.ConfigurationKey;
10  import nl.tudelft.goal.unreal.messages.ParameterMap;
11  import eis.eis2java.exception.TranslationException;
12  import eis.eis2java.translation.Parameter2Java;
13  import eis.eis2java.translation.Translator;
14  import eis.iilang.Identifier;
15  import eis.iilang.Parameter;
16  
17  public class ConfigurationTranslator implements Parameter2Java<Configuration> {
18  
19  	@Override
20  	public Configuration translate(Parameter parameter) throws TranslationException {
21  		Translator t = Translator.getInstance();
22  
23  		ParameterMap parameterMap = t.translate2Java(parameter, ParameterMap.class);
24  
25  		Configuration configuration = new Configuration();
26  
27  		for (Entry<Identifier, Parameter> entry : parameterMap.entrySet()) {
28  			ConfigurationKey key = t.translate2Java(entry.getKey(), ConfigurationKey.class);
29  			Parameter value = entry.getValue();
30  
31  			switch (key) {
32  			case BOTS:
33  				configuration.setBots(t.translate2Java(value, BotParametersList.class));
34  				break;
35  			case BOT_SERVER:
36  				configuration.setBotServer(t.translate2Java(value, URI.class));
37  				break;
38  			case LOGLEVEL:
39  				configuration.setLogLevel(t.translate2Java(value, Level.class));
40  				break;
41  			case VISUALIZER_SERVER:
42  				configuration.setVisualizer(t.translate2Java(value, URI.class));
43  				break;
44  			case CONTROL_SERVER:
45  				configuration.setControlServer(t.translate2Java(value, URI.class));
46  				break;
47  			case BOT_CONTROLLER:
48  				configuration.setBotControllerClass(t.translate2Java(value, Class.class));
49  	
50  			}
51  		}
52  
53  		return configuration;
54  
55  	}
56  
57  	@Override
58  	public Class<Configuration> translatesTo() {
59  		return Configuration.class;
60  	}
61  
62  }