View Javadoc

1    package nl.tudelft.goal.ut2004.translators;
2   
3   import java.util.Arrays;
4   
5   import nl.tudelft.goal.ut2004.messages.FireMode;
6   import eis.eis2java.exception.TranslationException;
7   import eis.eis2java.translation.Java2Parameter;
8   import eis.eis2java.translation.Parameter2Java;
9   import eis.eis2java.translation.Translator;
10  import eis.iilang.Identifier;
11  import eis.iilang.Parameter;
12  /**
13   * Example: primary<br>
14   * Example: secondary
15   * 
16   * 
17   * @author mpkorstanje
18   *
19   */
20  public class FireModeTranslator implements Parameter2Java<FireMode>, Java2Parameter<FireMode> {
21  
22  	@Override
23  	public FireMode translate(Parameter parameter) throws TranslationException {
24  		String string = Translator.getInstance().translate2Java(parameter, String.class);
25  
26  		try {
27  			return FireMode.valueOfIgnoreCase(string);
28  		} catch (IllegalArgumentException e) {
29  			String message = String.format("%s was not a fire mode. Expected on off %s.", string, Arrays.toString(FireMode.values()));
30  			throw new TranslationException(message, e);
31  		}
32  	}
33  
34  	@Override
35  	public Class<FireMode> translatesTo() {
36  		return FireMode.class;
37  	}
38  
39  	@Override
40  	public Parameter[] translate(FireMode o) throws TranslationException {
41  		return new Parameter[]{new Identifier(o.name().toLowerCase())};
42  	}
43  
44  	@Override
45  	public Class<? extends FireMode> translatesFrom() {
46  		return FireMode.class;
47  	}
48  
49  }