1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package nl.tudelft.goal.ut2004.translators;
18
19 import eis.eis2java.exception.TranslationException;
20 import eis.eis2java.translation.Parameter2Java;
21 import eis.eis2java.translation.Translator;
22 import eis.iilang.Parameter;
23 import java.util.Arrays;
24 import nl.tudelft.goal.ut2004.messages.Scope;
25
26
27
28
29
30 public class ScopeTranslator implements Parameter2Java<Scope> {
31
32 @Override
33 public Scope translate(Parameter parameter) throws TranslationException {
34 String scopeString = Translator.getInstance().translate2Java(parameter, String.class);
35
36 try {
37 return Scope.valueOfIgnoreCase(scopeString);
38 } catch (IllegalArgumentException e) {
39 String message = String.format("%s is not a valid scope. Excepted one off %", scopeString, Arrays.toString(Scope.values()));
40 throw new TranslationException(message, e);
41 }
42 }
43
44 @Override
45 public Class<Scope> translatesTo() {
46 return Scope.class;
47 }
48
49 }