1 package nl.tudelft.goal.ut2004.translators;
2
3 import nl.tudelft.goal.unreal.util.EnvironmentUtil;
4 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Group;
5 import eis.eis2java.exception.TranslationException;
6 import eis.eis2java.translation.Java2Parameter;
7 import eis.eis2java.translation.Parameter2Java;
8 import eis.eis2java.translation.Translator;
9 import eis.iilang.Identifier;
10 import eis.iilang.Parameter;
11
12 public class GroupTranslator implements Java2Parameter<Group>, Parameter2Java<Group> {
13
14 @Override
15 public Parameter[] translate(Group o) throws TranslationException {
16 return new Parameter[] { new Identifier(o.name().toLowerCase()) };
17 }
18
19 @Override
20 public Class<? extends Group> translatesFrom() {
21 return Group.class;
22 }
23
24 @Override
25 public Group translate(Parameter parameter) throws TranslationException {
26 String itemTypeString = Translator.getInstance().translate2Java(parameter, String.class);
27
28 try {
29 return Group.valueOf(itemTypeString.toUpperCase());
30 } catch (IllegalArgumentException e) {
31 String message = String.format("%s was not a ItemType. Expected on off %s.", itemTypeString, EnvironmentUtil.listValid(Group.class));
32 throw new TranslationException(message, e);
33 }
34 }
35
36 @Override
37 public Class<Group> translatesTo() {
38 return Group.class;
39 }
40
41 }