1 package nl.tudelft.goal.ut2004.translators;
2
3 import java.util.Arrays;
4
5 import nl.tudelft.goal.ut2004.messages.Combo;
6 import eis.eis2java.exception.TranslationException;
7 import eis.eis2java.translation.Parameter2Java;
8 import eis.eis2java.translation.Translator;
9 import eis.iilang.Parameter;
10
11 public class ComboTranslator implements Parameter2Java<Combo> {
12
13 @Override
14 public Combo translate(Parameter parameter) throws TranslationException {
15 String comboString = Translator.getInstance().translate2Java(parameter, String.class);
16
17 try {
18 return Combo.valueOfIgnoresCase(comboString);
19 } catch (IllegalArgumentException e) {
20 String message = String.format("%s was not a Combo. Expected on off %s.", comboString, Arrays.toString(Combo.values()));
21 throw new TranslationException(message, e);
22 }
23 }
24
25 @Override
26 public Class<Combo> translatesTo() {
27 return Combo.class;
28 }
29
30 }